Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#38103 closed defect (bug) (invalid)

Unit tests chokes due to clone being used (PHP 7)

Reported by: limikael's profile limikael Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: Build/Test Tools Keywords:
Focuses: Cc:

Description (last modified by swissspidy)


This is concerning the unit tests for external plugins, not the unit tests for the Wordpress core.

I'm running unit tests for a plugin, and I'm getting an error in the file testcase.php. The file is inside one of the directories installed when running this:

The error happens inside the function _backup_hooks, on this line:

self::$hooks_saved['wp_filter'][ $hook_name ] = clone $hook_object;

I tried to trace out the $hook_object variable, and it is an array. In this case it looks like this:

    [10] => Array
            [_manually_load_plugin] => Array
                    [function] => _manually_load_plugin
                    [accepted_args] => 1



So, it is an array, and not an object, and I guess that's why clone doesn't work. I'm using PHP 7.0.8-0ubuntu0.16.04.2. Last time I ran the tests it was on a PHP 5.something version, so I also guess this could have something to do with PHP 7 being stricter about objects/arrays when using clone.

Change History (4)

#1 @swissspidy
7 years ago

  • Description modified (diff)

#2 @swissspidy
7 years ago

It doesn't have much to do with PHP 7. Rather, it sounds like you're testing the plugin with the current stable version of WordPress — 4.6. — together with the test suite from trunk.

In trunk, $hook_object is indeed an object. It was an array before. See #17817 and

#3 @limikael
7 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Thanks for a quick reply!

It turned out the when I downloaded the latest version of from

then it worked. Is that the place where I'm supposed to get the file from? (And I know that the question doesn't really fit in a bug report, but I'm still wondering. If this is not the proper place to ask it, please point me to the place where I should ask).

#4 @swissspidy
7 years ago

  • Milestone Awaiting Review deleted

Glad you could resolve the issue.

I don't know how you develop your plugin, but comes from WP-CLI's wp scaffold plugin-tests command so yeah, you should occasionally update the script from there.

Note: See TracTickets for help on using tickets.