-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: PHPCS Errors for PHP files #143
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f74f767
Fix: phpcs errors
hbhalodia 76e3577
Fix: phpcs error for equal sign alignment
hbhalodia 1591080
Fix: phpcs errors
hbhalodia 50cf896
Fix: phpcs error for file /tests/bootstrap.php for spacing issue
hbhalodia 0f261fd
Fix: phpcs errors
hbhalodia 33480bd
Fix issue added by bot for undefined variable
hbhalodia dbed605
Exclude hook name validation rule instead ignoring
hbhalodia 27458de
Update unit tests workflow
hbhalodia 8e619a9
Add slah before wp_json_encode function
hbhalodia 8a4b3e8
Revert json encode change
hbhalodia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||
); | ||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about disabling this rule in phpcs config?
<rule ref="WordPress-Core"> <exclude name="Generic.Arrays.DisallowShortArraySyntax" /> <exclude name="Generic.Commenting.DocComment.MissingShort" /> <exclude name="WordPress.PHP.DisallowShortTernary" /> + <exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" /> </rule>
Probably include a todo comment as well?
<!-- @todo: Remove this once we rename the hooks with underscores and deprecate the old ones. -->
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, We can do exclude it from there with a todo for future, works well. 👍