Make WordPress Core

Changeset 53916


Ignore:
Timestamp:
08/21/2022 04:55:18 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Remove dynamic properties in theme 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 this particular group of test files, the test classes contain a set_up() method which sets a few dynamic (not explicitly declared) properties.

For those properties which were set using a function call or variable access, the property has been explicitly declared on the class now.

For those properties which were set using a constant scalar expression and for which the value is not changed by any of the tests, the property setting has been removed in favor of declaring a class constant.

Includes removing one unused dynamic property declaration: $this->queries in Test_Block_Supports_Layout, which appears to be a copy/paste from Tests_Theme_wpThemeJsonResolver.

Follow-up to [40/tests], [260/tests], [598/tests], [50960], [52675], [53085], [53557], [53558], [53850], [53851], [53852], [53853], [53854], [53856].

Props jrf.
See #56033.

Location:
trunk/tests/phpunit/tests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesTheme.php

    r52010 r53916  
    55class Tests_Admin_IncludesTheme extends WP_UnitTestCase {
    66
     7    /**
     8     * Theme root directory.
     9     *
     10     * @var string
     11     */
     12    const THEME_ROOT = DIR_TESTDATA . '/themedir1';
     13
     14    /**
     15     * Original theme directory.
     16     *
     17     * @var string
     18     */
     19    private $orig_theme_dir;
     20
    721    public function set_up() {
    822        parent::set_up();
    9         $this->theme_root = DIR_TESTDATA . '/themedir1';
    1023
    1124        $this->orig_theme_dir            = $GLOBALS['wp_theme_directories'];
    12         $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
     25        $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', self::THEME_ROOT );
    1326
    1427        add_filter( 'theme_root', array( $this, 'filter_theme_root' ) );
     
    3447    // Replace the normal theme root directory with our premade test directory.
    3548    public function filter_theme_root( $dir ) {
    36         return $this->theme_root;
     49        return self::THEME_ROOT;
    3750    }
    3851
  • trunk/tests/phpunit/tests/block-supports/layout.php

    r53680 r53916  
    1818 */
    1919class Test_Block_Supports_Layout extends WP_UnitTestCase {
     20
     21    /**
     22     * Theme root directory.
     23     *
     24     * @var string
     25     */
     26    private $theme_root;
     27
     28    /**
     29     * Original theme directory.
     30     *
     31     * @var string
     32     */
     33    private $orig_theme_dir;
     34
    2035    function set_up() {
    2136        parent::set_up();
     
    3146        add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) );
    3247
    33         $this->queries = array();
    3448        // Clear caches.
    3549        wp_clean_themes_cache();
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r53874 r53916  
    88class Tests_Theme_ThemeDir extends WP_UnitTestCase {
    99
     10    /**
     11     * Theme root directory.
     12     *
     13     * @var string
     14     */
     15    const THEME_ROOT = DIR_TESTDATA . '/themedir1';
     16
     17    /**
     18     * Original theme directory.
     19     *
     20     * @var string
     21     */
     22    private $orig_theme_dir;
     23
    1024    public function set_up() {
    1125        parent::set_up();
    12         $this->theme_root = DIR_TESTDATA . '/themedir1';
    1326
    1427        $this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
    1528
    1629        // /themes is necessary as theme.php functions assume /themes is the root if there is only one root.
    17         $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
     30        $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', self::THEME_ROOT );
    1831
    1932        add_filter( 'theme_root', array( $this, 'filter_theme_root' ) );
     
    3447    // Replace the normal theme root directory with our premade test directory.
    3548    public function filter_theme_root( $dir ) {
    36         return $this->theme_root;
     49        return self::THEME_ROOT;
    3750    }
    3851
     
    5871        $this->assertSame( 'default', $theme['Stylesheet'] );
    5972
    60         $this->assertContains( $this->theme_root . '/default/functions.php', $theme['Template Files'] );
    61         $this->assertContains( $this->theme_root . '/default/index.php', $theme['Template Files'] );
    62         $this->assertContains( $this->theme_root . '/default/style.css', $theme['Stylesheet Files'] );
    63 
    64         $this->assertSame( $this->theme_root . '/default', $theme['Template Dir'] );
    65         $this->assertSame( $this->theme_root . '/default', $theme['Stylesheet Dir'] );
     73        $this->assertContains( self::THEME_ROOT . '/default/functions.php', $theme['Template Files'] );
     74        $this->assertContains( self::THEME_ROOT . '/default/index.php', $theme['Template Files'] );
     75        $this->assertContains( self::THEME_ROOT . '/default/style.css', $theme['Stylesheet Files'] );
     76
     77        $this->assertSame( self::THEME_ROOT . '/default', $theme['Template Dir'] );
     78        $this->assertSame( self::THEME_ROOT . '/default', $theme['Stylesheet Dir'] );
    6679        $this->assertSame( 'publish', $theme['Status'] );
    6780        $this->assertSame( '', $theme['Parent Theme'] );
     
    89102        $template_files = $theme['Template Files'];
    90103
    91         $this->assertSame( $this->theme_root . '/sandbox/functions.php', reset( $template_files ) );
    92         $this->assertSame( $this->theme_root . '/sandbox/index.php', next( $template_files ) );
     104        $this->assertSame( self::THEME_ROOT . '/sandbox/functions.php', reset( $template_files ) );
     105        $this->assertSame( self::THEME_ROOT . '/sandbox/index.php', next( $template_files ) );
    93106
    94107        $stylesheet_files = $theme['Stylesheet Files'];
    95108
    96         $this->assertSame( $this->theme_root . '/sandbox/style.css', reset( $stylesheet_files ) );
    97 
    98         $this->assertSame( $this->theme_root . '/sandbox', $theme['Template Dir'] );
    99         $this->assertSame( $this->theme_root . '/sandbox', $theme['Stylesheet Dir'] );
     109        $this->assertSame( self::THEME_ROOT . '/sandbox/style.css', reset( $stylesheet_files ) );
     110
     111        $this->assertSame( self::THEME_ROOT . '/sandbox', $theme['Template Dir'] );
     112        $this->assertSame( self::THEME_ROOT . '/sandbox', $theme['Stylesheet Dir'] );
    100113        $this->assertSame( 'publish', $theme['Status'] );
    101114        $this->assertSame( '', $theme['Parent Theme'] );
     
    123136        $this->assertSame( 'sandbox', $theme['Template'] );
    124137        $this->assertSame( 'stylesheetonly', $theme['Stylesheet'] );
    125         $this->assertContains( $this->theme_root . '/sandbox/functions.php', $theme['Template Files'] );
    126         $this->assertContains( $this->theme_root . '/sandbox/index.php', $theme['Template Files'] );
    127 
    128         $this->assertContains( $this->theme_root . '/stylesheetonly/style.css', $theme['Stylesheet Files'] );
    129 
    130         $this->assertSame( $this->theme_root . '/sandbox', $theme['Template Dir'] );
    131         $this->assertSame( $this->theme_root . '/stylesheetonly', $theme['Stylesheet Dir'] );
     138        $this->assertContains( self::THEME_ROOT . '/sandbox/functions.php', $theme['Template Files'] );
     139        $this->assertContains( self::THEME_ROOT . '/sandbox/index.php', $theme['Template Files'] );
     140
     141        $this->assertContains( self::THEME_ROOT . '/stylesheetonly/style.css', $theme['Stylesheet Files'] );
     142
     143        $this->assertSame( self::THEME_ROOT . '/sandbox', $theme['Template Dir'] );
     144        $this->assertSame( self::THEME_ROOT . '/stylesheetonly', $theme['Stylesheet Dir'] );
    132145        $this->assertSame( 'publish', $theme['Status'] );
    133146        $this->assertSame( 'Sandbox', $theme['Parent Theme'] );
     
    143156        // Ignore themes in the default /themes directory.
    144157        foreach ( $themes as $theme_name => $theme ) {
    145             if ( $theme->get_theme_root() !== $this->theme_root ) {
     158            if ( $theme->get_theme_root() !== self::THEME_ROOT ) {
    146159                unset( $themes[ $theme_name ] );
    147160            }
     
    199212
    200213    public function test_wp_get_theme_with_non_default_theme_root() {
    201         $this->assertFalse( wp_get_theme( 'sandbox', $this->theme_root )->errors() );
     214        $this->assertFalse( wp_get_theme( 'sandbox', self::THEME_ROOT )->errors() );
    202215        $this->assertFalse( wp_get_theme( 'sandbox' )->errors() );
    203216    }
     
    213226
    214227        $templates = $theme['Template Files'];
    215         $this->assertContains( $this->theme_root . '/page-templates/template-top-level.php', $templates );
     228        $this->assertContains( self::THEME_ROOT . '/page-templates/template-top-level.php', $templates );
    216229    }
    217230
     
    239252     */
    240253    public function test_get_theme_data_subdir() {
    241         $theme_data = get_theme_data( $this->theme_root . '/subdir/theme2/style.css' );
     254        $theme_data = get_theme_data( self::THEME_ROOT . '/subdir/theme2/style.css' );
    242255
    243256        $this->assertSame( 'My Subdir Theme', $theme_data['Name'] );
  • trunk/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php

    r52682 r53916  
    88class Tests_Theme_wpGetGlobalStylesheet extends WP_UnitTestCase {
    99
     10    /**
     11     * Theme root directory.
     12     *
     13     * @var string
     14     */
     15    private $theme_root;
     16
     17    /**
     18     * Original theme directory.
     19     *
     20     * @var string
     21     */
     22    private $orig_theme_dir;
     23
    1024    public function set_up() {
    1125        parent::set_up();
  • trunk/tests/phpunit/tests/theme/wpTheme.php

    r53416 r53916  
    1010 */
    1111class Tests_Theme_wpTheme extends WP_UnitTestCase {
     12
     13    /**
     14     * Theme root directory.
     15     *
     16     * @var string
     17     */
     18    private $theme_root;
     19
     20    /**
     21     * Original theme directory.
     22     *
     23     * @var string
     24     */
     25    private $orig_theme_dir;
    1226
    1327    public function set_up() {
  • trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php

    r52372 r53916  
    1313class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
    1414
     15    /**
     16     * Theme root directory.
     17     *
     18     * @var string
     19     */
     20    private $theme_root;
     21
     22    /**
     23     * Original theme directory.
     24     *
     25     * @var string
     26     */
     27    private $orig_theme_dir;
     28
     29    /**
     30     * Queries.
     31     *
     32     * @var array
     33     */
     34    private $queries = array();
     35
    1536    public function set_up() {
    1637        parent::set_up();
Note: See TracChangeset for help on using the changeset viewer.