diff --git a/tests/phpunit/includes/plural-form-function.php b/tests/phpunit/includes/plural-form-function.php index 576ece6b03..714381339d 100644 --- a/tests/phpunit/includes/plural-form-function.php +++ b/tests/phpunit/includes/plural-form-function.php @@ -7,11 +7,14 @@ * @param string $expression */ function tests_make_plural_form_function( $nplurals, $expression ) { - $expression = str_replace( 'n', '$n', $expression ); - $func_body = " - \$index = (int)($expression); - return (\$index < $nplurals)? \$index : $nplurals - 1;"; + $closure = function ( $n ) use ( $nplurals, $expression ) { + $expression = str_replace( 'n', $n, $expression ); - // phpcs:ignore WordPress.PHP.RestrictedPHPFunctions.create_function_create_function - return create_function( '$n', $func_body ); + // phpcs:ignore Squiz.PHP.Eval -- This is test code, not production. + $index = (int) eval( 'return ' . $expression . ';' ); + + return ( $index < $nplurals ) ? $index : $nplurals - 1; + }; + + return $closure; } diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 032efc8006..2d53c29c56 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -74,10 +74,6 @@ class PluralFormsTest extends WP_UnitTestCase { * @group external-http */ public function test_regression( $lang, $nplurals, $expression ) { - if ( version_compare( phpversion(), '7.2', '>=' ) ) { - $this->markTestSkipped( 'Lambda functions are deprecated in PHP 7.2' ); - } - require_once dirname( dirname( __DIR__ ) ) . '/includes/plural-form-function.php'; $parenthesized = self::parenthesize_plural_expression( $expression );