#38103 closed defect (bug) (invalid)
Unit tests chokes due to clone being used (PHP 7)
Reported by: | limikael | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7 |
Component: | Build/Test Tools | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
Hi,
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:
https://github.com/wp-cli/wp-cli/blob/master/templates/install-wp-tests.sh
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:
Array ( [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)
#3
@
8 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 install-wp-tests.sh from
https://github.com/wp-cli/wp-cli/blob/master/templates/install-wp-tests.sh
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).
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 https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/.