From a3416725ad732d7d777aa6fe94ff0ab2acf079b6 Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Sun, 5 Feb 2023 21:36:48 +0000 Subject: [PATCH 01/17] setup abstract check runner class --- includes/Checker/Abstract_Check_Runner.php | 145 +++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 includes/Checker/Abstract_Check_Runner.php diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php new file mode 100644 index 000000000..d5507056a --- /dev/null +++ b/includes/Checker/Abstract_Check_Runner.php @@ -0,0 +1,145 @@ +requires_universal_preparations( $this->checks_to_run ) ) { + $preparation = new Universal_Runtime_Preparation(); + return $preparation->prepare(); + } + + return null; + } + + /** + * Determine if any of the checks requires the universal runtime preparation. + * + * @since n.e.x.t + * + * @param array $checks An array of check instances to run. + * + * @return boolean Returns true if one or more checks requires the universal runtime preparation. + */ + protected function requires_universal_preparations( array $checks ) { + foreach ( $checks as $check ) { + if ( $check instanceof Runtime_Check ) { + return true; + } + } + + return false; + } + + /** + * Return all shared preparations used by the checks to run. + * + * @since n.e.x.t + * + * @param array $checks An array of check instances to run. + * + * @return array An array of preparations to run. + */ + private function get_shared_preparations( array $checks ) { + $shared_preparations = array(); + + foreach ( $checks as $check ) { + if ( ! $check instanceof With_Shared_Preparations ) { + continue; + } + + $preparations = $check->get_shared_preparations(); + + foreach ( $preparations as $class => $parameters ) { + if ( ! isset( $shared_preparations[ $class ] ) ) { + $shared_preparations[ $class ] = $parameters; + } + } + } + + return $shared_preparations; + } + + /** + * Run the checks against the plugin. + * + * @since n.e.x.t + * + * @return Check_Result + */ + public function run() { + $checks = $this->checks->get_checks( $this->checks_to_run ); + + $preparations = $this->get_shared_preparations( $checks ); + $cleanups = array(); + + foreach ( $preparations as $preparation ) { + $cleanups[] = $preparation->prepare(); + } + + $results = $this->checks->run_checks( $checks ); + + if ( ! empty( $cleanups ) ) { + foreach ( $cleanups as $cleanup ) { + $cleanup(); + } + } + + return $results; + } +} From a2c742034b273f968c399c556d78a9cc39035793 Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Wed, 8 Feb 2023 14:22:55 +0000 Subject: [PATCH 02/17] update get_shared_preparations method --- includes/Checker/Abstract_Check_Runner.php | 48 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index d5507056a..375ab2364 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -9,6 +9,7 @@ use WordPress\Plugin_Check\Checker\Check_Runner; use WordPress\Plugin_Check\Checker\Check_Result; +use WordPress\Plugin_Check\Checker\Preparations\Universal_Runtime_Preparation; /** * Abstract Check Runner class. @@ -25,6 +26,14 @@ abstract class Abstract_Check_Runner implements Check_Runner { */ protected $checks; + /** + * Instance of the Check_Context class. + * + * @since n.e.x.t + * @var Check_Context + */ + protected $context; + /** * Array of Check instances to run. * @@ -43,7 +52,7 @@ abstract class Abstract_Check_Runner implements Check_Runner { abstract public function is_plugin_check(); /** - * Setup checks and preparations based on the request. + * Setup the check context, checks and preparations based on the request. * * @since n.e.x.t */ @@ -60,7 +69,7 @@ abstract protected function setup_checks(); */ public function prepare() { if ( ! $this->requires_universal_preparations( $this->checks_to_run ) ) { - $preparation = new Universal_Runtime_Preparation(); + $preparation = new Universal_Runtime_Preparation( $this->context ); return $preparation->prepare(); } @@ -91,9 +100,9 @@ protected function requires_universal_preparations( array $checks ) { * * @since n.e.x.t * - * @param array $checks An array of check instances to run. + * @param array $checks An array of Check instances to run. * - * @return array An array of preparations to run. + * @return array An array of reparations to run. */ private function get_shared_preparations( array $checks ) { $shared_preparations = array(); @@ -105,13 +114,38 @@ private function get_shared_preparations( array $checks ) { $preparations = $check->get_shared_preparations(); - foreach ( $preparations as $class => $parameters ) { - if ( ! isset( $shared_preparations[ $class ] ) ) { - $shared_preparations[ $class ] = $parameters; + foreach ( $preparations as $class => $args ) { + // Find the array keys for any existing shared preparation with the same class. + $existing_keys = array_keys( array_column( $shared_preparations, 'class' ), $class, true ); + + // Set a flag as to whether the checks preparation should be added to the shared preparations array. + $unique = true; + + foreach ( $existing_keys as $key ) { + // If the shared preparation already exists with the same arguments. + if ( isset( $shared_preparations[ $key ]['args'] ) && $shared_preparations[ $key ]['args'] === $args ) { + $unique = false; + } + } + + // If the shared preparation is unique, instantiate it and add to the shared preparations. + if ( $unique ) { + $shared_preparations[] = array( + 'class' => $class, + 'args' => $args, + ); } } } + // Map over the shared preparations and instantiate the classes. + $shared_preparations = array_map( + function( $preparation ) { + return new $preparation['class']( ...$preparation['args'] ); + }, + $shared_preparations + ); + return $shared_preparations; } From 69b0d663085ea2ec63157867063ab8cf05c15430 Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Wed, 8 Feb 2023 14:30:49 +0000 Subject: [PATCH 03/17] minor fixes --- includes/Checker/Abstract_Check_Runner.php | 64 +++++++++++----------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 375ab2364..7817ff0c5 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -76,6 +76,34 @@ public function prepare() { return null; } + /** + * Run the checks against the plugin. + * + * @since n.e.x.t + * + * @return Check_Result + */ + public function run() { + $checks = $this->checks->get_checks( $this->checks_to_run ); + + $preparations = $this->get_shared_preparations( $checks ); + $cleanups = array(); + + foreach ( $preparations as $preparation ) { + $cleanups[] = $preparation->prepare(); + } + + $results = $this->checks->run_checks( $checks ); + + if ( ! empty( $cleanups ) ) { + foreach ( $cleanups as $cleanup ) { + $cleanup(); + } + } + + return $results; + } + /** * Determine if any of the checks requires the universal runtime preparation. * @@ -115,20 +143,20 @@ private function get_shared_preparations( array $checks ) { $preparations = $check->get_shared_preparations(); foreach ( $preparations as $class => $args ) { - // Find the array keys for any existing shared preparation with the same class. + // Find the array keys for any existing shared preparation with the same class name. $existing_keys = array_keys( array_column( $shared_preparations, 'class' ), $class, true ); - // Set a flag as to whether the checks preparation should be added to the shared preparations array. + // Set a flag to add the preparation to the shared preparations array. $unique = true; foreach ( $existing_keys as $key ) { - // If the shared preparation already exists with the same arguments. + // If the shared preparation already exists with the same parameters. if ( isset( $shared_preparations[ $key ]['args'] ) && $shared_preparations[ $key ]['args'] === $args ) { $unique = false; } } - // If the shared preparation is unique, instantiate it and add to the shared preparations. + // Add to the shared preparations if the shared preparation is unique. if ( $unique ) { $shared_preparations[] = array( 'class' => $class, @@ -148,32 +176,4 @@ function( $preparation ) { return $shared_preparations; } - - /** - * Run the checks against the plugin. - * - * @since n.e.x.t - * - * @return Check_Result - */ - public function run() { - $checks = $this->checks->get_checks( $this->checks_to_run ); - - $preparations = $this->get_shared_preparations( $checks ); - $cleanups = array(); - - foreach ( $preparations as $preparation ) { - $cleanups[] = $preparation->prepare(); - } - - $results = $this->checks->run_checks( $checks ); - - if ( ! empty( $cleanups ) ) { - foreach ( $cleanups as $cleanup ) { - $cleanup(); - } - } - - return $results; - } } From 0b0b4ae126c23561177bf8cecae207bd2015df78 Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Thu, 9 Feb 2023 18:01:05 +0000 Subject: [PATCH 04/17] simplify get_shared_preparations logic --- includes/Checker/Abstract_Check_Runner.php | 39 ++++++---------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 7817ff0c5..afa695ca2 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -52,14 +52,14 @@ abstract class Abstract_Check_Runner implements Check_Runner { abstract public function is_plugin_check(); /** - * Setup the check context, checks and preparations based on the request. + * Sets up the check context, checks and preparations based on the request. * * @since n.e.x.t */ abstract protected function setup_checks(); /** - * Prepare the environment for running the requested checks. + * Prepares the environment for running the requested checks. * * @since n.e.x.t * @@ -77,7 +77,7 @@ public function prepare() { } /** - * Run the checks against the plugin. + * Runs the checks against the plugin. * * @since n.e.x.t * @@ -90,7 +90,8 @@ public function run() { $cleanups = array(); foreach ( $preparations as $preparation ) { - $cleanups[] = $preparation->prepare(); + $instance = new $preparation['class']( ...$preparation['args'] ); + $cleanups[] = $instance->prepare(); } $results = $this->checks->run_checks( $checks ); @@ -105,7 +106,7 @@ public function run() { } /** - * Determine if any of the checks requires the universal runtime preparation. + * Determines if any of the checks requires the universal runtime preparation. * * @since n.e.x.t * @@ -124,7 +125,7 @@ protected function requires_universal_preparations( array $checks ) { } /** - * Return all shared preparations used by the checks to run. + * Returns all shared preparations used by the checks to run. * * @since n.e.x.t * @@ -143,22 +144,10 @@ private function get_shared_preparations( array $checks ) { $preparations = $check->get_shared_preparations(); foreach ( $preparations as $class => $args ) { - // Find the array keys for any existing shared preparation with the same class name. - $existing_keys = array_keys( array_column( $shared_preparations, 'class' ), $class, true ); + $key = $class . '::' . md5( json_encode( $args ) ); - // Set a flag to add the preparation to the shared preparations array. - $unique = true; - - foreach ( $existing_keys as $key ) { - // If the shared preparation already exists with the same parameters. - if ( isset( $shared_preparations[ $key ]['args'] ) && $shared_preparations[ $key ]['args'] === $args ) { - $unique = false; - } - } - - // Add to the shared preparations if the shared preparation is unique. - if ( $unique ) { - $shared_preparations[] = array( + if ( ! isset( $shared_preparations[ $key ] ) ) { + $shared_preparations[ $key ] = array( 'class' => $class, 'args' => $args, ); @@ -166,14 +155,6 @@ private function get_shared_preparations( array $checks ) { } } - // Map over the shared preparations and instantiate the classes. - $shared_preparations = array_map( - function( $preparation ) { - return new $preparation['class']( ...$preparation['args'] ); - }, - $shared_preparations - ); - return $shared_preparations; } } From a5e9f6ebef14fa5cbf645bd6b9aaab224acea98b Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Thu, 9 Feb 2023 18:24:00 +0000 Subject: [PATCH 05/17] replace properties with methods --- includes/Checker/Abstract_Check_Runner.php | 47 +++++++++------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index afa695ca2..66e118f5f 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -19,44 +19,40 @@ abstract class Abstract_Check_Runner implements Check_Runner { /** - * Instance of the Checks class. + * Determines if the current request is intended for the plugin checker. * * @since n.e.x.t - * @var Checks - */ - protected $checks; - - /** - * Instance of the Check_Context class. * - * @since n.e.x.t - * @var Check_Context + * @return bool Returns true if the check is for plugin else false. */ - protected $context; + abstract public function is_plugin_check(); /** - * Array of Check instances to run. + * Creates and returns an instance of the Checks class based on the request. * * @since n.e.x.t - * @var array + * + * @return Checks An instances of the Checks class. */ - protected $checks_to_run; + abstract protected function get_checks(); /** - * Determines if the current request is intended for the plugin checker. + * Creates and returns the Check_Context for the plugin to check based on the request. * * @since n.e.x.t * - * @return boolean Returns true if the check is for plugin else false. + * @return Check_Context The Check_Context for the plugin to check. */ - abstract public function is_plugin_check(); + abstract protected function get_context(); /** - * Sets up the check context, checks and preparations based on the request. + * Creates and returns an array of Check instances to run based on the request. * * @since n.e.x.t + * + * @return array An array of Check instances. */ - abstract protected function setup_checks(); + abstract protected function get_checks_to_run(); /** * Prepares the environment for running the requested checks. @@ -68,12 +64,12 @@ abstract protected function setup_checks(); * @throws Exception Thrown exception when preparation fails. */ public function prepare() { - if ( ! $this->requires_universal_preparations( $this->checks_to_run ) ) { - $preparation = new Universal_Runtime_Preparation( $this->context ); + if ( ! $this->requires_universal_preparations( $this->get_checks_to_run() ) ) { + $preparation = new Universal_Runtime_Preparation( $this->get_context() ); return $preparation->prepare(); } - return null; + return function() {}; } /** @@ -84,8 +80,7 @@ public function prepare() { * @return Check_Result */ public function run() { - $checks = $this->checks->get_checks( $this->checks_to_run ); - + $checks = $this->get_checks_to_run(); $preparations = $this->get_shared_preparations( $checks ); $cleanups = array(); @@ -94,7 +89,7 @@ public function run() { $cleanups[] = $instance->prepare(); } - $results = $this->checks->run_checks( $checks ); + $results = $this->get_checks()->run_checks( $checks ); if ( ! empty( $cleanups ) ) { foreach ( $cleanups as $cleanup ) { @@ -111,8 +106,7 @@ public function run() { * @since n.e.x.t * * @param array $checks An array of check instances to run. - * - * @return boolean Returns true if one or more checks requires the universal runtime preparation. + * @return bool Returns true if one or more checks requires the universal runtime preparation. */ protected function requires_universal_preparations( array $checks ) { foreach ( $checks as $check ) { @@ -130,7 +124,6 @@ protected function requires_universal_preparations( array $checks ) { * @since n.e.x.t * * @param array $checks An array of Check instances to run. - * * @return array An array of reparations to run. */ private function get_shared_preparations( array $checks ) { From fff26bca6f02d0ea06d383f5f96a221eab355074 Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Thu, 9 Feb 2023 18:40:32 +0000 Subject: [PATCH 06/17] update imports --- includes/Checker/Abstract_Check_Runner.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 66e118f5f..4e01ddec4 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -7,9 +7,7 @@ namespace WordPress\Plugin_Check\Checker; -use WordPress\Plugin_Check\Checker\Check_Runner; -use WordPress\Plugin_Check\Checker\Check_Result; -use WordPress\Plugin_Check\Checker\Preparations\Universal_Runtime_Preparation; +use Preparations\Universal_Runtime_Preparation; /** * Abstract Check Runner class. From 86d693004a7ccf29c5ff1068e707c47fe69a35cd Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Thu, 9 Feb 2023 18:43:40 +0000 Subject: [PATCH 07/17] update docblock comments --- includes/Checker/Abstract_Check_Runner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 4e01ddec4..1e36b7060 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -75,7 +75,7 @@ public function prepare() { * * @since n.e.x.t * - * @return Check_Result + * @return Check_Result An object containing all check results. */ public function run() { $checks = $this->get_checks_to_run(); From 319a8e0edcd8cb88ad382a8452da264ef928aa88 Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Fri, 10 Feb 2023 15:12:55 +0000 Subject: [PATCH 08/17] create CLI_Runner class --- includes/Checker/CLI_Runner.php | 104 ++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 includes/Checker/CLI_Runner.php diff --git a/includes/Checker/CLI_Runner.php b/includes/Checker/CLI_Runner.php new file mode 100644 index 000000000..ddc173407 --- /dev/null +++ b/includes/Checker/CLI_Runner.php @@ -0,0 +1,104 @@ +get_plugin_main_file() ); + } + + /** + * Returns an instance of the Check_Context class. + * + * @since n.e.x.t + * + * @return Check_Context + */ + protected function get_context() { + return new Check_Context( $this->get_plugin_main_file() ); + } + + /** + * Returns an array of Check instances to run. + * + * @since n.e.x.t + * + * @return array An array of Check instances to run. + */ + protected function get_checks_to_run() { + $checks = []; + + foreach( $_SERVER['argv'] as $value ) { + if ( 0 <= strpos( $value, '--checks=' ) ) { + $checks = $value; + break; + } + } + + if ( ! empty( $checks ) ) { + $checks = explode( ',', $checks ); + } + + return $this->get_checks()->get_checks( $checks ); + } +} From bac30bbb621cc7efe3a24dd4d8b56d37b4d60c3d Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Fri, 10 Feb 2023 16:09:44 +0000 Subject: [PATCH 09/17] add tests --- includes/Checker/Abstract_Check_Runner.php | 4 +- includes/Checker/CLI_Runner.php | 25 ++-- includes/Checker/Checks.php | 2 +- tests/Checker/CLI_Runner_Tests.php | 155 +++++++++++++++++++++ tests/testdata/Checks/Runtime_Check.php | 12 ++ 5 files changed, 183 insertions(+), 15 deletions(-) create mode 100644 tests/Checker/CLI_Runner_Tests.php create mode 100644 tests/testdata/Checks/Runtime_Check.php diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 1e36b7060..ac8a6b45b 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -7,7 +7,7 @@ namespace WordPress\Plugin_Check\Checker; -use Preparations\Universal_Runtime_Preparation; +use WordPress\Plugin_Check\Checker\Preparations\Universal_Runtime_Preparation; /** * Abstract Check Runner class. @@ -62,7 +62,7 @@ abstract protected function get_checks_to_run(); * @throws Exception Thrown exception when preparation fails. */ public function prepare() { - if ( ! $this->requires_universal_preparations( $this->get_checks_to_run() ) ) { + if ( $this->requires_universal_preparations( $this->get_checks_to_run() ) ) { $preparation = new Universal_Runtime_Preparation( $this->get_context() ); return $preparation->prepare(); } diff --git a/includes/Checker/CLI_Runner.php b/includes/Checker/CLI_Runner.php index ddc173407..648584576 100644 --- a/includes/Checker/CLI_Runner.php +++ b/includes/Checker/CLI_Runner.php @@ -31,9 +31,9 @@ public function is_plugin_check() { } if ( - $_SERVER['argv'][0] === 'wp' && - $_SERVER['argv'][1] === 'plugin' && - $_SERVER['argv'][2] === 'check' + 'wp' === $_SERVER['argv'][0] && + 'plugin' === $_SERVER['argv'][1] && + 'check' === $_SERVER['argv'][2] ) { return true; } @@ -62,8 +62,7 @@ private function get_plugin_main_file() { * * @return Checks */ - protected function get_checks() - { + protected function get_checks() { return new Checks( $this->get_plugin_main_file() ); } @@ -86,19 +85,21 @@ protected function get_context() { * @return array An array of Check instances to run. */ protected function get_checks_to_run() { - $checks = []; + $checks = array(); - foreach( $_SERVER['argv'] as $value ) { - if ( 0 <= strpos( $value, '--checks=' ) ) { - $checks = $value; + foreach ( $_SERVER['argv'] as $value ) { + if ( false !== strpos( $value, '--checks=' ) ) { + $checks = explode( ',', str_replace( '--checks=', '', $value ) ); break; } } - if ( ! empty( $checks ) ) { - $checks = explode( ',', $checks ); + $all_checks = $this->get_checks()->get_checks(); + + if ( empty( $checks ) ) { + return $all_checks; } - return $this->get_checks()->get_checks( $checks ); + return array_intersect_key( $all_checks, array_flip( $checks ) ); } } diff --git a/includes/Checker/Checks.php b/includes/Checker/Checks.php index 7219269df..8a2fd56d9 100644 --- a/includes/Checker/Checks.php +++ b/includes/Checker/Checks.php @@ -54,7 +54,7 @@ public function run_checks( array $checks ) { $checks_to_run = array_filter( $checks, function( $check ) use ( $all_checks ) { - return in_array( $check, $all_checks, true ); + return in_array( $check, $all_checks ); // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict } ); diff --git a/tests/Checker/CLI_Runner_Tests.php b/tests/Checker/CLI_Runner_Tests.php new file mode 100644 index 000000000..744cfbb48 --- /dev/null +++ b/tests/Checker/CLI_Runner_Tests.php @@ -0,0 +1,155 @@ +assertTrue( $runner->is_plugin_check() ); + } + + public function test_is_plugin_check_returns_false() { + $runner = new CLI_Runner(); + + $this->assertTrue( $runner->is_plugin_check() ); + } + + public function test_prepare_with_runtime_check() { + $_SERVER['argv'] = array( + 'wp', + 'plugin', + 'check', + 'plugin-check', + '--checks=runtime-check', + ); + + add_filter( + 'wp_plugin_check_checks', + function( $checks ) { + return array( + 'runtime-check' => new WordPress\Plugin_Check\Test_Data\Runtime_Check(), + ); + } + ); + + $runner = new CLI_Runner(); + $cleanup = $runner->prepare(); + + $this->assertIsCallable( $cleanup ); + + // Assert the Universal_Runtume_Preparation was run. + $this->assertTrue( has_filter( 'option_active_plugins' ) ); + $this->assertTrue( has_filter( 'default_option_active_plugins' ) ); + $this->assertTrue( has_filter( 'stylesheet' ) ); + $this->assertTrue( has_filter( 'template' ) ); + $this->assertTrue( has_filter( 'pre_option_template' ) ); + $this->assertTrue( has_filter( 'pre_option_stylesheet' ) ); + $this->assertTrue( has_filter( 'pre_option_current_theme' ) ); + $this->assertTrue( has_filter( 'pre_option_template_root' ) ); + $this->assertTrue( has_filter( 'pre_option_stylesheet_root' ) ); + } + + public function test_prepare_with_static_check() { + $_SERVER['argv'] = array( + 'wp', + 'plugin', + 'check', + 'plugin-check', + '--checks=empty-check', + ); + + add_filter( + 'wp_plugin_check_checks', + function( $checks ) { + return array( + 'empty-check' => new WordPress\Plugin_Check\Test_Data\Empty_Check(), + ); + } + ); + + $runner = new CLI_Runner(); + $cleanup = $runner->prepare(); + + $this->assertIsCallable( $cleanup ); + + // Assert the Universal_Runtume_Preparation was not run. + $this->assertFalse( has_filter( 'option_active_plugins' ) ); + $this->assertFalse( has_filter( 'default_option_active_plugins' ) ); + $this->assertFalse( has_filter( 'stylesheet' ) ); + $this->assertFalse( has_filter( 'template' ) ); + $this->assertFalse( has_filter( 'pre_option_template' ) ); + $this->assertFalse( has_filter( 'pre_option_stylesheet' ) ); + $this->assertFalse( has_filter( 'pre_option_current_theme' ) ); + $this->assertFalse( has_filter( 'pre_option_template_root' ) ); + $this->assertFalse( has_filter( 'pre_option_stylesheet_root' ) ); + } + + public function test_run() { + $_SERVER['argv'] = array( + 'wp', + 'plugin', + 'check', + 'plugin-check', + '--checks=empty-check', + ); + + add_filter( + 'wp_plugin_check_checks', + function( $checks ) { + return array( + 'empty-check' => new WordPress\Plugin_Check\Test_Data\Empty_Check(), + ); + } + ); + + $runner = new CLI_Runner(); + $runner->prepare(); + $results = $runner->run(); + + $this->assertInstanceOf( Check_Result::class, $results ); + $this->assertEmpty( $results->get_warnings() ); + $this->assertEmpty( $results->get_errors() ); + } + + public function test_run_with_errors() { + $_SERVER['argv'] = array( + 'wp', + 'plugin', + 'check', + 'plugin-check', + '--checks=error-check', + ); + + add_filter( + 'wp_plugin_check_checks', + function( $checks ) { + return array( + 'error-check' => new WordPress\Plugin_Check\Test_Data\Error_Check(), + ); + } + ); + + $runner = new CLI_Runner(); + $runner->prepare(); + $results = $runner->run(); + + $this->assertInstanceOf( Check_Result::class, $results ); + $this->assertEmpty( $results->get_warnings() ); + $this->assertNotEmpty( $results->get_errors() ); + } +} diff --git a/tests/testdata/Checks/Runtime_Check.php b/tests/testdata/Checks/Runtime_Check.php new file mode 100644 index 000000000..95c22b039 --- /dev/null +++ b/tests/testdata/Checks/Runtime_Check.php @@ -0,0 +1,12 @@ + Date: Fri, 10 Feb 2023 17:02:21 +0000 Subject: [PATCH 10/17] remove imports --- includes/Checker/CLI_Runner.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/includes/Checker/CLI_Runner.php b/includes/Checker/CLI_Runner.php index 648584576..3a46ac931 100644 --- a/includes/Checker/CLI_Runner.php +++ b/includes/Checker/CLI_Runner.php @@ -7,10 +7,6 @@ namespace WordPress\Plugin_Check\Checker; -use WordPress\Plugin_Check\Checker\Checks; -use WordPress\Plugin_Check\Checker\Check_Context; -use WordPress\Plugin_Check\Checker\Abstract_Check_Runner; - /** * CLI Runner class. * From b90860c0331c0dda4b9c3c4dbda74a0c7916e61f Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Fri, 10 Feb 2023 17:19:36 +0000 Subject: [PATCH 11/17] fix tests --- tests/Checker/CLI_Runner_Tests.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Checker/CLI_Runner_Tests.php b/tests/Checker/CLI_Runner_Tests.php index 744cfbb48..278f3f211 100644 --- a/tests/Checker/CLI_Runner_Tests.php +++ b/tests/Checker/CLI_Runner_Tests.php @@ -24,9 +24,11 @@ public function test_is_plugin_check_returns_true() { } public function test_is_plugin_check_returns_false() { + $_SERVER['argv'] = array(); + $runner = new CLI_Runner(); - $this->assertTrue( $runner->is_plugin_check() ); + $this->assertFalse( $runner->is_plugin_check() ); } public function test_prepare_with_runtime_check() { From 63de1b3bc390292af48d2da2fa01aa0f4f0b523f Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Mon, 13 Feb 2023 09:15:47 +0000 Subject: [PATCH 12/17] remove get_context method --- includes/Checker/Abstract_Check_Runner.php | 11 +---------- includes/Checker/CLI_Runner.php | 11 ----------- includes/Checker/Checks.php | 11 +++++++++++ 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index ac8a6b45b..1e49c9f21 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -34,15 +34,6 @@ abstract public function is_plugin_check(); */ abstract protected function get_checks(); - /** - * Creates and returns the Check_Context for the plugin to check based on the request. - * - * @since n.e.x.t - * - * @return Check_Context The Check_Context for the plugin to check. - */ - abstract protected function get_context(); - /** * Creates and returns an array of Check instances to run based on the request. * @@ -63,7 +54,7 @@ abstract protected function get_checks_to_run(); */ public function prepare() { if ( $this->requires_universal_preparations( $this->get_checks_to_run() ) ) { - $preparation = new Universal_Runtime_Preparation( $this->get_context() ); + $preparation = new Universal_Runtime_Preparation( $this->get_checks()->context() ); return $preparation->prepare(); } diff --git a/includes/Checker/CLI_Runner.php b/includes/Checker/CLI_Runner.php index 3a46ac931..77bc9b39f 100644 --- a/includes/Checker/CLI_Runner.php +++ b/includes/Checker/CLI_Runner.php @@ -62,17 +62,6 @@ protected function get_checks() { return new Checks( $this->get_plugin_main_file() ); } - /** - * Returns an instance of the Check_Context class. - * - * @since n.e.x.t - * - * @return Check_Context - */ - protected function get_context() { - return new Check_Context( $this->get_plugin_main_file() ); - } - /** * Returns an array of Check instances to run. * diff --git a/includes/Checker/Checks.php b/includes/Checker/Checks.php index 8a2fd56d9..a6872bdb8 100644 --- a/includes/Checker/Checks.php +++ b/includes/Checker/Checks.php @@ -36,6 +36,17 @@ public function __construct( $plugin_main_file ) { $this->check_context = new Check_Context( $plugin_main_file ); } + /** + * Returns the Check Context. + * + * @since n.e.x.t + * + * @return Check_Context + */ + public function context() { + return $this->check_context; + } + /** * Runs checks against the plugin. * From 24e0d58d8c1dc9a4ea5b1a82efdf6d6d991807fa Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Mon, 13 Feb 2023 09:42:43 +0000 Subject: [PATCH 13/17] update checks methods --- includes/Checker/Abstract_Check_Runner.php | 21 +++++++++++++-------- includes/Checker/CLI_Runner.php | 18 +++++++++++++++--- includes/Checker/Checks.php | 8 +++++--- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 1e49c9f21..0d3f960c2 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -32,16 +32,16 @@ abstract public function is_plugin_check(); * * @return Checks An instances of the Checks class. */ - abstract protected function get_checks(); + abstract protected function get_checks_instance(); /** - * Creates and returns an array of Check instances to run based on the request. + * Returns an array of Check slugs to run based on the request. * * @since n.e.x.t * - * @return array An array of Check instances. + * @return array An array of Check slugs. */ - abstract protected function get_checks_to_run(); + abstract protected function get_check_slugs_to_run(); /** * Prepares the environment for running the requested checks. @@ -54,7 +54,7 @@ abstract protected function get_checks_to_run(); */ public function prepare() { if ( $this->requires_universal_preparations( $this->get_checks_to_run() ) ) { - $preparation = new Universal_Runtime_Preparation( $this->get_checks()->context() ); + $preparation = new Universal_Runtime_Preparation( $this->get_checks_instance()->context() ); return $preparation->prepare(); } @@ -78,7 +78,7 @@ public function run() { $cleanups[] = $instance->prepare(); } - $results = $this->get_checks()->run_checks( $checks ); + $results = $this->get_checks_instance()->run_checks( $checks ); if ( ! empty( $cleanups ) ) { foreach ( $cleanups as $cleanup ) { @@ -113,7 +113,12 @@ protected function requires_universal_preparations( array $checks ) { * @since n.e.x.t * * @param array $checks An array of Check instances to run. - * @return array An array of reparations to run. + * @return array { + * An array of Preparations to run where each item is an array with the class name and args. + * + * @type string $class The full class name of the Preparation. + * @type array $args An array of parameters to pass to the class constructor. + * } */ private function get_shared_preparations( array $checks ) { $shared_preparations = array(); @@ -137,6 +142,6 @@ private function get_shared_preparations( array $checks ) { } } - return $shared_preparations; + return array_values( $shared_preparations ); } } diff --git a/includes/Checker/CLI_Runner.php b/includes/Checker/CLI_Runner.php index 77bc9b39f..276dc0c7d 100644 --- a/includes/Checker/CLI_Runner.php +++ b/includes/Checker/CLI_Runner.php @@ -58,7 +58,7 @@ private function get_plugin_main_file() { * * @return Checks */ - protected function get_checks() { + protected function get_checks_instance() { return new Checks( $this->get_plugin_main_file() ); } @@ -69,7 +69,7 @@ protected function get_checks() { * * @return array An array of Check instances to run. */ - protected function get_checks_to_run() { + protected function get_check_slugs_to_run() { $checks = array(); foreach ( $_SERVER['argv'] as $value ) { @@ -79,7 +79,19 @@ protected function get_checks_to_run() { } } - $all_checks = $this->get_checks()->get_checks(); + return $checks; + } + + /** + * Returns the Check instances to run. + * + * @since n.e.x.t + * + * @return array An array of Check instances. + */ + protected function get_checks_to_run() { + $check_slugs = $this->get_check_slugs_to_run(); + $all_checks = $this->get_checks_instance()->get_checks(); if ( empty( $checks ) ) { return $all_checks; diff --git a/includes/Checker/Checks.php b/includes/Checker/Checks.php index a6872bdb8..34b5de55c 100644 --- a/includes/Checker/Checks.php +++ b/includes/Checker/Checks.php @@ -116,18 +116,20 @@ protected function run_check_with_result( Check $check, Check_Result $result ) { * * @since n.e.x.t * - * @return array List of plugin check class instances implementing the Check interface. + * @return array An array map of check slugs to Check instances. */ public function get_checks() { // TODO: Add checks once implemented. - $checks = array(); + $checks = array( + 'i18n-usage' => new Checks\I18n_Usage_Check(), + ); /** * Filters the available plugin check classes. * * @since n.e.x.t * - * @param array $checks List of plugin check class instances implementing the Check interface. + * @param array $checks An array map of check slugs to Check instances. */ return apply_filters( 'wp_plugin_check_checks', $checks ); } From 151ba82ea2e9677a86086efa3171ffa1d7812260 Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Mon, 13 Feb 2023 10:42:39 +0000 Subject: [PATCH 14/17] create Plugin_Request_Utility class --- includes/Checker/Abstract_Check_Runner.php | 18 ++++++ includes/Checker/CLI_Runner.php | 31 +++------ includes/Utilities/Plugin_Request_Utility.php | 63 +++++++++++++++++++ .../Plugin_Request_Utility_Tests.php | 31 +++++++++ 4 files changed, 122 insertions(+), 21 deletions(-) create mode 100644 includes/Utilities/Plugin_Request_Utility.php create mode 100644 tests/Utilities/Plugin_Request_Utility_Tests.php diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 0d3f960c2..be8f383ed 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -144,4 +144,22 @@ private function get_shared_preparations( array $checks ) { return array_values( $shared_preparations ); } + + /** + * Returns the Check instances to run. + * + * @since n.e.x.t + * + * @return array An array of Check instances. + */ + protected function get_checks_to_run() { + $check_slugs = $this->get_check_slugs_to_run(); + $all_checks = $this->get_checks_instance()->get_checks(); + + if ( empty( $checks ) ) { + return $all_checks; + } + + return array_intersect_key( $all_checks, array_flip( $check_slugs ) ); + } } diff --git a/includes/Checker/CLI_Runner.php b/includes/Checker/CLI_Runner.php index 276dc0c7d..fcbb412ef 100644 --- a/includes/Checker/CLI_Runner.php +++ b/includes/Checker/CLI_Runner.php @@ -7,6 +7,8 @@ namespace WordPress\Plugin_Check\Checker; +use WordPress\Plugin_Check\Utilities\Plugin_Request_Utility; + /** * CLI Runner class. * @@ -22,7 +24,7 @@ class CLI_Runner extends Abstract_Check_Runner { * @return bool */ public function is_plugin_check() { - if ( empty( $_SERVER['argv'] ) ) { + if ( empty( $_SERVER['argv'] ) || 3 > count( $_SERVER['argv'] ) ) { return false; } @@ -43,12 +45,15 @@ public function is_plugin_check() { * @since n.e.x.t * * @return string The absolute path to the plugin main file. + * + * @throws Exception Thrown if an invalid basename or plugin slug is provided. */ private function get_plugin_main_file() { // Get the plugin name from the command line arguments. - $plugin_name = $_SERVER['argv'][3]; + $plugin_slug = isset( $_SERVER['argv'][3] ) ? $_SERVER['argv'][3] : ''; + $plugin_file = Plugin_Request_Utility::get_plugin_basename_from_input( $plugin_slug ); - return WP_PLUGIN_DIR . '/' . $plugin_name . '/' . $plugin_name . '.php'; + return WP_PLUGIN_DIR . '/' . $plugin_file; } /** @@ -57,6 +62,8 @@ private function get_plugin_main_file() { * @since n.e.x.t * * @return Checks + * + * @throws Exception Thrown if the plugin main file cannot be found based on the CLI input. */ protected function get_checks_instance() { return new Checks( $this->get_plugin_main_file() ); @@ -81,22 +88,4 @@ protected function get_check_slugs_to_run() { return $checks; } - - /** - * Returns the Check instances to run. - * - * @since n.e.x.t - * - * @return array An array of Check instances. - */ - protected function get_checks_to_run() { - $check_slugs = $this->get_check_slugs_to_run(); - $all_checks = $this->get_checks_instance()->get_checks(); - - if ( empty( $checks ) ) { - return $all_checks; - } - - return array_intersect_key( $all_checks, array_flip( $checks ) ); - } } diff --git a/includes/Utilities/Plugin_Request_Utility.php b/includes/Utilities/Plugin_Request_Utility.php new file mode 100644 index 000000000..bcb481256 --- /dev/null +++ b/includes/Utilities/Plugin_Request_Utility.php @@ -0,0 +1,63 @@ + $plugin_data ) { + if ( strpos( $plugin_basename, $plugin_slug . '/' ) === 0 ) { + return $plugin_basename; + } + } + + throw new Exception( + sprintf( + 'Invalid positional argument. Plugin with slug %s is not installed.', + $plugin_slug + ) + ); + } +} diff --git a/tests/Utilities/Plugin_Request_Utility_Tests.php b/tests/Utilities/Plugin_Request_Utility_Tests.php new file mode 100644 index 000000000..ce9a09aaa --- /dev/null +++ b/tests/Utilities/Plugin_Request_Utility_Tests.php @@ -0,0 +1,31 @@ +assertSame( plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ), $plugin ); + } + + public function test_get_plugin_basename_from_input_with_empty_input() { + $this->expectException( 'Exception' ); + $this->expectExceptionMessage( 'Missing positional argument. Please provide the plugin slug as first positional argument.' ); + + Plugin_Request_Utility::get_plugin_basename_from_input( '' ); + } + + public function test_get_plugin_basename_from_input_with_invalid_input() { + $this->expectException( 'Exception' ); + $this->expectExceptionMessage( 'Invalid positional argument. Plugin with slug invalid is not installed.' ); + + Plugin_Request_Utility::get_plugin_basename_from_input( 'invalid' ); + } +} From a0b32c02725a93775e41ee6d5f1c1320b90dcf6d Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Mon, 13 Feb 2023 12:23:53 +0000 Subject: [PATCH 15/17] update checks --- includes/Checker/Abstract_Check_Runner.php | 2 +- includes/Checker/CLI_Runner.php | 35 ++++++++++---------- includes/Checker/Checks.php | 38 ++++++++++++++-------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index be8f383ed..3affd17b6 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -156,7 +156,7 @@ protected function get_checks_to_run() { $check_slugs = $this->get_check_slugs_to_run(); $all_checks = $this->get_checks_instance()->get_checks(); - if ( empty( $checks ) ) { + if ( empty( $check_slugs ) ) { return $all_checks; } diff --git a/includes/Checker/CLI_Runner.php b/includes/Checker/CLI_Runner.php index fcbb412ef..d240ebf2c 100644 --- a/includes/Checker/CLI_Runner.php +++ b/includes/Checker/CLI_Runner.php @@ -16,6 +16,14 @@ */ class CLI_Runner extends Abstract_Check_Runner { + /** + * An instances of the Checks class. + * + * @since n.e.x.t + * @var Checks + */ + protected $checks; + /** * Checks if the current request is a CLI request for the Plugin Checker. * @@ -39,23 +47,6 @@ public function is_plugin_check() { return false; } - /** - * Returns the plugin main file based on the request. - * - * @since n.e.x.t - * - * @return string The absolute path to the plugin main file. - * - * @throws Exception Thrown if an invalid basename or plugin slug is provided. - */ - private function get_plugin_main_file() { - // Get the plugin name from the command line arguments. - $plugin_slug = isset( $_SERVER['argv'][3] ) ? $_SERVER['argv'][3] : ''; - $plugin_file = Plugin_Request_Utility::get_plugin_basename_from_input( $plugin_slug ); - - return WP_PLUGIN_DIR . '/' . $plugin_file; - } - /** * Retruns an instance of the Checks class. * @@ -66,7 +57,15 @@ private function get_plugin_main_file() { * @throws Exception Thrown if the plugin main file cannot be found based on the CLI input. */ protected function get_checks_instance() { - return new Checks( $this->get_plugin_main_file() ); + if ( ! isset( $this->checks ) ) { + // Get the plugin name from the command line arguments. + $plugin_slug = isset( $_SERVER['argv'][3] ) ? $_SERVER['argv'][3] : ''; + $plugin_file = Plugin_Request_Utility::get_plugin_basename_from_input( $plugin_slug ); + + $this->checks = new Checks( WP_PLUGIN_DIR . '/' . $plugin_file ); + } + + return $this->checks; } /** diff --git a/includes/Checker/Checks.php b/includes/Checker/Checks.php index 34b5de55c..789a797b4 100644 --- a/includes/Checker/Checks.php +++ b/includes/Checker/Checks.php @@ -17,6 +17,14 @@ */ class Checks { + /** + * Array of all available Checks. + * + * @since n.e.x.t + * @var array + */ + protected $checks; + /** * Context for the plugin to check. * @@ -65,7 +73,7 @@ public function run_checks( array $checks ) { $checks_to_run = array_filter( $checks, function( $check ) use ( $all_checks ) { - return in_array( $check, $all_checks ); // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict + return in_array( $check, $all_checks, true ); } ); @@ -119,18 +127,22 @@ protected function run_check_with_result( Check $check, Check_Result $result ) { * @return array An array map of check slugs to Check instances. */ public function get_checks() { - // TODO: Add checks once implemented. - $checks = array( - 'i18n-usage' => new Checks\I18n_Usage_Check(), - ); + if ( ! isset( $this->checks ) ) { + // TODO: Add checks once implemented. + $checks = array( + 'i18n-usage' => new Checks\I18n_Usage_Check(), + ); + + /** + * Filters the available plugin check classes. + * + * @since n.e.x.t + * + * @param array $checks An array map of check slugs to Check instances. + */ + $this->checks = apply_filters( 'wp_plugin_check_checks', $checks ); + } - /** - * Filters the available plugin check classes. - * - * @since n.e.x.t - * - * @param array $checks An array map of check slugs to Check instances. - */ - return apply_filters( 'wp_plugin_check_checks', $checks ); + return $this->checks; } } From ee2685060debadadd6fd7d37d987403a2fd39f00 Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Tue, 14 Feb 2023 11:08:51 +0000 Subject: [PATCH 16/17] update comments and exception messages --- includes/Checker/Abstract_Check_Runner.php | 9 ++------- includes/Checker/Checks.php | 4 ++-- includes/Utilities/Plugin_Request_Utility.php | 6 +++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 3affd17b6..d3d44c6ce 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -113,12 +113,7 @@ protected function requires_universal_preparations( array $checks ) { * @since n.e.x.t * * @param array $checks An array of Check instances to run. - * @return array { - * An array of Preparations to run where each item is an array with the class name and args. - * - * @type string $class The full class name of the Preparation. - * @type array $args An array of parameters to pass to the class constructor. - * } + * @return array An array of Preparations to run where each item is an array with keys `class` and `args`. */ private function get_shared_preparations( array $checks ) { $shared_preparations = array(); @@ -150,7 +145,7 @@ private function get_shared_preparations( array $checks ) { * * @since n.e.x.t * - * @return array An array of Check instances. + * @return array An array map of check slugs to Check instances. */ protected function get_checks_to_run() { $check_slugs = $this->get_check_slugs_to_run(); diff --git a/includes/Checker/Checks.php b/includes/Checker/Checks.php index 789a797b4..75f112bb4 100644 --- a/includes/Checker/Checks.php +++ b/includes/Checker/Checks.php @@ -49,7 +49,7 @@ public function __construct( $plugin_main_file ) { * * @since n.e.x.t * - * @return Check_Context + * @return Check_Context The plugin context that is being checked. */ public function context() { return $this->check_context; @@ -130,7 +130,7 @@ public function get_checks() { if ( ! isset( $this->checks ) ) { // TODO: Add checks once implemented. $checks = array( - 'i18n-usage' => new Checks\I18n_Usage_Check(), + 'i18n_usage' => new Checks\I18n_Usage_Check(), ); /** diff --git a/includes/Utilities/Plugin_Request_Utility.php b/includes/Utilities/Plugin_Request_Utility.php index bcb481256..e06162ba4 100644 --- a/includes/Utilities/Plugin_Request_Utility.php +++ b/includes/Utilities/Plugin_Request_Utility.php @@ -28,7 +28,7 @@ public static function get_plugin_basename_from_input( $plugin_slug ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; if ( empty( $plugin_slug ) ) { - throw new Exception( 'Missing positional argument. Please provide the plugin slug as first positional argument.' ); + throw new Exception( 'Invalid plugin slug: Plugin slug must not be empty.' ); } $plugins = get_plugins(); @@ -41,7 +41,7 @@ public static function get_plugin_basename_from_input( $plugin_slug ) { if ( strpos( $plugin_slug, '/' ) ) { throw new Exception( sprintf( - 'Invalid positional argument. Plugin with basename %s is not installed.', + 'Invalid plugin basename: Plugin with basename %s is not installed.', $plugin_slug ) ); @@ -55,7 +55,7 @@ public static function get_plugin_basename_from_input( $plugin_slug ) { throw new Exception( sprintf( - 'Invalid positional argument. Plugin with slug %s is not installed.', + 'Invalid plugin slug: Plugin with slug %s is not installed.', $plugin_slug ) ); From 011c8a41dd35fd0d540ed00c44b6dff85a889653 Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Tue, 14 Feb 2023 11:13:37 +0000 Subject: [PATCH 17/17] update tests --- tests/Utilities/Plugin_Request_Utility_Tests.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Utilities/Plugin_Request_Utility_Tests.php b/tests/Utilities/Plugin_Request_Utility_Tests.php index ce9a09aaa..47b677f57 100644 --- a/tests/Utilities/Plugin_Request_Utility_Tests.php +++ b/tests/Utilities/Plugin_Request_Utility_Tests.php @@ -17,14 +17,14 @@ public function test_get_plugin_basename_from_input() { public function test_get_plugin_basename_from_input_with_empty_input() { $this->expectException( 'Exception' ); - $this->expectExceptionMessage( 'Missing positional argument. Please provide the plugin slug as first positional argument.' ); + $this->expectExceptionMessage( 'Invalid plugin slug: Plugin slug must not be empty.' ); Plugin_Request_Utility::get_plugin_basename_from_input( '' ); } public function test_get_plugin_basename_from_input_with_invalid_input() { $this->expectException( 'Exception' ); - $this->expectExceptionMessage( 'Invalid positional argument. Plugin with slug invalid is not installed.' ); + $this->expectExceptionMessage( 'Invalid plugin slug: Plugin with slug invalid is not installed.' ); Plugin_Request_Utility::get_plugin_basename_from_input( 'invalid' ); }