Make WordPress Core


Ignore:
Timestamp:
06/23/2022 02:24:08 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Remove dynamic properties in Tests_*_Slashes.

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 this particular case, the test classes contain a set_up() method that sets a group of properties, which are used by the tests, but the values of these properties are never changed by the tests.

In other words, setting these properties in the set_up() is an unnecessary overhead and the properties should be changed to class constants.

Follow-up to [1041/tests], [1071/tests].

Props jrf.
See #56033.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/option/slashes.php

    r52010 r53557  
    88class Tests_Option_Slashes extends WP_UnitTestCase {
    99
    10     public function set_up() {
    11         parent::set_up();
     10    /*
     11     * It is important to test with both even and odd numbered slashes,
     12     * as KSES does a strip-then-add slashes in some of its function calls.
     13     */
    1214
    13         // It is important to test with both even and odd numbered slashes,
    14         // as KSES does a strip-then-add slashes in some of its function calls.
    15         $this->slash_1 = 'String with 1 slash \\';
    16         $this->slash_2 = 'String with 2 slashes \\\\';
    17         $this->slash_3 = 'String with 3 slashes \\\\\\';
    18         $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    19         $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    20         $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    21         $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    22     }
     15    const SLASH_1 = 'String with 1 slash \\';
     16    const SLASH_2 = 'String with 2 slashes \\\\';
     17    const SLASH_3 = 'String with 3 slashes \\\\\\';
     18    const SLASH_4 = 'String with 4 slashes \\\\\\\\';
     19    const SLASH_5 = 'String with 5 slashes \\\\\\\\\\';
     20    const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\';
     21    const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    2322
    2423    /**
     
    2625     */
    2726    public function test_add_option() {
    28         add_option( 'slash_test_1', $this->slash_1 );
    29         add_option( 'slash_test_2', $this->slash_2 );
    30         add_option( 'slash_test_3', $this->slash_3 );
    31         add_option( 'slash_test_4', $this->slash_4 );
     27        add_option( 'slash_test_1', self::SLASH_1 );
     28        add_option( 'slash_test_2', self::SLASH_2 );
     29        add_option( 'slash_test_3', self::SLASH_3 );
     30        add_option( 'slash_test_4', self::SLASH_4 );
    3231
    33         $this->assertSame( $this->slash_1, get_option( 'slash_test_1' ) );
    34         $this->assertSame( $this->slash_2, get_option( 'slash_test_2' ) );
    35         $this->assertSame( $this->slash_3, get_option( 'slash_test_3' ) );
    36         $this->assertSame( $this->slash_4, get_option( 'slash_test_4' ) );
     32        $this->assertSame( self::SLASH_1, get_option( 'slash_test_1' ) );
     33        $this->assertSame( self::SLASH_2, get_option( 'slash_test_2' ) );
     34        $this->assertSame( self::SLASH_3, get_option( 'slash_test_3' ) );
     35        $this->assertSame( self::SLASH_4, get_option( 'slash_test_4' ) );
    3736    }
    3837
     
    4342        add_option( 'slash_test_5', 'foo' );
    4443
    45         update_option( 'slash_test_5', $this->slash_1 );
    46         $this->assertSame( $this->slash_1, get_option( 'slash_test_5' ) );
     44        update_option( 'slash_test_5', self::SLASH_1 );
     45        $this->assertSame( self::SLASH_1, get_option( 'slash_test_5' ) );
    4746
    48         update_option( 'slash_test_5', $this->slash_2 );
    49         $this->assertSame( $this->slash_2, get_option( 'slash_test_5' ) );
     47        update_option( 'slash_test_5', self::SLASH_2 );
     48        $this->assertSame( self::SLASH_2, get_option( 'slash_test_5' ) );
    5049
    51         update_option( 'slash_test_5', $this->slash_3 );
    52         $this->assertSame( $this->slash_3, get_option( 'slash_test_5' ) );
     50        update_option( 'slash_test_5', self::SLASH_3 );
     51        $this->assertSame( self::SLASH_3, get_option( 'slash_test_5' ) );
    5352
    54         update_option( 'slash_test_5', $this->slash_4 );
    55         $this->assertSame( $this->slash_4, get_option( 'slash_test_5' ) );
     53        update_option( 'slash_test_5', self::SLASH_4 );
     54        $this->assertSame( self::SLASH_4, get_option( 'slash_test_5' ) );
    5655    }
    5756}
Note: See TracChangeset for help on using the changeset viewer.