[wp-trac] [WordPress Trac] #38103: Unit tests chokes due to clone being used (PHP 7)

WordPress Trac noreply at wordpress.org
Tue Sep 20 08:11:12 UTC 2016


#38103: Unit tests chokes due to clone being used (PHP 7)
------------------------------+------------------------------
 Reporter:  limikael          |       Owner:
     Type:  defect (bug)      |      Status:  new
 Priority:  normal            |   Milestone:  Awaiting Review
Component:  Build/Test Tools  |     Version:  trunk
 Severity:  normal            |  Resolution:
 Keywords:                    |     Focuses:
------------------------------+------------------------------
Description changed by swissspidy:

Old description:

> 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.

New description:

 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.

--

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38103#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list