I am currently doing TDD with WordPress, in the PHPUnit I need to test if the meta box is actually registered on a method call, I could not find any function in WordPress to do that, so I was trying to verify it by calling global $wp_meta_boxes, but it returns null when invoked inside a PHPUnit test.

Is this variable is assigned on a hook?

Could any one provide the action/filter name?

1 Answer 1


Here is what i have did as a workaround, i realized we cant do that in TDD way.so its better to write the code first instead of writing the test when you face this problem.

So in my code i have added this

add_meta_box( 'meta-box-id', __( 'My Meta Box', 'textdomain' ), 'wpdocs_my_display_callback', 'post' );

and in test the $wp_meta_boxes is now displaying the array of registered meta boxes.

array(1) {
  array(1) {
    array(1) {
      array(1) {
        array(4) {
          string(11) "meta-box-id"
          string(11) "My Meta Box"
          string(26) "wpdocs_my_display_callback"

This changes nothing, the code still remains the same, but the way of writing differs now due to this issue.

  • Could you post the code of the test that you are using? That would make it easier to understand the issue that you are facing.
    – Fränk
    Commented Oct 13, 2020 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.