Make WordPress Core


Ignore:
Timestamp:
08/07/2022 02:48:42 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Remove dynamic properties in Tests_File.

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 case, as the $badchars property never changes, declaring this as a class constant is the sensible option.

As for the $dir property (which cannot be turned into a constant due to the function call), this is used in multiple tests, so making this property explicit makes sense.

Follow-up to [139/tests], [53557], [53558], [53850], [53851], [53852], [53853].

Props jrf.
See #56033.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/file.php

    r52932 r53854  
    66class Tests_File extends WP_UnitTestCase {
    77
     8    const BADCHARS = '"\'[]*&?$';
     9
     10    private $dir;
     11
    812    public function set_up() {
    913        parent::set_up();
    1014
    1115        $this->dir = untrailingslashit( get_temp_dir() );
    12 
    13         $this->badchars = '"\'[]*&?$';
    1416    }
    1517
     
    138140    public function test_unique_filename_is_sanitized() {
    139141        $name     = __FUNCTION__;
    140         $filename = wp_unique_filename( $this->dir, $name . $this->badchars . '.txt' );
     142        $filename = wp_unique_filename( $this->dir, $name . self::BADCHARS . '.txt' );
    141143
    142144        // Make sure the bad characters were all stripped out.
Note: See TracChangeset for help on using the changeset viewer.