From db3322ee32f019940ca106fb8a65f52aeb89ccbc Mon Sep 17 00:00:00 2001 From: Colin Stewart <79332690+costdev@users.noreply.github.com> Date: Sun, 1 Dec 2024 10:09:52 +0000 Subject: [PATCH] Add tests for `Controller::__construct()` (#219) --- includes/class-controller.php | 6 +++ .../Controller/Controller_ConstructTest.php | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/phpunit/tests/Controller/Controller_ConstructTest.php diff --git a/includes/class-controller.php b/includes/class-controller.php index 672dd1d..f0ee703 100644 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -27,6 +27,8 @@ public function __construct() { /** * Enable API Rewrites based on the Users settings. * + * @codeCoverageIgnore Side-effects are from other methods already covered by tests. + * * @return void */ private function api_rewrite() { @@ -52,6 +54,8 @@ private function api_rewrite() { /** * Ajax action to clear the Log file. * + * @codeCoverageIgnore Cannot be tested. Results in script termination. + * * @return void */ public function clear_log() { @@ -82,6 +86,8 @@ public function clear_log() { /** * Ajax action to read the Log file. * + * @codeCoverageIgnore Cannot be tested. Results in script termination. + * * @return void */ public function read_log() { diff --git a/tests/phpunit/tests/Controller/Controller_ConstructTest.php b/tests/phpunit/tests/Controller/Controller_ConstructTest.php new file mode 100644 index 0000000..c1eb0dd --- /dev/null +++ b/tests/phpunit/tests/Controller/Controller_ConstructTest.php @@ -0,0 +1,44 @@ +assertIsInt( has_action( $hook, [ $controller, $method ] ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_hooks_and_methods() { + return [ + 'wp_ajax_aspireupdate_clear_log -> clear_log' => [ + 'hook' => 'wp_ajax_aspireupdate_clear_log', + 'method' => 'clear_log', + ], + 'wp_ajax_aspireupdate_read_log -> read_log' => [ + 'hook' => 'wp_ajax_aspireupdate_read_log', + 'method' => 'read_log', + ], + ]; + } +}