diff --git a/WordPress/Tests/Helpers/WPHookHelper/GetHookNameParamUnitTest.php b/WordPress/Tests/Helpers/WPHookHelper/GetHookNameParamUnitTest.php new file mode 100644 index 0000000000..335fad88d4 --- /dev/null +++ b/WordPress/Tests/Helpers/WPHookHelper/GetHookNameParamUnitTest.php @@ -0,0 +1,86 @@ + $parameters The parameters array to pass to the method. + * @param array|false $expectedResult The expected return value. + * + * @return void + */ + public function testGetHookNameParam( $functionName, $parameters, $expectedResult ) { + $this->assertSame( + $expectedResult, + WPHookHelper::get_hook_name_param( $functionName, $parameters ) + ); + } + + /** + * Data provider. + * + * @see testGetHookNameParam() + * + * @return array|false|string>> + */ + public static function dataGetHookNameParam() { + // Note: The parameter arrays use a simplified format instead of the real PassedParameters::getParameters() + // output as most of the array entries are not relevant for the method under test. + return array( + 'not_a_hook_function' => array( + 'functionName' => 'printf', + 'parameters' => array( 1 => array( 'my_action' ) ), + 'expectedResult' => false, + ), + 'hook_name_param_missing' => array( + 'functionName' => 'apply_filters_ref_array', + 'parameters' => array( 2 => array( '$arg' ) ), + 'expectedResult' => false, + ), + 'lowercase_name' => array( + 'functionName' => 'do_action', + 'parameters' => array( 1 => array( 'my_action' ) ), + 'expectedResult' => array( 'my_action' ), + ), + 'mixedcase_name' => array( + 'functionName' => 'aPpLy_FiLtErS', + 'parameters' => array( + 1 => array( 'my_filter' ), + 2 => array( '$value' ), + ), + 'expectedResult' => array( 'my_filter' ), + ), + 'named_parameter' => array( + 'functionName' => 'do_action_deprecated', + 'parameters' => array( + 'args' => array( '$args' ), + 'hook_name' => array( 'my_action' ), + ), + 'expectedResult' => array( 'my_action' ), + ), + ); + } +} diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php index 98649fb620..763760f1c3 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php @@ -17,7 +17,7 @@ * @since 0.10.0 * @since 0.13.0 Class name changed: this class is now namespaced. * - * @covers \WordPressCS\WordPress\Helpers\WPHookHelper + * @covers \WordPressCS\WordPress\Helpers\WPHookHelper::get_functions * @covers \WordPressCS\WordPress\Sniffs\NamingConventions\ValidHookNameSniff */ final class ValidHookNameUnitTest extends AbstractSniffUnitTest {