Make WordPress Core


Ignore:
Timestamp:
08/25/2022 03:34:24 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Explicitly declare all properties in various tests.

Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

In each of the cases included in this commit, one or more individual tests set a property to allow a filter or action access to certain information.

This commit:

  • Explicitly declares these properties and documents in which tests they are being used.
  • Adds a reset to the default value of the property to a pre-existing tear_down() method or adds that method specifically for that purpose. This ensures that tests do not accidentally “taint” each other.

As these properties are being declared on test classes, they are marked as private. Even though the original dynamic property was public, this should not be considered a backward compatibility break as this only involves test classes.

Includes:

  • In the Tests_Post_Query class, there were two tests assigning a value to an undeclared $post_id property, but subsequently not using the property, so those assignments should have been to a local variable (if they should be assignments at all).
  • In the Test_User_Capabilities class, the property name had a leading _ underscore. This is an outdated PHP 4 practice to indicate a private property. As PHP 4 is no longer supported, the leading underscore is removed from the property name.
  • In the Tests_User_Capabilities class, an unused $_role_test_wp_roles_role property was declared somewhere in the middle of the class. That property is now removed in favor of $_role_test_wp_roles_init, which appears to be the intended name, previously misspelled.

Follow-up to [27294], [36277], [36750], [37712], [38571], [39082], [40290], [43049], [44628], [48328], [53557], [53558], [53850], [53851], [53852], [53853], [53854], [53856], [53916], [53935], [53936], [53937], [53938].

Props jrf.
See #56033.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/hooks/addFilter.php

    r53804 r53942  
    1212    public $hook;
    1313
     14    /**
     15     * Temporary storage for action output.
     16     *
     17     * Used in the following tests:
     18     * - `test_remove_and_add_action()`
     19     * - `test_remove_and_add_last_action()`
     20     * - `test_remove_and_recurse_and_add_action()`
     21     *
     22     * @var array
     23     */
     24    private $action_output = '';
     25
     26    public function tear_down() {
     27        $this->action_output = '';
     28        parent::tear_down();
     29    }
     30
    1431    public function test_add_filter_with_function() {
    1532        $callback      = '__return_null';
     
    203220
    204221    public function test_remove_and_add_action() {
    205         $this->hook          = new WP_Hook();
    206         $this->action_output = '';
     222        $this->hook = new WP_Hook();
    207223
    208224        $this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
     
    218234
    219235    public function test_remove_and_add_last_action() {
    220         $this->hook          = new WP_Hook();
    221         $this->action_output = '';
     236        $this->hook = new WP_Hook();
    222237
    223238        $this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
     
    233248
    234249    public function test_remove_and_recurse_and_add_action() {
    235         $this->hook          = new WP_Hook();
    236         $this->action_output = '';
     250        $this->hook = new WP_Hook();
    237251
    238252        $this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
Note: See TracChangeset for help on using the changeset viewer.