WordPress.org

Make WordPress Core

Changeset 48790


Ignore:
Timestamp:
08/13/2020 12:32:03 PM (5 weeks ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Change create_function() in phpunit/includes/plural-form-function.php to closure.

create_function() has been deprecated in PHP >= 7.2 and removed in PHP 8.

The only instance left in core was used in a test that was being skipped on PHP >= 7.2. This allows the test to run again.

Follow-up to [41722], [41730].

Props jrf.
Fixes #50899.

Location:
trunk/tests/phpunit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/plural-form-function.php

    r46586 r48790  
    88 */
    99function tests_make_plural_form_function( $nplurals, $expression ) {
    10     $expression = str_replace( 'n', '$n', $expression );
    11     $func_body  = "
    12         \$index = (int)($expression);
    13         return (\$index < $nplurals)? \$index : $nplurals - 1;";
     10    $closure = function ( $n ) use ( $nplurals, $expression ) {
     11        $expression = str_replace( 'n', $n, $expression );
    1412
    15     // phpcs:ignore WordPress.PHP.RestrictedPHPFunctions.create_function_create_function
    16     return create_function( '$n', $func_body );
     13        // phpcs:ignore Squiz.PHP.Eval -- This is test code, not production.
     14        $index = (int) eval( 'return ' . $expression . ';' );
     15
     16        return ( $index < $nplurals ) ? $index : $nplurals - 1;
     17    };
     18
     19    return $closure;
    1720}
  • trunk/tests/phpunit/tests/pomo/pluralForms.php

    r47198 r48790  
    7575     */
    7676    public function test_regression( $lang, $nplurals, $expression ) {
    77         if ( version_compare( phpversion(), '7.2', '>=' ) ) {
    78             $this->markTestSkipped( 'Lambda functions are deprecated in PHP 7.2' );
    79         }
    80 
    8177        require_once dirname( dirname( __DIR__ ) ) . '/includes/plural-form-function.php';
    8278
Note: See TracChangeset for help on using the changeset viewer.