From 8b8030ee8fc7cdf95a885ff39c7780bf5abf1b3e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 25 Dec 2022 13:10:42 +0000 Subject: [PATCH] Code Modernization: Rename parameters that use reserved keywords in `phpunit/includes/abstract-testcase.php`. While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names. This commit: * Renames the `$function` parameter to `$function_name` in: * `WP_UnitTestCase_Base::deprecated_function_run()` * `WP_UnitTestCase_Base::doing_it_wrong_run()` * Renames the `$object` parameter to `$actual` in: * `WP_UnitTestCase_Base::assertEqualFields()` * `WP_UnitTestCase_Base::assertNonEmptyMultidimensionalArray()` Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956], [54959], [54960], [54961], [54962], [54964], [54965], [54969], [54970], [54971], [54972], [54996], [55000], [55011], [55013], [55014], [55015]. Props jrf, aristath, poena, justinahinon, SergeyBiryukov. See #56788. git-svn-id: https://develop.svn.wordpress.org/trunk@55016 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 62 ++++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 6cfeaa307c..3a684b2490 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -682,26 +682,26 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { * @since 3.7.0 * @since 6.1.0 Added the `$replacement`, `$version`, and `$message` parameters. * - * @param string $function The deprecated function. - * @param string $replacement The function that should have been called. - * @param string $version The version of WordPress that deprecated the function. - * @param string $message Optional. A message regarding the change. + * @param string $function_name The deprecated function. + * @param string $replacement The function that should have been called. + * @param string $version The version of WordPress that deprecated the function. + * @param string $message Optional. A message regarding the change. */ - public function deprecated_function_run( $function, $replacement, $version, $message = '' ) { - if ( ! isset( $this->caught_deprecated[ $function ] ) ) { + public function deprecated_function_run( $function_name, $replacement, $version, $message = '' ) { + if ( ! isset( $this->caught_deprecated[ $function_name ] ) ) { switch ( current_action() ) { case 'deprecated_function_run': if ( $replacement ) { $message = sprintf( 'Function %1$s is deprecated since version %2$s! Use %3$s instead.', - $function, + $function_name, $version, $replacement ); } else { $message = sprintf( 'Function %1$s is deprecated since version %2$s with no alternative available.', - $function, + $function_name, $version ); } @@ -711,14 +711,14 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { if ( $replacement ) { $message = sprintf( 'Function %1$s was called with an argument that is deprecated since version %2$s! %3$s', - $function, + $function_name, $version, $replacement ); } else { $message = sprintf( 'Function %1$s was called with an argument that is deprecated since version %2$s with no alternative available.', - $function, + $function_name, $version ); } @@ -728,14 +728,14 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { if ( $replacement ) { $message = sprintf( 'File %1$s is deprecated since version %2$s! Use %3$s instead.', - $function, + $function_name, $version, $replacement ) . ' ' . $message; } else { $message = sprintf( 'File %1$s is deprecated since version %2$s with no alternative available.', - $function, + $function_name, $version ) . ' ' . $message; } @@ -745,21 +745,21 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { if ( $replacement ) { $message = sprintf( 'Hook %1$s is deprecated since version %2$s! Use %3$s instead.', - $function, + $function_name, $version, $replacement ) . ' ' . $message; } else { $message = sprintf( 'Hook %1$s is deprecated since version %2$s with no alternative available.', - $function, + $function_name, $version ) . ' ' . $message; } break; } - $this->caught_deprecated[ $function ] = $message; + $this->caught_deprecated[ $function_name ] = $message; } } @@ -769,17 +769,17 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { * @since 3.7.0 * @since 6.1.0 Added the `$message` and `$version` parameters. * - * @param string $function The function to add. - * @param string $message A message explaining what has been done incorrectly. - * @param string $version The version of WordPress where the message was added. + * @param string $function_name The function to add. + * @param string $message A message explaining what has been done incorrectly. + * @param string $version The version of WordPress where the message was added. */ - public function doing_it_wrong_run( $function, $message, $version ) { - if ( ! isset( $this->caught_doing_it_wrong[ $function ] ) ) { + public function doing_it_wrong_run( $function_name, $message, $version ) { + if ( ! isset( $this->caught_doing_it_wrong[ $function_name ] ) ) { if ( $version ) { $message .= ' ' . sprintf( '(This message was added in version %s.)', $version ); } - $this->caught_doing_it_wrong[ $function ] = $message; + $this->caught_doing_it_wrong[ $function_name ] = $message; } } @@ -837,18 +837,18 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { * @since UT (3.7.0) * @since 5.9.0 Added the `$message` parameter. * - * @param object $object The object to check. + * @param object $actual The object to check. * @param array $fields The fields to check. * @param string $message Optional. Message to display when the assertion fails. */ - public function assertEqualFields( $object, $fields, $message = '' ) { - $this->assertIsObject( $object, $message . ' Passed $object is not an object.' ); + public function assertEqualFields( $actual, $fields, $message = '' ) { + $this->assertIsObject( $actual, $message . ' Passed $actual is not an object.' ); $this->assertIsArray( $fields, $message . ' Passed $fields is not an array.' ); $this->assertNotEmpty( $fields, $message . ' Fields array is empty.' ); foreach ( $fields as $field_name => $field_value ) { - $this->assertObjectHasAttribute( $field_name, $object, $message . " Property $field_name does not exist on the object." ); - $this->assertSame( $field_value, $object->$field_name, $message . " Value of property $field_name is not $field_value." ); + $this->assertObjectHasAttribute( $field_name, $actual, $message . " Property $field_name does not exist on the object." ); + $this->assertSame( $field_value, $actual->$field_name, $message . " Value of property $field_name is not $field_value." ); } } @@ -1012,14 +1012,14 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { * @since 4.8.0 * @since 5.9.0 Added the `$message` parameter. * - * @param array $array Array to check. + * @param array $actual Array to check. * @param string $message Optional. Message to display when the assertion fails. */ - public function assertNonEmptyMultidimensionalArray( $array, $message = '' ) { - $this->assertIsArray( $array, $message . ' Value under test is not an array.' ); - $this->assertNotEmpty( $array, $message . ' Array is empty.' ); + public function assertNonEmptyMultidimensionalArray( $actual, $message = '' ) { + $this->assertIsArray( $actual, $message . ' Value under test is not an array.' ); + $this->assertNotEmpty( $actual, $message . ' Array is empty.' ); - foreach ( $array as $sub_array ) { + foreach ( $actual as $sub_array ) { $this->assertIsArray( $sub_array, $message . ' Subitem of the array is not an array.' ); $this->assertNotEmpty( $sub_array, $message . ' Subitem of the array is empty.' ); }