From 75207e3ffab3a2cc9da352727bbe2997b0a016bd Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Mon, 18 Dec 2023 16:56:14 -0500 Subject: [PATCH 01/10] Add tests for '_doing_it_wrong' function Gave up. --- .../phpunit/tests/functions/doingItWrong.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/phpunit/tests/functions/doingItWrong.php diff --git a/tests/phpunit/tests/functions/doingItWrong.php b/tests/phpunit/tests/functions/doingItWrong.php new file mode 100644 index 0000000000000..a7bfcdc5349af --- /dev/null +++ b/tests/phpunit/tests/functions/doingItWrong.php @@ -0,0 +1,60 @@ +expectError(); +// $this->expectErrorMessage( 'function_name(): expected the function name and message' ); + + $action = new MockAction(); + add_filter( 'doing_it_wrong_run', array( $action, 'action' ) ); + + _doing_it_wrong( 'function_name', 'message', 1 ); + + $this->assertSame( 1, $action->get_call_count() ); + } + + /** + * @ticket 60057 + * + * This method tests if the 'doing_it_wrong_trigger_error' filter is called + * when the _doing_it_wrong() function is invoked. + * + * It creates a mock action object and adds a filter to the 'doing_it_wrong_trigger_error' + * hook, using the mock action as the callback. Then, it calls the _doing_it_wrong() + * function with the specified function name, message, and error level. + * Finally, it asserts that the filter callback is called exactly once by checking + * the call count of the mock action object. + * + * @return void + */ + public function test__doing_it_wrong_filter_called() { +// $this->expectError(); +// $this->expectErrorMessage( 'function_name(): expected the function name and message' ); + + $filter = new MockAction(); + add_filter( 'doing_it_wrong_trigger_error', array( $filter, 'filter' ) ); + + _doing_it_wrong( 'function_name', 'message', 1 ); + + $this->assertSame( 1, $filter->get_call_count() ); + } +} From 3e4fcb61e1bb771ed00a28940d9096b565a3f331 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 19 Dec 2023 11:55:09 -0500 Subject: [PATCH 02/10] Enhance 'doingItWrong' function tests Extended the PHPUnit test suite for the 'doingItWrong' function in WordPress. Added more comprehensive test cases, including the setup phase and validation for the error notice. These improvements enhance code quality by ensuring that the function behaves as expected under varying conditions. --- .../phpunit/tests/functions/doingItWrong.php | 53 +++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/functions/doingItWrong.php b/tests/phpunit/tests/functions/doingItWrong.php index a7bfcdc5349af..c3f486d7bd2d3 100644 --- a/tests/phpunit/tests/functions/doingItWrong.php +++ b/tests/phpunit/tests/functions/doingItWrong.php @@ -7,7 +7,34 @@ * * @covers ::_doing_it_wrong */ -class Tests_Functions_doingItWrong extends WP_UnitTestCase{ +class Tests_Functions_doingItWrong extends WP_UnitTestCase { + + /** + * Sets up the test case. + * + * This method is responsible for setting up the test case before each test method is executed. + * It removes certain actions related to deprecated and doing_it_wrong functions. + * + * @return void + */ + public function set_up() { + parent::set_up(); + +// remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ), 10, 3 ); +// remove_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ), 10, 3 ); +// remove_action( 'deprecated_class_run', array( $this, 'deprecated_function_run' ), 10, 3 ); +// remove_action( 'deprecated_file_included', array( $this, 'deprecated_function_run' ), 10, 4 ); +// remove_action( 'deprecated_hook_run', array( $this, 'deprecated_function_run' ), 10, 4 ); + remove_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ), 10, 3 ); + +// remove_action( 'deprecated_function_trigger_error', '__return_false' ); +// remove_action( 'deprecated_argument_trigger_error', '__return_false' ); +// remove_action( 'deprecated_class_trigger_error', '__return_false' ); +// remove_action( 'deprecated_file_trigger_error', '__return_false' ); +// remove_action( 'deprecated_hook_trigger_error', '__return_false' ); + remove_action( 'doing_it_wrong_trigger_error', '__return_false' ); + } + /** * @ticket 60057 @@ -21,8 +48,8 @@ class Tests_Functions_doingItWrong extends WP_UnitTestCase{ * @return void */ public function test__doing_it_wrong_action_called() { - $this->expectError(); -// $this->expectErrorMessage( 'function_name(): expected the function name and message' ); + $this->expectNotice(); + $this->expectNoticeMessage( 'Function function_name was called incorrectly. message Please see Debugging in WordPress for more information. (This message was added in version 1.)' ); $action = new MockAction(); add_filter( 'doing_it_wrong_run', array( $action, 'action' ) ); @@ -47,8 +74,8 @@ public function test__doing_it_wrong_action_called() { * @return void */ public function test__doing_it_wrong_filter_called() { -// $this->expectError(); -// $this->expectErrorMessage( 'function_name(): expected the function name and message' ); + $this->expectNotice(); + $this->expectNoticeMessage( 'Function function_name was called incorrectly. message Please see Debugging in WordPress for more information. (This message was added in version 1.)' ); $filter = new MockAction(); add_filter( 'doing_it_wrong_trigger_error', array( $filter, 'filter' ) ); @@ -57,4 +84,20 @@ public function test__doing_it_wrong_filter_called() { $this->assertSame( 1, $filter->get_call_count() ); } + + /** + * @ticket 60057 + * + * Tests the _doing_it_wrong function when called without a version number. + * + * This method verifies that the _doing_it_wrong function throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test__doing_it_wrong_no_version() { + $this->expectNotice(); + $this->expectNoticeMessage( 'Function function_name was called incorrectly. message Please see Debugging in WordPress for more information.' ); + + _doing_it_wrong( 'function_name', 'message', false ); + } } From 6c9ca5d34be6daf4c59a60e5a2c708472a905da4 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 19 Dec 2023 12:00:17 -0500 Subject: [PATCH 03/10] Update 'doingItWrong' tests configuration Removed unnecessary actions in the 'doingItWrong' PHPUnit test setup. The setup is simplified for a cleaner and more focused testing of the 'doingItWrong' function. This streamlining allows for accurate and effective evaluation of the function's overall performance and expected behavior. --- tests/phpunit/tests/functions/doingItWrong.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/tests/phpunit/tests/functions/doingItWrong.php b/tests/phpunit/tests/functions/doingItWrong.php index c3f486d7bd2d3..0117b2138ab90 100644 --- a/tests/phpunit/tests/functions/doingItWrong.php +++ b/tests/phpunit/tests/functions/doingItWrong.php @@ -20,18 +20,8 @@ class Tests_Functions_doingItWrong extends WP_UnitTestCase { public function set_up() { parent::set_up(); -// remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ), 10, 3 ); -// remove_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ), 10, 3 ); -// remove_action( 'deprecated_class_run', array( $this, 'deprecated_function_run' ), 10, 3 ); -// remove_action( 'deprecated_file_included', array( $this, 'deprecated_function_run' ), 10, 4 ); -// remove_action( 'deprecated_hook_run', array( $this, 'deprecated_function_run' ), 10, 4 ); + // remove ethe spherical handling for doing_it_wrong in the PHPUnint setup so we can test it remove_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ), 10, 3 ); - -// remove_action( 'deprecated_function_trigger_error', '__return_false' ); -// remove_action( 'deprecated_argument_trigger_error', '__return_false' ); -// remove_action( 'deprecated_class_trigger_error', '__return_false' ); -// remove_action( 'deprecated_file_trigger_error', '__return_false' ); -// remove_action( 'deprecated_hook_trigger_error', '__return_false' ); remove_action( 'doing_it_wrong_trigger_error', '__return_false' ); } From e2a29e9e9f7482c6be91b54aa723a6c18467aac2 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 19 Dec 2023 13:14:57 -0500 Subject: [PATCH 04/10] Refactor tests to check '__deprecated_hook' function Renamed 'doingItWrong' PHPUnit test file and class to 'deprecatedHook' to match its function testing. Adjusted all method names, action hooks, comments, and tested functionalities inside test methods to focus on the '__deprecated_hook' function. This is a pivotal change for a more precise assessment of '__deprecated_hook' function's behavior and performance under varying scenarios. --- .../tests/functions/deprecatedHook.php | 125 ++++++++++++++++++ .../phpunit/tests/functions/doingItWrong.php | 93 ------------- 2 files changed, 125 insertions(+), 93 deletions(-) create mode 100644 tests/phpunit/tests/functions/deprecatedHook.php delete mode 100644 tests/phpunit/tests/functions/doingItWrong.php diff --git a/tests/phpunit/tests/functions/deprecatedHook.php b/tests/phpunit/tests/functions/deprecatedHook.php new file mode 100644 index 0000000000000..3c6d6fe96ebd8 --- /dev/null +++ b/tests/phpunit/tests/functions/deprecatedHook.php @@ -0,0 +1,125 @@ +expectDeprecation(); + $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1! Use replacement_hook instead. message' ); + + $action = new MockAction(); + add_filter( 'deprecated_hook_run', array( $action, 'action' ) ); + + _deprecated_hook( 'hook_name', 1, 'replacement_hook', 'message' ); + + $this->assertSame( 1, $action->get_call_count() ); + } + + /** + * @ticket 60057 + * + * This method tests if the '_deprecated_hook_trigger_error' filter is called + * when the __deprecated_hook() function is invoked. + * + * It creates a mock action object and adds a filter to the '_deprecated_hook_trigger_error' + * hook, using the mock action as the callback. Then, it calls the __deprecated_hook() + * function with the specified function name, message, and error level. + * Finally, it asserts that the filter callback is called exactly once by checking + * the call count of the mock action object. + * + * @return void + */ + public function test_deprecated_hook_filter_called() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1! Use replacement_hook instead. message' ); + + $filter = new MockAction(); + add_filter( 'deprecated_hook_trigger_error', array( $filter, 'filter' ) ); + + _deprecated_hook( 'hook_name', 1, 'replacement_hook', 'message' ); + + $this->assertSame( 1, $filter->get_call_count() ); + } + + /** + * @ticket 60057 + * + * Tests the __deprecated_hook function when called without a version number. + * + * This method verifies that the __deprecated_hook function throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test_deprecated_hook_no_replacement() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1 with no alternative available. message' ); + + _deprecated_hook( 'hook_name', 1, '', 'message' ); + } + + /** + * @ticket 60057 + * + * Tests the __deprecated_hook function when called without a version number. + * + * This method verifies that the __deprecated_hook function throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test_deprecated_hook_no_message() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1! Use replacement_hook instead.' ); + + _deprecated_hook( 'hook_name', 1, 'replacement_hook' ); + } + + /** + * @ticket 60057 + * + * Tests the __deprecated_hook function when called without a version number. + * + * This method verifies that the __deprecated_hook function throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test_deprecated_hook() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1 with no alternative available.' ); + + _deprecated_hook( 'hook_name', 1 ); + } +} diff --git a/tests/phpunit/tests/functions/doingItWrong.php b/tests/phpunit/tests/functions/doingItWrong.php deleted file mode 100644 index 0117b2138ab90..0000000000000 --- a/tests/phpunit/tests/functions/doingItWrong.php +++ /dev/null @@ -1,93 +0,0 @@ -expectNotice(); - $this->expectNoticeMessage( 'Function function_name was called incorrectly. message Please see Debugging in WordPress for more information. (This message was added in version 1.)' ); - - $action = new MockAction(); - add_filter( 'doing_it_wrong_run', array( $action, 'action' ) ); - - _doing_it_wrong( 'function_name', 'message', 1 ); - - $this->assertSame( 1, $action->get_call_count() ); - } - - /** - * @ticket 60057 - * - * This method tests if the 'doing_it_wrong_trigger_error' filter is called - * when the _doing_it_wrong() function is invoked. - * - * It creates a mock action object and adds a filter to the 'doing_it_wrong_trigger_error' - * hook, using the mock action as the callback. Then, it calls the _doing_it_wrong() - * function with the specified function name, message, and error level. - * Finally, it asserts that the filter callback is called exactly once by checking - * the call count of the mock action object. - * - * @return void - */ - public function test__doing_it_wrong_filter_called() { - $this->expectNotice(); - $this->expectNoticeMessage( 'Function function_name was called incorrectly. message Please see Debugging in WordPress for more information. (This message was added in version 1.)' ); - - $filter = new MockAction(); - add_filter( 'doing_it_wrong_trigger_error', array( $filter, 'filter' ) ); - - _doing_it_wrong( 'function_name', 'message', 1 ); - - $this->assertSame( 1, $filter->get_call_count() ); - } - - /** - * @ticket 60057 - * - * Tests the _doing_it_wrong function when called without a version number. - * - * This method verifies that the _doing_it_wrong function throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test__doing_it_wrong_no_version() { - $this->expectNotice(); - $this->expectNoticeMessage( 'Function function_name was called incorrectly. message Please see Debugging in WordPress for more information.' ); - - _doing_it_wrong( 'function_name', 'message', false ); - } -} From f337d7b317be1ce51a4d509bb6425555ede00631 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 19 Dec 2023 13:27:59 -0500 Subject: [PATCH 05/10] The 'deprecatedHook' PHPUnit test file and class have been renamed to 'deprecatedArgument' to represent the actual function being tested. All related method names, action hooks, comments, and functionality within the test methods have been adjusted to focus on the '_deprecated_argument' function. This change allows for a more accurate evaluation of the '_deprecated_argument' function's behavior and performance. --- .../tests/functions/deprecatedArgument.php | 109 +++++++++++++++ .../tests/functions/deprecatedHook.php | 125 ------------------ 2 files changed, 109 insertions(+), 125 deletions(-) create mode 100644 tests/phpunit/tests/functions/deprecatedArgument.php delete mode 100644 tests/phpunit/tests/functions/deprecatedHook.php diff --git a/tests/phpunit/tests/functions/deprecatedArgument.php b/tests/phpunit/tests/functions/deprecatedArgument.php new file mode 100644 index 0000000000000..0daf255aac625 --- /dev/null +++ b/tests/phpunit/tests/functions/deprecatedArgument.php @@ -0,0 +1,109 @@ +expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name was called with an argument that is deprecated since version 1! message' ); + + $action = new MockAction(); + add_filter( 'deprecated_argument_run', array( $action, 'action' ) ); + + _deprecated_argument( 'function_name', 1, 'message' ); + + $this->assertSame( 1, $action->get_call_count() ); + } + + /** + * @ticket 60057 + * + * This method tests if the '_deprecated_argument_trigger_error' filter is called + * when the _deprecated_argument() function is invoked. + * + * It creates a mock action object and adds a filter to the '_deprecated_argument_trigger_error' + * hook, using the mock action as the callback. Then, it calls the __deprecated_argument() + * function with the specified function name, message, and error level. + * Finally, it asserts that the filter callback is called exactly once by checking + * the call count of the mock action object. + * + * @return void + */ + public function test_deprecated_argument_filter_called() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name was called with an argument that is deprecated since version 1! message' ); + + $filter = new MockAction(); + add_filter( 'deprecated_argument_trigger_error', array( $filter, 'filter' ) ); + + _deprecated_argument( 'function_name', 1, 'message' ); + + $this->assertSame( 1, $filter->get_call_count() ); + } + + /** + * @ticket 60057 + * + * Tests the _deprecated_argumentfunction when called without a version number. + * + * This method verifies that the _deprecated_argumentfunction throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test_deprecated_argument_no_replacement() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name was called with an argument that is deprecated since version 1! message' ); + + _deprecated_argument( 'function_name', 1, 'message' ); + } + + /** + * @ticket 60057 + * + * Tests the _deprecated_argumentfunction when called without a version number. + * + * This method verifies that the _deprecated_argumentfunction throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test_deprecated_argument() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name was called with an argument that is deprecated since version 1 with no alternative available.' ); + + _deprecated_argument( 'function_name', 1 ); + } +} diff --git a/tests/phpunit/tests/functions/deprecatedHook.php b/tests/phpunit/tests/functions/deprecatedHook.php deleted file mode 100644 index 3c6d6fe96ebd8..0000000000000 --- a/tests/phpunit/tests/functions/deprecatedHook.php +++ /dev/null @@ -1,125 +0,0 @@ -expectDeprecation(); - $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1! Use replacement_hook instead. message' ); - - $action = new MockAction(); - add_filter( 'deprecated_hook_run', array( $action, 'action' ) ); - - _deprecated_hook( 'hook_name', 1, 'replacement_hook', 'message' ); - - $this->assertSame( 1, $action->get_call_count() ); - } - - /** - * @ticket 60057 - * - * This method tests if the '_deprecated_hook_trigger_error' filter is called - * when the __deprecated_hook() function is invoked. - * - * It creates a mock action object and adds a filter to the '_deprecated_hook_trigger_error' - * hook, using the mock action as the callback. Then, it calls the __deprecated_hook() - * function with the specified function name, message, and error level. - * Finally, it asserts that the filter callback is called exactly once by checking - * the call count of the mock action object. - * - * @return void - */ - public function test_deprecated_hook_filter_called() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1! Use replacement_hook instead. message' ); - - $filter = new MockAction(); - add_filter( 'deprecated_hook_trigger_error', array( $filter, 'filter' ) ); - - _deprecated_hook( 'hook_name', 1, 'replacement_hook', 'message' ); - - $this->assertSame( 1, $filter->get_call_count() ); - } - - /** - * @ticket 60057 - * - * Tests the __deprecated_hook function when called without a version number. - * - * This method verifies that the __deprecated_hook function throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test_deprecated_hook_no_replacement() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1 with no alternative available. message' ); - - _deprecated_hook( 'hook_name', 1, '', 'message' ); - } - - /** - * @ticket 60057 - * - * Tests the __deprecated_hook function when called without a version number. - * - * This method verifies that the __deprecated_hook function throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test_deprecated_hook_no_message() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1! Use replacement_hook instead.' ); - - _deprecated_hook( 'hook_name', 1, 'replacement_hook' ); - } - - /** - * @ticket 60057 - * - * Tests the __deprecated_hook function when called without a version number. - * - * This method verifies that the __deprecated_hook function throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test_deprecated_hook() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Hook hook_name is deprecated since version 1 with no alternative available.' ); - - _deprecated_hook( 'hook_name', 1 ); - } -} From b38a887ddd5aa985940d671f3286cb7a2710788a Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 19 Dec 2023 13:42:12 -0500 Subject: [PATCH 06/10] The 'deprecatedArgument' PHPUnit test file is renamed to 'deprecatedFile' to better reflect the functionality being tested. All relevant method names, hooks, comments, and tests have been updated accordingly. This refactoring allows more accurate and specific testing of the '_deprecated_file' function. --- .../tests/functions/deprecatedArgument.php | 109 --------------- .../tests/functions/deprecatedFile.php | 124 ++++++++++++++++++ 2 files changed, 124 insertions(+), 109 deletions(-) delete mode 100644 tests/phpunit/tests/functions/deprecatedArgument.php create mode 100644 tests/phpunit/tests/functions/deprecatedFile.php diff --git a/tests/phpunit/tests/functions/deprecatedArgument.php b/tests/phpunit/tests/functions/deprecatedArgument.php deleted file mode 100644 index 0daf255aac625..0000000000000 --- a/tests/phpunit/tests/functions/deprecatedArgument.php +++ /dev/null @@ -1,109 +0,0 @@ -expectDeprecation(); - $this->expectDeprecationMessage( 'Function function_name was called with an argument that is deprecated since version 1! message' ); - - $action = new MockAction(); - add_filter( 'deprecated_argument_run', array( $action, 'action' ) ); - - _deprecated_argument( 'function_name', 1, 'message' ); - - $this->assertSame( 1, $action->get_call_count() ); - } - - /** - * @ticket 60057 - * - * This method tests if the '_deprecated_argument_trigger_error' filter is called - * when the _deprecated_argument() function is invoked. - * - * It creates a mock action object and adds a filter to the '_deprecated_argument_trigger_error' - * hook, using the mock action as the callback. Then, it calls the __deprecated_argument() - * function with the specified function name, message, and error level. - * Finally, it asserts that the filter callback is called exactly once by checking - * the call count of the mock action object. - * - * @return void - */ - public function test_deprecated_argument_filter_called() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Function function_name was called with an argument that is deprecated since version 1! message' ); - - $filter = new MockAction(); - add_filter( 'deprecated_argument_trigger_error', array( $filter, 'filter' ) ); - - _deprecated_argument( 'function_name', 1, 'message' ); - - $this->assertSame( 1, $filter->get_call_count() ); - } - - /** - * @ticket 60057 - * - * Tests the _deprecated_argumentfunction when called without a version number. - * - * This method verifies that the _deprecated_argumentfunction throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test_deprecated_argument_no_replacement() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Function function_name was called with an argument that is deprecated since version 1! message' ); - - _deprecated_argument( 'function_name', 1, 'message' ); - } - - /** - * @ticket 60057 - * - * Tests the _deprecated_argumentfunction when called without a version number. - * - * This method verifies that the _deprecated_argumentfunction throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test_deprecated_argument() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Function function_name was called with an argument that is deprecated since version 1 with no alternative available.' ); - - _deprecated_argument( 'function_name', 1 ); - } -} diff --git a/tests/phpunit/tests/functions/deprecatedFile.php b/tests/phpunit/tests/functions/deprecatedFile.php new file mode 100644 index 0000000000000..7bf4d077488c6 --- /dev/null +++ b/tests/phpunit/tests/functions/deprecatedFile.php @@ -0,0 +1,124 @@ +expectDeprecation(); + $this->expectDeprecationMessage( 'File file_name is deprecated since version 1! Use replacement_file instead. message' ); + + $action = new MockAction(); + add_filter( 'deprecated_file_run', array( $action, 'action' ) ); + + _deprecated_file( 'file_name', 1, 'replacement_file', 'message' ); + + $this->assertSame( 1, $action->get_call_count() ); + } + + /** + * @ticket 60057 + * + * This method tests if the '_deprecated_file_trigger_error' filter is called + * when the _deprecated_file() function is invoked. + * + * It creates a mock action object and adds a filter to the '_deprecated_file_trigger_error' + * hook, using the mock action as the callback. Then, it calls the __deprecated_file() + * function with the specified function name, message, and error level. + * Finally, it asserts that the filter callback is called exactly once by checking + * the call count of the mock action object. + * + * @return void + */ + public function test_deprecated_file_filter_called() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'File file_name is deprecated since version 1! Use replacement_file instead. message' ); + + $filter = new MockAction(); + add_filter( 'deprecated_file_trigger_error', array( $filter, 'filter' ) ); + + _deprecated_file( 'file_name', 1, 'replacement_file', 'message' ); + + $this->assertSame( 1, $filter->get_call_count() ); + } + + /** + * @ticket 60057 + * + * Tests the _deprecated_filefunction when called without a version number. + * + * This method verifies that the _deprecated_filefunction throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test_deprecated_file_no_replacement() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'File file_name is deprecated since version 1 with no alternative available. message' ); + + _deprecated_file( 'file_name', 1, '', 'message' ); + } + + /** + * @ticket 60057 + * + * Tests the _deprecated_filefunction when called without a version number. + * + * This method verifies that the _deprecated_filefunction throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test_deprecated_file_no_message() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'File file_name is deprecated since version 1! Use replacement_file instead.' ); + + _deprecated_file( 'file_name', 1, 'replacement_file' ); + } + /** + * @ticket 60057 + * + * Tests the _deprecated_filefunction when called without a version number. + * + * This method verifies that the _deprecated_filefunction throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test_deprecated_file() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'File file_name is deprecated since version 1 with no alternative available.' ); + + _deprecated_file( 'file_name', 1 ); + } +} From 6af2fdde661c04ffbc06c442a16d7acb9ef9a776 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 19 Dec 2023 15:32:27 -0500 Subject: [PATCH 07/10] Fix typo in _deprecated_class function comment A typo was detected and fixed in the phpunit test file 'deprecatedClass.php'. The underscore separating '_deprecated_class' and 'function' in the method comments section was missing, which could lead to readability issues. --- .../tests/functions/deprecatedClass.php | 94 +++++++++++++ .../tests/functions/deprecatedFile.php | 124 ------------------ 2 files changed, 94 insertions(+), 124 deletions(-) create mode 100644 tests/phpunit/tests/functions/deprecatedClass.php delete mode 100644 tests/phpunit/tests/functions/deprecatedFile.php diff --git a/tests/phpunit/tests/functions/deprecatedClass.php b/tests/phpunit/tests/functions/deprecatedClass.php new file mode 100644 index 0000000000000..e0e0ebc257b2f --- /dev/null +++ b/tests/phpunit/tests/functions/deprecatedClass.php @@ -0,0 +1,94 @@ +expectDeprecation(); + $this->expectDeprecationMessage( 'Class class_name is deprecated since version 1! Use replacement_class instead.' ); + + $action = new MockAction(); + add_filter( 'deprecated_class_run', array( $action, 'action' ) ); + + _deprecated_class( 'class_name', 1, 'replacement_class' ); + + $this->assertSame( 1, $action->get_call_count() ); + } + + /** + * @ticket 60114 + * + * This method tests if the '_deprecated_class_trigger_error' filter is called + * when the _deprecated_class() function is invoked. + * + * It creates a mock action object and adds a filter to the '_deprecated_class_trigger_error' + * hook, using the mock action as the callback. Then, it calls the __deprecated_class() + * function with the specified function name, message, and error level. + * Finally, it asserts that the filter callback is called exactly once by checking + * the call count of the mock action object. + * + * @return void + */ + public function test_deprecated_class_filter_called() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Class class_name is deprecated since version 1! Use replacement_class instead.' ); + + $filter = new MockAction(); + add_filter( 'deprecated_class_trigger_error', array( $filter, 'filter' ) ); + + _deprecated_class( 'class_name', 1, 'replacement_class' ); + + $this->assertSame( 1, $filter->get_call_count() ); + } + + /** + * @ticket 60114 + * + * Tests the _deprecated_classfunction when called without a version number. + * + * This method verifies that the _deprecated_classfunction throws a notice and displays the correct message when called without a version number. + * + * @return void + */ + public function test_deprecated_class_no_replacement() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Class class_name is deprecated since version 1 with no alternative available.' ); + + _deprecated_class( 'class_name', 1 ); + } + +} diff --git a/tests/phpunit/tests/functions/deprecatedFile.php b/tests/phpunit/tests/functions/deprecatedFile.php deleted file mode 100644 index 7bf4d077488c6..0000000000000 --- a/tests/phpunit/tests/functions/deprecatedFile.php +++ /dev/null @@ -1,124 +0,0 @@ -expectDeprecation(); - $this->expectDeprecationMessage( 'File file_name is deprecated since version 1! Use replacement_file instead. message' ); - - $action = new MockAction(); - add_filter( 'deprecated_file_run', array( $action, 'action' ) ); - - _deprecated_file( 'file_name', 1, 'replacement_file', 'message' ); - - $this->assertSame( 1, $action->get_call_count() ); - } - - /** - * @ticket 60057 - * - * This method tests if the '_deprecated_file_trigger_error' filter is called - * when the _deprecated_file() function is invoked. - * - * It creates a mock action object and adds a filter to the '_deprecated_file_trigger_error' - * hook, using the mock action as the callback. Then, it calls the __deprecated_file() - * function with the specified function name, message, and error level. - * Finally, it asserts that the filter callback is called exactly once by checking - * the call count of the mock action object. - * - * @return void - */ - public function test_deprecated_file_filter_called() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'File file_name is deprecated since version 1! Use replacement_file instead. message' ); - - $filter = new MockAction(); - add_filter( 'deprecated_file_trigger_error', array( $filter, 'filter' ) ); - - _deprecated_file( 'file_name', 1, 'replacement_file', 'message' ); - - $this->assertSame( 1, $filter->get_call_count() ); - } - - /** - * @ticket 60057 - * - * Tests the _deprecated_filefunction when called without a version number. - * - * This method verifies that the _deprecated_filefunction throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test_deprecated_file_no_replacement() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'File file_name is deprecated since version 1 with no alternative available. message' ); - - _deprecated_file( 'file_name', 1, '', 'message' ); - } - - /** - * @ticket 60057 - * - * Tests the _deprecated_filefunction when called without a version number. - * - * This method verifies that the _deprecated_filefunction throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test_deprecated_file_no_message() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'File file_name is deprecated since version 1! Use replacement_file instead.' ); - - _deprecated_file( 'file_name', 1, 'replacement_file' ); - } - /** - * @ticket 60057 - * - * Tests the _deprecated_filefunction when called without a version number. - * - * This method verifies that the _deprecated_filefunction throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test_deprecated_file() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'File file_name is deprecated since version 1 with no alternative available.' ); - - _deprecated_file( 'file_name', 1 ); - } -} From 1ab9e6cb929b157c7cb7ba7898243c242793550d Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 19 Dec 2023 15:53:55 -0500 Subject: [PATCH 08/10] The PHPUnit test suite has been updated by changing the test class from `deprecatedClass` to `deprecatedFunction`. All associated actions, filters, and method names within the test have been updated to match this change. This ensures our tests now correctly apply to deprecated functions instead of deprecated classes. --- .../tests/functions/deprecatedClass.php | 94 ------------------- .../tests/functions/deprecatedFunction.php | 91 ++++++++++++++++++ 2 files changed, 91 insertions(+), 94 deletions(-) delete mode 100644 tests/phpunit/tests/functions/deprecatedClass.php create mode 100644 tests/phpunit/tests/functions/deprecatedFunction.php diff --git a/tests/phpunit/tests/functions/deprecatedClass.php b/tests/phpunit/tests/functions/deprecatedClass.php deleted file mode 100644 index e0e0ebc257b2f..0000000000000 --- a/tests/phpunit/tests/functions/deprecatedClass.php +++ /dev/null @@ -1,94 +0,0 @@ -expectDeprecation(); - $this->expectDeprecationMessage( 'Class class_name is deprecated since version 1! Use replacement_class instead.' ); - - $action = new MockAction(); - add_filter( 'deprecated_class_run', array( $action, 'action' ) ); - - _deprecated_class( 'class_name', 1, 'replacement_class' ); - - $this->assertSame( 1, $action->get_call_count() ); - } - - /** - * @ticket 60114 - * - * This method tests if the '_deprecated_class_trigger_error' filter is called - * when the _deprecated_class() function is invoked. - * - * It creates a mock action object and adds a filter to the '_deprecated_class_trigger_error' - * hook, using the mock action as the callback. Then, it calls the __deprecated_class() - * function with the specified function name, message, and error level. - * Finally, it asserts that the filter callback is called exactly once by checking - * the call count of the mock action object. - * - * @return void - */ - public function test_deprecated_class_filter_called() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Class class_name is deprecated since version 1! Use replacement_class instead.' ); - - $filter = new MockAction(); - add_filter( 'deprecated_class_trigger_error', array( $filter, 'filter' ) ); - - _deprecated_class( 'class_name', 1, 'replacement_class' ); - - $this->assertSame( 1, $filter->get_call_count() ); - } - - /** - * @ticket 60114 - * - * Tests the _deprecated_classfunction when called without a version number. - * - * This method verifies that the _deprecated_classfunction throws a notice and displays the correct message when called without a version number. - * - * @return void - */ - public function test_deprecated_class_no_replacement() { - $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Class class_name is deprecated since version 1 with no alternative available.' ); - - _deprecated_class( 'class_name', 1 ); - } - -} diff --git a/tests/phpunit/tests/functions/deprecatedFunction.php b/tests/phpunit/tests/functions/deprecatedFunction.php new file mode 100644 index 0000000000000..fe43c7132405a --- /dev/null +++ b/tests/phpunit/tests/functions/deprecatedFunction.php @@ -0,0 +1,91 @@ +expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1! Use replacement_function instead.' ); + + $action = new MockAction(); + add_filter( 'deprecated_function_run', array( $action, 'action' ) ); + + _deprecated_function( 'function_name', 1, 'replacement_function' ); + + $this->assertSame( 1, $action->get_call_count() ); + } + + /** + * @ticket 60116 + * + * This method tests if the '_deprecated_function_trigger_error' filter is called + * when the _deprecated_function() function is invoked. + * + * It creates a mock action object and adds a filter to the '_deprecated_function_trigger_error' + * hook, using the mock action as the callback. Then, it calls the __deprecated_function() + * function with the specified function name, message, and error level. + * Finally, it asserts that the filter callback is called exactly once by checking + * the call count of the mock action object. + * + * @return void + */ + public function test_deprecated_function_filter_called() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1! Use replacement_function instead.' ); + + $filter = new MockAction(); + add_filter( 'deprecated_function_trigger_error', array( $filter, 'filter' ) ); + + _deprecated_function( 'function_name', 1, 'replacement_function' ); + + $this->assertSame( 1, $filter->get_call_count() ); + } + + /** + * @ticket 60116 + * + * + * @return void + */ + public function test_deprecated_function_no_replacement() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1 with no alternative available.' ); + + _deprecated_function( 'function_name', 1 ); + } + +} From fb102dabf3749c70863032209749f17db5d08f56 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Fri, 26 Jun 2026 14:53:10 -0400 Subject: [PATCH 09/10] Update deprecatedFunction.php --- tests/phpunit/tests/functions/deprecatedFunction.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/phpunit/tests/functions/deprecatedFunction.php b/tests/phpunit/tests/functions/deprecatedFunction.php index fe43c7132405a..fe438466a1249 100644 --- a/tests/phpunit/tests/functions/deprecatedFunction.php +++ b/tests/phpunit/tests/functions/deprecatedFunction.php @@ -87,5 +87,4 @@ public function test_deprecated_function_no_replacement() { _deprecated_function( 'function_name', 1 ); } - } From 966478dc1abb54f9f71e6edf9b0865da23bb50be Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Fri, 26 Jun 2026 15:29:29 -0400 Subject: [PATCH 10/10] Update PHPUnit tests to include HTML tags in deprecation messages --- tests/phpunit/tests/functions/deprecatedFunction.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/functions/deprecatedFunction.php b/tests/phpunit/tests/functions/deprecatedFunction.php index fe438466a1249..b83dfbd46b0a2 100644 --- a/tests/phpunit/tests/functions/deprecatedFunction.php +++ b/tests/phpunit/tests/functions/deprecatedFunction.php @@ -39,7 +39,7 @@ public function set_up() { */ public function test_deprecated_function_action_called() { $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1! Use replacement_function instead.' ); + $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1! Use replacement_function instead.' ); $action = new MockAction(); add_filter( 'deprecated_function_run', array( $action, 'action' ) ); @@ -65,7 +65,7 @@ public function test_deprecated_function_action_called() { */ public function test_deprecated_function_filter_called() { $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1! Use replacement_function instead.' ); + $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1! Use replacement_function instead.' ); $filter = new MockAction(); add_filter( 'deprecated_function_trigger_error', array( $filter, 'filter' ) ); @@ -83,7 +83,7 @@ public function test_deprecated_function_filter_called() { */ public function test_deprecated_function_no_replacement() { $this->expectDeprecation(); - $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1 with no alternative available.' ); + $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1 with no alternative available.' ); _deprecated_function( 'function_name', 1 ); }