-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix errors/warnings flagged by PHPCS (#143)
* Fix: phpcs errors 1. Blank line after function. 2. Ignore WordPress.NamingConventions.ValidHookName.UseUnderscores because of backward compatibility * Fix: phpcs error for equal sign alignment * Fix: phpcs errors 1. Spacing and equal line alignement issue. 2. Ignore object param and return type because assuming php greater than 7.1 also requrires php 7.4 as plugin description. 3. Change CamelCase to snake_case variables. * Fix: phpcs error for file /tests/bootstrap.php for spacing issue * Fix: phpcs errors 1. Spacing and alignment issue. 2. Naming convention 3. Multiline array comma issue * Fix issue added by bot for undefined variable * Exclude hook name validation rule instead ignoring * Update unit tests workflow * Add slah before wp_json_encode function * Revert json encode change
- Loading branch information
Showing
19 changed files
with
495 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,14 @@ | |
* | ||
* @author Guido Scialfa <[email protected]> | ||
*/ | ||
class TestCase extends WPMockTestCase | ||
{ | ||
class TestCase extends WPMockTestCase { | ||
|
||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
public function setUp(): void | ||
{ | ||
public function setUp(): void { | ||
|
||
parent::setUp(); | ||
\WP_Mock::setUp(); | ||
} | ||
|
@@ -35,8 +35,8 @@ public function setUp(): void | |
* Tears down the fixture, for example, close a network connection. | ||
* This method is called after a test is executed. | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
public function tearDown(): void { | ||
|
||
parent::tearDown(); | ||
\WP_Mock::tearDown(); | ||
} | ||
|
@@ -46,27 +46,28 @@ public function tearDown(): void | |
* | ||
* Basic configuration available for all of the testee objects, call `getMock` to get the mock. | ||
* | ||
* @param string $className | ||
* @param array $constructorArguments | ||
* @param array $methods | ||
* @param string $sutMethod | ||
* @param string $class_name | ||
* @param array $constructor_arguments | ||
* @param array $methods | ||
* @param string $sut_method | ||
* | ||
* @return PHPUnit_Framework_MockObject_MockBuilder | ||
*/ | ||
protected function buildTesteeMock( | ||
string $className, | ||
array $constructorArguments, | ||
string $class_name, | ||
array $constructor_arguments, | ||
array $methods, | ||
string $sutMethod | ||
): object { | ||
string $sut_method | ||
): object { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.objectFound -- Ignoring because assuming php application version greater than 7.1. | ||
|
||
$testee = $this->getMockBuilder( $class_name ); | ||
|
||
$testee = $this->getMockBuilder($className); | ||
$constructorArguments | ||
? $testee->setConstructorArgs($constructorArguments) | ||
$constructor_arguments | ||
? $testee->setConstructorArgs( $constructor_arguments ) | ||
: $testee->disableOriginalConstructor(); | ||
|
||
$methods and $testee->setMethods($methods); | ||
$sutMethod and $testee->setMethodsExcept([$sutMethod]); | ||
$methods && $testee->setMethods( $methods ); | ||
$sut_method && $testee->setMethodsExcept( [ $sut_method ] ); | ||
|
||
return $testee; | ||
} | ||
|
@@ -75,31 +76,36 @@ protected function buildTesteeMock( | |
* Retrieve a Testee Mock to Test Protected Methods | ||
* | ||
* return MockBuilder | ||
* @param string $className | ||
* @param array $constructorArguments | ||
* | ||
* @param string $class_name | ||
* @param array $constructor_arguments | ||
* @param string $method | ||
* @param array $methods | ||
* @param array $methods | ||
* | ||
* @return array | ||
* | ||
* @throws ReflectionException | ||
*/ | ||
protected function buildTesteeMethodMock( | ||
string $className, | ||
array $constructorArguments, | ||
string $class_name, | ||
array $constructor_arguments, | ||
string $method, | ||
array $methods | ||
): array { | ||
|
||
$testee = $this->buildTesteeMock( | ||
$className, | ||
$constructorArguments, | ||
$class_name, | ||
$constructor_arguments, | ||
$methods, | ||
'' | ||
)->getMock(); | ||
$reflectionMethod = new ReflectionMethod($className, $method); | ||
$reflectionMethod->setAccessible(true); | ||
|
||
$reflection_method = new ReflectionMethod( $class_name, $method ); | ||
$reflection_method->setAccessible( true ); | ||
|
||
return [ | ||
$testee, | ||
$reflectionMethod, | ||
$reflection_method, | ||
]; | ||
} | ||
|
||
|
@@ -112,13 +118,14 @@ protected function buildTesteeMethodMock( | |
//phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration.NoReturnType | ||
protected function getTesteeProperty( | ||
string $property, | ||
object $object | ||
object $object // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewParamTypeDeclarations.objectFound -- Ignoring because assuming php application version greater than 7.1. | ||
) { | ||
|
||
$reflection = new \ReflectionClass($object); | ||
$reflectionProperty = $reflection->getProperty($property); | ||
$reflectionProperty->setAccessible(true); | ||
return $reflectionProperty->getValue($object); | ||
$reflection = new \ReflectionClass( $object ); | ||
$reflection_property = $reflection->getProperty( $property ); | ||
|
||
$reflection_property->setAccessible( true ); | ||
return $reflection_property->getValue( $object ); | ||
} | ||
|
||
/** | ||
|
@@ -131,12 +138,17 @@ protected function getTesteeProperty( | |
* @throws ReflectionException | ||
*/ | ||
// phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType | ||
protected function setTesteeProperty(object $object, string $property, $value): void | ||
{ | ||
$reflection = new \ReflectionClass($object); | ||
$reflectionProperty = $reflection->getProperty($property); | ||
$reflectionProperty->setAccessible(true); | ||
$reflectionProperty->setValue($object, $value); | ||
protected function setTesteeProperty( | ||
object $object, // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewParamTypeDeclarations.objectFound -- Ignoring because assuming php application version greater than 7.1. | ||
string $property, | ||
$value | ||
): void { | ||
|
||
$reflection = new \ReflectionClass( $object ); | ||
$reflection_property = $reflection->getProperty( $property ); | ||
|
||
$reflection_property->setAccessible( true ); | ||
$reflection_property->setValue( $object, $value ); | ||
} | ||
|
||
/** | ||
|
@@ -146,30 +158,32 @@ protected function setTesteeProperty(object $object, string $property, $value): | |
* @param string $function_name | ||
* @param mixed $args | ||
* @param int $times | ||
* | ||
* @param mixed $return | ||
*/ | ||
protected function wpMockFunction( | ||
string $functionName, | ||
string $function_name, | ||
$args = [], | ||
int $times = 1, | ||
$return = null | ||
) { | ||
|
||
$funcArgs = [ | ||
$func_args = [ | ||
'times' => $times, | ||
]; | ||
|
||
if (!empty($args)) { | ||
$funcArgs['args'] = $args; | ||
if ( ! empty( $args ) ) { | ||
$func_args['args'] = $args; | ||
} | ||
|
||
if (!empty($return)) { | ||
$funcArgs['return'] = $return; | ||
if ( ! empty( $return ) ) { | ||
$func_args['return'] = $return; | ||
} | ||
|
||
\WP_Mock::userFunction( | ||
$functionName, | ||
$funcArgs | ||
$function_name, | ||
$func_args | ||
); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.