diff --git a/.github/workflows/phpunit_on_pull_request.yml b/.github/workflows/phpunit_on_pull_request.yml
index fcca5610..e2670d3a 100644
--- a/.github/workflows/phpunit_on_pull_request.yml
+++ b/.github/workflows/phpunit_on_pull_request.yml
@@ -48,9 +48,13 @@ jobs:
if: steps.check_files.outputs.files_exists == 'true'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
+ - name: Update composer packages
+ if: steps.check_files.outputs.files_exists == 'true'
+ run: composer update
+
- name: Run PHPUnit
if: steps.check_files.outputs.files_exists == 'true'
- run: composer update && composer tests:unit
+ run: vendor/bin/phpunit tests/php/Unit/ --verbose
- name: Archive code coverage results
uses: actions/upload-artifact@v2
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 4ee495a9..2379080a 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -5,6 +5,11 @@
+
+
diff --git a/src/Interfaces/Container.php b/src/Interfaces/Container.php
index b83e9613..a5ff90ce 100644
--- a/src/Interfaces/Container.php
+++ b/src/Interfaces/Container.php
@@ -16,6 +16,7 @@
* @package WpGuruDev\OrderExport\Interfaces
*/
interface Container {
+
/**
* Define services in container.
*
diff --git a/src/Modules/Shortcode.php b/src/Modules/Shortcode.php
index 0d9c87a5..05f86bfc 100644
--- a/src/Modules/Shortcode.php
+++ b/src/Modules/Shortcode.php
@@ -134,7 +134,6 @@ public function scan_shortcode( string $output, string $tag, $attrs ): string {
return $output;
}
-
/**
* Filter redirect URL as per shortcode param.
*
diff --git a/src/Utils/GoogleClient.php b/src/Utils/GoogleClient.php
index ea78f887..b162f00e 100644
--- a/src/Utils/GoogleClient.php
+++ b/src/Utils/GoogleClient.php
@@ -244,11 +244,14 @@ public function user(): \stdClass {
* @return string
*/
public function state(): string {
- $state_data['nonce'] = wp_create_nonce( 'login_with_google' );
+
+ $state_data = [
+ 'nonce' => wp_create_nonce( 'login_with_google' ),
+ ];
+
$state_data = apply_filters( 'rtcamp.google_login_state', $state_data );
$state_data['provider'] = 'google';
return base64_encode( wp_json_encode( $state_data ) );
}
-
}
diff --git a/templates/google-login-button.php b/templates/google-login-button.php
index c010785f..93290387 100644
--- a/templates/google-login-button.php
+++ b/templates/google-login-button.php
@@ -20,7 +20,7 @@
if ( is_user_logged_in() ) {
$button_text = __( 'Log out', 'login-with-google' );
- $button_url = wp_logout_url( get_permalink() );
+ $button_url = wp_logout_url( get_permalink() );
}
?>
diff --git a/tests/php/TestCase.php b/tests/php/TestCase.php
index 94c6e820..fb03ffff 100644
--- a/tests/php/TestCase.php
+++ b/tests/php/TestCase.php
@@ -19,14 +19,14 @@
*
* @author Guido Scialfa
*/
-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
);
+
}
}
diff --git a/tests/php/Unit/ContainerTest.php b/tests/php/Unit/ContainerTest.php
index be42f480..86aaf586 100644
--- a/tests/php/Unit/ContainerTest.php
+++ b/tests/php/Unit/ContainerTest.php
@@ -27,7 +27,7 @@ class ContainerTest extends TestCase {
/**
* @var PimpleContainer
*/
- private $pimpleMock;
+ private $pimple_mock;
/**
* Object under test.
@@ -40,11 +40,14 @@ class ContainerTest extends TestCase {
* @return void
*/
public function setUp(): void {
- $this->pimpleMock = $this->createMock( PimpleContainer::class );
- $this->testee = new Testee( $this->pimpleMock );
+
+ $this->pimple_mock = $this->createMock( PimpleContainer::class );
+ $this->testee = new Testee( $this->pimple_mock );
+
}
public function testContainerImplementsInterface() {
+
$this->assertInstanceOf( ContainerInterface::class, $this->testee );
}
@@ -52,11 +55,13 @@ public function testContainerImplementsInterface() {
* @covers ::get
*/
public function testGetThrowsExceptionForNonExistentService() {
- $this->pimpleMock->expects( $this->once() )
- ->method( 'keys' )
- ->willReturn( [ 'example_service' ] );
+
+ $this->pimple_mock->expects( $this->once() )
+ ->method( 'keys' )
+ ->willReturn( [ 'example_service' ] );
$this->expectException( InvalidArgumentException::class );
+
$this->testee->get( 'non_existent_service' );
}
@@ -64,21 +69,22 @@ public function testGetThrowsExceptionForNonExistentService() {
* @covers ::get
*/
public function testGetReturnsServiceObject() {
- $dummyService = (object) [
+
+ $dummy_service = (object) [
'some_key' => 'some_value',
'some_other_key' => 'some_other_value',
];
- $this->testee->container['test_service'] = $dummyService;
+ $this->testee->container['test_service'] = $dummy_service;
- $this->pimpleMock->expects( $this->once() )
- ->method( 'keys' )
- ->willReturn( [ 'test_service' ] );
+ $this->pimple_mock->expects( $this->once() )
+ ->method( 'keys' )
+ ->willReturn( [ 'test_service' ] );
- $this->pimpleMock->expects( $this->once() )
- ->method( 'offsetGet' )
- ->with( 'test_service' )
- ->willReturn( $dummyService );
+ $this->pimple_mock->expects( $this->once() )
+ ->method( 'offsetGet' )
+ ->with( 'test_service' )
+ ->willReturn( $dummy_service );
$this->testee->get( 'test_service' );
}
diff --git a/tests/php/Unit/Modules/AssetsTest.php b/tests/php/Unit/Modules/AssetsTest.php
index 4342eaca..008db153 100644
--- a/tests/php/Unit/Modules/AssetsTest.php
+++ b/tests/php/Unit/Modules/AssetsTest.php
@@ -45,7 +45,7 @@ public function testInit() {
'login_enqueue_scripts',
[
$this->testee,
- 'enqueue_login_styles'
+ 'enqueue_login_styles',
]
);
@@ -111,7 +111,7 @@ function () {
'login-with-google',
'https://example.com/assets/js/login.js',
[
- 'some-other-script'
+ 'some-other-script',
],
false,
true,
@@ -124,7 +124,7 @@ function () {
'login-with-google',
'js/login.js',
[
- 'some-other-script'
+ 'some-other-script',
]
);
diff --git a/tests/php/Unit/Modules/BlockTest.php b/tests/php/Unit/Modules/BlockTest.php
index e5edc9e8..096f8c6e 100644
--- a/tests/php/Unit/Modules/BlockTest.php
+++ b/tests/php/Unit/Modules/BlockTest.php
@@ -27,12 +27,12 @@ class BlockTest extends TestCase {
/**
* @var GoogleClient
*/
- private $ghClientMock;
+ private $gh_client_mock;
/**
* @var Assets
*/
- private $assetMock;
+ private $assert_mock;
/**
* @var Testee
@@ -45,15 +45,15 @@ class BlockTest extends TestCase {
* @return void
*/
public function setUp(): void {
- $this->ghClientMock = $this->createMock( GoogleClient::class );
- $this->assetMock = $this->createMock( Assets::class );
- $this->testee = new Testee( $this->assetMock, $this->ghClientMock );
+ $this->gh_client_mock = $this->createMock( GoogleClient::class );
+ $this->assert_mock = $this->createMock( Assets::class );
+ $this->testee = new Testee( $this->assert_mock, $this->gh_client_mock );
}
public function tearDown(): void {
parent::tearDown();
- $this->ghClientMock = null;
- $this->assetMock = null;
+ $this->gh_client_mock = null;
+ $this->assert_mock = null;
unset( $this->testee );
}
@@ -114,20 +114,20 @@ function () use ( $path ) {
true
);
- $this->assetMock->expects( $this->once() )->method( 'register_login_styles' );
- $this->assetMock->expects( $this->once() )->method( 'register_script' )
- ->with(
- 'google-login-block',
- 'build/js/block-button.js',
- [
- 'wp-blocks',
- 'wp-element',
- 'wp-editor',
- 'wp-components',
- ],
- filemtime( $path . 'build/js/block-button.js' ),
- false
- );
+ $this->assert_mock->expects( $this->once() )->method( 'register_login_styles' );
+ $this->assert_mock->expects( $this->once() )->method( 'register_script' )
+ ->with(
+ 'google-login-block',
+ 'build/js/block-button.js',
+ [
+ 'wp-blocks',
+ 'wp-element',
+ 'wp-editor',
+ 'wp-components',
+ ],
+ filemtime( $path . 'build/js/block-button.js' ),
+ false
+ );
$this->testee->enqueue_block_editor_assets();
}
@@ -164,12 +164,12 @@ public function testRegister() {
$this->assertConditionsMet();
}
-
/**
* @covers ::render_login_button, ::markup
*/
public function testRenderLoginButton() {
- $mockAttributes = [
+
+ $mock_attributes = [
'login_url' => '#',
'custom_btn_text' => 'test',
'force_display' => false,
@@ -186,7 +186,7 @@ public function testRenderLoginButton() {
'wp_parse_args',
[],
1,
- $mockAttributes
+ $mock_attributes
);
$this->wpMockFunction(
@@ -219,11 +219,11 @@ function () use ( $path ) {
);
- $helperMock = \Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'render_template' )->once()->withArgs(
+ $helper_mock = \Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'render_template' )->once()->withArgs(
[
$path . 'google-login-button.php',
- $mockAttributes,
+ $mock_attributes,
false,
]
)->andReturn( '' );
@@ -231,7 +231,7 @@ function () use ( $path ) {
$markup = $this->testee->render_login_button(
[
$path . '/google-login-button.php',
- $mockAttributes,
+ $mock_attributes,
false,
]
);
@@ -243,7 +243,8 @@ function () use ( $path ) {
* @covers ::render_login_button, ::markup
*/
public function testRenderLogoutButton() {
- $mockAttributes = [
+
+ $mock_attributes = [
'login_url' => '#',
'custom_btn_text' => 'test',
'force_display' => true,
@@ -260,7 +261,7 @@ public function testRenderLogoutButton() {
'wp_parse_args',
[],
1,
- $mockAttributes
+ $mock_attributes
);
$this->wpMockFunction(
@@ -293,11 +294,11 @@ function () use ( $path ) {
);
- $helperMock = \Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'render_template' )->once()->withArgs(
+ $helper_mock = \Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'render_template' )->once()->withArgs(
[
$path . 'google-login-button.php',
- $mockAttributes,
+ $mock_attributes,
false,
]
)->andReturn( '' );
@@ -305,7 +306,7 @@ function () use ( $path ) {
$markup = $this->testee->render_login_button(
[
$path . '/google-login-button.php',
- $mockAttributes,
+ $mock_attributes,
false,
]
);
diff --git a/tests/php/Unit/Modules/LoginTest.php b/tests/php/Unit/Modules/LoginTest.php
index 94c5b958..372f43f0 100644
--- a/tests/php/Unit/Modules/LoginTest.php
+++ b/tests/php/Unit/Modules/LoginTest.php
@@ -31,12 +31,12 @@ class LoginTest extends TestCase {
/**
* @var GoogleClient
*/
- private $ghClientMock;
+ private $gh_client_mock;
/**
* @var Settings
*/
- private $authenticatorMock;
+ private $authenticator_mock;
/**
* @var Testee
@@ -49,16 +49,18 @@ class LoginTest extends TestCase {
* @return void
*/
public function setUp(): void {
- $this->ghClientMock = $this->createMock( GoogleClient::class );
- $this->authenticatorMock = $this->createMock( Authenticator::class );
- $this->testee = new Testee( $this->ghClientMock, $this->authenticatorMock );
+ $this->gh_client_mock = $this->createMock( GoogleClient::class );
+ $this->authenticator_mock = $this->createMock( Authenticator::class );
+
+ $this->testee = new Testee( $this->gh_client_mock, $this->authenticator_mock );
}
/**
* @covers ::name
*/
public function testName() {
+
$this->assertSame( 'login_flow', $this->testee->name() );
}
@@ -66,6 +68,7 @@ public function testName() {
* @covers ::__construct
*/
public function testImplementsModuleInterface() {
+
$this->assertTrue( $this->testee instanceof ModuleInterface );
}
@@ -73,9 +76,10 @@ public function testImplementsModuleInterface() {
* @covers ::init
*/
public function testInit() {
+
WP_Mock::expectActionAdded( 'login_form', [ $this->testee, 'login_button' ] );
WP_Mock::expectActionAdded( 'authenticate', [ $this->testee, 'authenticate' ], 20 );
- WP_Mock::expectActionAdded( 'rtcamp.google_register_user', [ $this->authenticatorMock, 'register' ] );
+ WP_Mock::expectActionAdded( 'rtcamp.google_register_user', [ $this->authenticator_mock, 'register' ] );
WP_Mock::expectActionAdded( 'rtcamp.google_redirect_url', [ $this->testee, 'redirect_url' ] );
WP_Mock::expectActionAdded( 'rtcamp.google_user_created', [ $this->testee, 'user_meta' ] );
WP_Mock::expectFilterAdded( 'rtcamp.google_login_state', [ $this->testee, 'state_redirect' ] );
@@ -89,27 +93,28 @@ public function testInit() {
* @covers ::login_button
*/
public function testLoginButton() {
- $pluginMock = $this->createMock( Plugin::class );
- $pluginMock->template_dir = 'https://example.com/templates/';
- $containerMock = $this->createMock( Container::class );
- $containerMock->expects( $this->once() )
- ->method( 'get' )
- ->willReturn( $this->ghClientMock );
+ $plugin_mock = $this->createMock( Plugin::class );
+ $plugin_mock->template_dir = 'https://example.com/templates/';
+
+ $container_mock = $this->createMock( Container::class );
+ $container_mock->expects( $this->once() )
+ ->method( 'get' )
+ ->willReturn( $this->gh_client_mock );
- $pluginMock->expects( $this->once() )
- ->method( 'container' )
- ->willReturn( $containerMock );
+ $plugin_mock->expects( $this->once() )
+ ->method( 'container' )
+ ->willReturn( $container_mock );
- $this->ghClientMock->expects( $this->once() )
- ->method( 'authorization_url' )
- ->willReturn( 'https://google.com/auth/' );
+ $this->gh_client_mock->expects( $this->once() )
+ ->method( 'authorization_url' )
+ ->willReturn( 'https://google.com/auth/' );
$this->wpMockFunction(
'RtCamp\GoogleLogin\plugin',
[],
2,
- $pluginMock
+ $plugin_mock
);
WP_Mock::userFunction(
@@ -117,19 +122,19 @@ public function testLoginButton() {
[
'times' => 1,
'args' => [
- 'https://example.com/templates/'
+ 'https://example.com/templates/',
],
- 'return_arg' => 0
+ 'return_arg' => 0,
]
);
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'render_template' )->once()->withArgs(
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'render_template' )->once()->withArgs(
[
'https://example.com/templates/google-login-button.php',
[
'login_url' => 'https://google.com/auth/',
- ]
+ ],
]
);
@@ -141,12 +146,13 @@ public function testLoginButton() {
* @covers ::authenticate
*/
public function testAuthenticationForNoCode() {
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'code',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( null );
@@ -154,7 +160,7 @@ public function testAuthenticationForNoCode() {
$wp_user_mock->login = 'test';
$wp_user_mock->email = 'test@unit.com';
- $returned = $this->testee->authenticate( $wp_user_mock );
+ $returned = $this->testee->authenticate( $wp_user_mock );
$this->assertSame( $returned, $wp_user_mock );
}
@@ -163,12 +169,13 @@ public function testAuthenticationForNoCode() {
* @covers ::authenticate
*/
public function testAuthenticationForAlreadyAuthenticatedUser() {
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'filter_input' )->never()->withArgs(
+
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'filter_input' )->never()->withArgs(
[
INPUT_GET,
'code',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( null );
@@ -182,27 +189,28 @@ public function testAuthenticationForAlreadyAuthenticatedUser() {
* @covers ::authenticate
*/
public function testAuthenticationForDifferentProvider() {
+
$state = [
'nonce' => '1234',
'provider' => 'some_other',
];
- $state = base64_encode( json_encode( $state ) );
+ $state = base64_encode( wp_json_encode( $state ) );
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'code',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( 'test_code' );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'state',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( $state );
@@ -210,7 +218,7 @@ public function testAuthenticationForDifferentProvider() {
$wp_user_mock->login = 'test';
$wp_user_mock->email = 'test@unit.com';
- $returned = $this->testee->authenticate( $wp_user_mock );
+ $returned = $this->testee->authenticate( $wp_user_mock );
$this->assertSame( $returned, $wp_user_mock );
}
@@ -219,20 +227,21 @@ public function testAuthenticationForDifferentProvider() {
* @covers ::authenticate
*/
public function testAuthenticationWithForgedState() {
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'code',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( 'abc' );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'state',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( 'eyJwcm92aWRlciI6ImdpdGh1YiJ9' );
@@ -246,26 +255,27 @@ public function testAuthenticationWithForgedState() {
* @covers ::authenticate
*/
public function testAuthenticationWhenUserExists() {
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'code',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( 'abc' );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'state',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( 'eyJwcm92aWRlciI6Imdvb2dsZSIsIm5vbmNlIjoidGVzdG5vbmNlIn0=' );
- $this->ghClientMock->expects( $this->never() )
- ->method( 'state' )
- ->willReturn( 'eyJwcm92aWRlciI6Imdvb2dsZSIsIm5vbmNlIjoidGVzdG5vbmNlIn0=' );
+ $this->gh_client_mock->expects( $this->never() )
+ ->method( 'state' )
+ ->willReturn( 'eyJwcm92aWRlciI6Imdvb2dsZSIsIm5vbmNlIjoidGVzdG5vbmNlIn0=' );
$this->wpMockFunction(
'wp_verify_nonce',
@@ -277,26 +287,26 @@ public function testAuthenticationWhenUserExists() {
true
);
- $this->ghClientMock->expects( $this->once() )
- ->method( 'set_access_token' )
- ->with( 'abc' );
+ $this->gh_client_mock->expects( $this->once() )
+ ->method( 'set_access_token' )
+ ->with( 'abc' );
$user = (object) [
'email' => 'fakeemail@domain.com',
];
- $this->ghClientMock->expects( $this->once() )
- ->method( 'user' )
- ->willReturn( $user );
+ $this->gh_client_mock->expects( $this->once() )
+ ->method( 'user' )
+ ->willReturn( $user );
- $userMock = Mockery::mock( 'WP_User' );
- $this->authenticatorMock->expects( $this->once() )
- ->method( 'authenticate' )
- ->willReturn( $userMock );
+ $user_mock = Mockery::mock( 'WP_User' );
+ $this->authenticator_mock->expects( $this->once() )
+ ->method( 'authenticate' )
+ ->willReturn( $user_mock );
$returned = $this->testee->authenticate();
- $this->assertSame( $returned, $userMock );
+ $this->assertSame( $returned, $user_mock );
$this->assertConditionsMet();
}
@@ -305,26 +315,27 @@ public function testAuthenticationWhenUserExists() {
* @covers ::authenticate
*/
public function testAuthenticationCapturesExceptions() {
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'code',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( 'abc' );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'state',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( 'eyJwcm92aWRlciI6Imdvb2dsZSIsIm5vbmNlIjoidGVzdG5vbmNlIn0=' );
- $this->ghClientMock->expects( $this->never() )
- ->method( 'state' )
- ->willReturn( 'eyJwcm92aWRlciI6Imdvb2dsZSIsIm5vbmNlIjoidGVzdG5vbmNlIn0=' );
+ $this->gh_client_mock->expects( $this->never() )
+ ->method( 'state' )
+ ->willReturn( 'eyJwcm92aWRlciI6Imdvb2dsZSIsIm5vbmNlIjoidGVzdG5vbmNlIn0=' );
$this->wpMockFunction(
'wp_verify_nonce',
@@ -336,10 +347,10 @@ public function testAuthenticationCapturesExceptions() {
true
);
- $this->ghClientMock->expects( $this->once() )
- ->method( 'set_access_token' )
- ->with( 'abc' )
- ->willThrowException( new Exception( 'Exception for test' ) );
+ $this->gh_client_mock->expects( $this->once() )
+ ->method( 'set_access_token' )
+ ->with( 'abc' )
+ ->willThrowException( new Exception( 'Exception for test' ) );
Mockery::mock( 'WP_Error' );
$returned = $this->testee->authenticate();
@@ -352,7 +363,8 @@ public function testAuthenticationCapturesExceptions() {
* @covers ::user_meta
*/
public function testUserMeta() {
- $user = new \stdClass();
+
+ $user = new \stdClass();
$user->login = 'login';
$this->wpMockFunction(
@@ -387,6 +399,7 @@ public function testUserMeta() {
* @covers ::redirect_url
*/
public function testRedirectURLRetuensWithQueryParam() {
+
$url = 'https://example.com/?redirect_to=https://example.com/wp-admin';
$this->wpMockFunction(
@@ -407,12 +420,13 @@ public function testRedirectURLRetuensWithQueryParam() {
* @covers ::state_redirect
*/
public function testStateRedirectWithRedirectTo() {
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'redirect_to',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( 'https://example.com/state-page' );
@@ -426,12 +440,13 @@ public function testStateRedirectWithRedirectTo() {
* @covers ::state_redirect
*/
public function testStateRedirectWithoutRedirectTo() {
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'redirect_to',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( null );
@@ -452,12 +467,13 @@ public function testStateRedirectWithoutRedirectTo() {
* @covers ::login_redirect
*/
public function testLoginRedirectWithNotStateAuthenticated() {
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'filter_input' )->once()->withArgs(
+
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'filter_input' )->once()->withArgs(
[
INPUT_GET,
'state',
- FILTER_SANITIZE_STRING
+ FILTER_SANITIZE_STRING,
]
)->andReturn( [] );
diff --git a/tests/php/Unit/Modules/SettingsTest.php b/tests/php/Unit/Modules/SettingsTest.php
index bc2616e1..d095a772 100644
--- a/tests/php/Unit/Modules/SettingsTest.php
+++ b/tests/php/Unit/Modules/SettingsTest.php
@@ -33,6 +33,7 @@ class SettingsTest extends TestCase {
* @return void
*/
public function setUp(): void {
+
$this->testee = new Testee();
}
@@ -40,10 +41,12 @@ public function setUp(): void {
* @covers ::name
*/
public function testName() {
+
$this->assertSame( 'settings', $this->testee->name() );
}
public function testImplementsModuleInterface() {
+
$this->assertTrue( $this->testee instanceof ModuleInterface );
}
@@ -51,6 +54,7 @@ public function testImplementsModuleInterface() {
* @covers ::__get
*/
public function testGetWithNull() {
+
$value = $this->testee->__get( 'some_test_property' );
$this->assertEquals( null, $value );
}
@@ -59,15 +63,16 @@ public function testGetWithNull() {
* @covers ::__get
*/
public function testGetWithProper() {
+
$this->wpMockFunction(
'get_option',
[
'wp_google_login_settings',
- []
+ [],
],
1,
[
- 'client_id' => 'cid'
+ 'client_id' => 'cid',
]
);
@@ -80,11 +85,12 @@ public function testGetWithProper() {
* @covers ::init
*/
public function testInit() {
+
$this->wpMockFunction(
'get_option',
[
'wp_google_login_settings',
- []
+ [],
],
1,
[]
@@ -101,11 +107,12 @@ public function testInit() {
* @covers ::register_settings
*/
public function testRegisterSettings() {
+
$this->wpMockFunction(
'register_setting',
[
'wp_google_login',
- 'wp_google_login_settings'
+ 'wp_google_login_settings',
],
1,
true
@@ -117,7 +124,7 @@ public function testRegisterSettings() {
'wp_google_login_section',
'Log in with Google Settings',
\Closure::class,
- 'login-with-google'
+ 'login-with-google',
],
1
);
@@ -133,7 +140,7 @@ public function testRegisterSettings() {
\WP_Mock\Functions::type( 'string' ),
\WP_Mock\Functions::type( 'array' ),
],
- 'times' => 6
+ 'times' => 6,
]
);
@@ -145,6 +152,7 @@ public function testRegisterSettings() {
* @covers ::settings_page
*/
public function testSettingsPage() {
+
$this->wpMockFunction(
'add_options_page',
[
@@ -154,7 +162,7 @@ public function testSettingsPage() {
'login-with-google',
[
$this->testee,
- 'output'
+ 'output',
],
]
);
@@ -167,6 +175,7 @@ public function testSettingsPage() {
* @covers ::output
*/
public function testOutput() {
+
$this->wpMockFunction(
'settings_fields',
[
@@ -190,7 +199,7 @@ public function testOutput() {
''
);
- $this->setOutputCallback(function() {});
+ $this->setOutputCallback( function() {} );
$this->testee->output();
$this->assertConditionsMet();
}
@@ -199,13 +208,14 @@ public function testOutput() {
* @covers ::client_id_field
*/
public function testClientIdField() {
+
$this->wpMockFunction(
'esc_html__',
[
'Create oAuth Client ID and Client Secret at',
- 'login-with-google'
+ 'login-with-google',
],
- 2,
+ 2
);
$this->wpMockFunction(
@@ -216,12 +226,12 @@ public function testClientIdField() {
esc_html__( 'Create oAuth Client ID and Client Secret at', 'login-with-google' ),
'https://console.developers.google.com/apis/dashboard',
'console.developers.google.com'
- )
+ ),
],
- 1,
+ 1
);
- $this->setOutputCallback(function() {});
+ $this->setOutputCallback( function() {} );
$this->testee->client_id_field();
$this->assertConditionsMet();
}
@@ -230,23 +240,24 @@ public function testClientIdField() {
* @covers ::user_registration
*/
public function testUserRegistration() {
+
$this->testee->registration_enabled = 'yes';
$this->wpMockFunction(
'checked',
[
- 'yes'
+ 'yes',
],
- 1,
+ 1
);
$this->wpMockFunction(
'esc_html_e',
[
'Create a new user account if it does not exist already',
- 'login-with-google'
+ 'login-with-google',
],
- 1,
+ 1
);
$this->wpMockFunction(
@@ -262,10 +273,10 @@ public function testUserRegistration() {
/* translators: %1s will be replaced by page link */
__( 'If this setting is checked, a new user will be created even if membership setting is off.', 'login-with-google' ),
],
- 1,
+ 1
);
- $this->setOutputCallback(function() {});
+ $this->setOutputCallback( function() {} );
$this->testee->user_registration();
$this->assertConditionsMet();
}
@@ -274,6 +285,7 @@ public function testUserRegistration() {
* @covers ::whitelisted_domains
*/
public function testWhitelistedDomains() {
+
$this->testee->whitelisted_domains = 'https://example1.com,https://example2.com';
$this->wpMockFunction(
@@ -281,18 +293,18 @@ public function testWhitelistedDomains() {
[
'https://example1.com,https://example2.com',
],
- 1,
+ 1
);
$this->wpMockFunction(
'esc_html',
[
- __( 'Add each domain comma separated', 'login-with-google' )
+ __( 'Add each domain comma separated', 'login-with-google' ),
],
- 1,
+ 1
);
- $this->setOutputCallback(function() {});
+ $this->setOutputCallback( function() {} );
$this->testee->whitelisted_domains();
$this->assertConditionsMet();
}
@@ -301,18 +313,18 @@ public function testWhitelistedDomains() {
* @covers ::client_secret_field
*/
public function testClientSecretField() {
+
$this->testee->client_secret = 'cis';
$this->wpMockFunction(
'esc_attr',
[
- 'cis'
+ 'cis',
],
1
);
- $this->setOutputCallback(function() {});
+ $this->setOutputCallback( function() {} );
$this->testee->client_secret_field();
$this->assertConditionsMet();
}
-
}
diff --git a/tests/php/Unit/Modules/ShortCodeTest.php b/tests/php/Unit/Modules/ShortCodeTest.php
index 0d1f270a..2e526213 100644
--- a/tests/php/Unit/Modules/ShortCodeTest.php
+++ b/tests/php/Unit/Modules/ShortCodeTest.php
@@ -27,12 +27,12 @@ class ShortCodeTest extends TestCase {
/**
* @var GoogleClient
*/
- private $ghClientMock;
+ private $gh_client_mock;
/**
* @var Assets
*/
- private $assetMock;
+ private $asset_mock;
/**
* @var Testee
@@ -45,10 +45,10 @@ class ShortCodeTest extends TestCase {
* @return void
*/
public function setUp(): void {
- $this->ghClientMock = $this->createMock( GoogleClient::class );
- $this->assetMock = $this->createMock( Assets::class );
+ $this->gh_client_mock = $this->createMock( GoogleClient::class );
+ $this->asset_mock = $this->createMock( Assets::class );
- $this->testee = new Testee( $this->ghClientMock, $this->assetMock );
+ $this->testee = new Testee( $this->gh_client_mock, $this->asset_mock );
}
/**
@@ -76,7 +76,7 @@ public function testInit() {
[
$this->testee,
'callback',
- ]
+ ],
]
);
@@ -91,6 +91,7 @@ public function testInit() {
* @covers ::should_display
*/
public function testCallbackWhenUserIsLoggedIn() {
+
$this->wpMockFunction(
'get_permalink',
[],
@@ -111,7 +112,7 @@ public function testCallbackWhenUserIsLoggedIn() {
'google_login',
],
'times' => 1,
- 'return_arg' => 0
+ 'return_arg' => 0,
]
);
@@ -132,6 +133,7 @@ public function testCallbackWhenUserIsLoggedIn() {
* @covers ::should_display
*/
public function testCallbackWhenUserIsLoggedOut() {
+
WP_Mock::userFunction(
'shortcode_atts',
[
@@ -145,7 +147,7 @@ public function testCallbackWhenUserIsLoggedOut() {
'google_login',
],
'times' => 1,
- 'return_arg' => 0
+ 'return_arg' => 0,
]
);
@@ -174,13 +176,13 @@ public function testCallbackWhenUserIsLoggedOut() {
'/some/path/templates/'
);
- $this->ghClientMock->expects( $this->once() )
- ->method( 'authorization_url' )
- ->willReturn( 'https://google.com/auth/' );
+ $this->gh_client_mock->expects( $this->once() )
+ ->method( 'authorization_url' )
+ ->willReturn( 'https://google.com/auth/' );
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'render_template' )->once()->withArgs(
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'render_template' )->once()->withArgs(
[
'/some/path/templates/google-login-button.php',
[
@@ -189,7 +191,7 @@ public function testCallbackWhenUserIsLoggedOut() {
'redirect_to' => null,
'login_url' => 'https://google.com/auth/',
],
- false
+ false,
]
)->andReturn( '' );
@@ -202,6 +204,7 @@ public function testCallbackWhenUserIsLoggedOut() {
* @covers ::should_display
*/
public function testScanShortcodeForSinglePage() {
+
$this->wpMockFunction(
'is_single',
[],
@@ -223,7 +226,7 @@ public function testScanShortcodeForSinglePage() {
false
);
- $this->assetMock->expects( $this->once() )->method( 'enqueue_login_styles' );
+ $this->asset_mock->expects( $this->once() )->method( 'enqueue_login_styles' );
$output = $this->testee->scan_shortcode( 'Hello', 'google_login', [] );
$this->assertSame( 'Hello', $output );
@@ -234,6 +237,7 @@ public function testScanShortcodeForSinglePage() {
* @covers ::should_display
*/
public function testScanShortcodeForDifferentTag() {
+
$this->wpMockFunction(
'is_single',
[],
@@ -248,8 +252,7 @@ public function testScanShortcodeForDifferentTag() {
false
);
-
- $this->assetMock->expects( $this->never() )->method( 'enqueue_login_styles' );
+ $this->asset_mock->expects( $this->never() )->method( 'enqueue_login_styles' );
$output = $this->testee->scan_shortcode( 'Hello', 'other_tag', [] );
$this->assertSame( 'Hello', $output );
@@ -259,14 +262,15 @@ public function testScanShortcodeForDifferentTag() {
* @covers ::redirect_url
*/
public function testRedirectURL() {
- $url = 'https://example.com/?redirect_to=https://example.com/wp-admin';
+
+ $url = 'https://example.com/?redirect_to=https://example.com/wp-admin';
$this->testee->redirect_uri = 'https://example.com/some-page';
$this->wpMockFunction(
'remove_query_arg',
[
'redirect_to',
- $url
+ $url,
],
1,
'https://example.com/'
@@ -280,11 +284,12 @@ public function testRedirectURL() {
* @covers ::state_redirect
*/
public function testStateRedirectWithRedirectUrl() {
+
$this->testee->redirect_uri = 'https://example.com';
$state = [
'provider' => 'google',
- 'redirect_to' => 'https://example.com'
+ 'redirect_to' => 'https://example.com',
];
$expected = $this->testee->state_redirect( $state );
@@ -295,10 +300,11 @@ public function testStateRedirectWithRedirectUrl() {
* @covers ::state_redirect
*/
public function testStateRedirectWithoutRedirectUrl() {
+
$this->testee->redirect_uri = null;
$state = [
- 'provider' => 'google'
+ 'provider' => 'google',
];
$expected = $this->testee->state_redirect( $state );
diff --git a/tests/php/Unit/PluginTest.php b/tests/php/Unit/PluginTest.php
index d594aad0..967043bf 100644
--- a/tests/php/Unit/PluginTest.php
+++ b/tests/php/Unit/PluginTest.php
@@ -29,14 +29,14 @@ class PluginTest extends TestCase {
*
* @var ContainerInterface
*/
- private $containerMock;
+ private $container_mock;
/**
* Mock for module.
*
* @var ModuleInterface
*/
- private $moduleMock;
+ private $module_mock;
/**
* Object in test.
@@ -49,9 +49,10 @@ class PluginTest extends TestCase {
* Runs before any test in class is run.
*/
public function setUp(): void {
- $this->moduleMock = $this->createMock( ModuleInterface::class );
- $this->containerMock = $this->createMock( Container::class );
- $this->testee = new Testee( $this->containerMock );
+
+ $this->module_mock = $this->createMock( ModuleInterface::class );
+ $this->container_mock = $this->createMock( Container::class );
+ $this->testee = new Testee( $this->container_mock );
}
/**
@@ -61,22 +62,23 @@ public function setUp(): void {
* @covers ::activate_modules
*/
public function testRun() {
- $this->moduleMock->expects( $this->exactly( 6 ) )
- ->method( 'init' );
- $this->containerMock->expects( $this->once() )
- ->method( 'define_services' );
+ $this->module_mock->expects( $this->exactly( 6 ) )
+ ->method( 'init' );
+
+ $this->container_mock->expects( $this->once() )
+ ->method( 'define_services' );
- $this->containerMock->expects( $this->exactly( 6 ) )
- ->method( 'get' )
- ->withAnyParameters()
- ->willReturn( $this->moduleMock );
+ $this->container_mock->expects( $this->exactly( 6 ) )
+ ->method( 'get' )
+ ->withAnyParameters()
+ ->willReturn( $this->module_mock );
$this->wpMockFunction(
'trailingslashit',
[
- WP_Mock\Functions::type( 'string' )
+ WP_Mock\Functions::type( 'string' ),
],
3,
'slashedstring/'
@@ -85,7 +87,7 @@ public function testRun() {
$this->wpMockFunction(
'plugin_dir_url',
[
- 'slashedstring/login-with-google.php'
+ 'slashedstring/login-with-google.php',
]
);
@@ -100,21 +102,22 @@ public function testRun() {
* @covers ::run
*/
public function testPath() {
- $this->moduleMock->expects( $this->exactly( 6 ) )
- ->method( 'init' );
- $this->containerMock->expects( $this->once() )
- ->method( 'define_services' );
+ $this->module_mock->expects( $this->exactly( 6 ) )
+ ->method( 'init' );
+
+ $this->container_mock->expects( $this->once() )
+ ->method( 'define_services' );
- $this->containerMock->expects( $this->exactly( 6 ) )
- ->method( 'get' )
- ->withAnyParameters()
- ->willReturn( $this->moduleMock );
+ $this->container_mock->expects( $this->exactly( 6 ) )
+ ->method( 'get' )
+ ->withAnyParameters()
+ ->willReturn( $this->module_mock );
$this->wpMockFunction(
'trailingslashit',
[
- WP_Mock\Functions::type( 'string' )
+ WP_Mock\Functions::type( 'string' ),
],
3,
'slashedstring/'
@@ -123,7 +126,7 @@ public function testPath() {
$this->wpMockFunction(
'plugin_dir_url',
[
- 'slashedstring/login-with-google.php'
+ 'slashedstring/login-with-google.php',
]
);
@@ -138,15 +141,16 @@ public function testPath() {
* @covers ::run
*/
public function testTemplateDirPath() {
- $this->containerMock->expects( $this->exactly( 6 ) )
- ->method( 'get' )
- ->withAnyParameters()
- ->willReturn( $this->moduleMock );
+
+ $this->container_mock->expects( $this->exactly( 6 ) )
+ ->method( 'get' )
+ ->withAnyParameters()
+ ->willReturn( $this->module_mock );
$this->wpMockFunction(
'trailingslashit',
[
- WP_Mock\Functions::type( 'string' )
+ WP_Mock\Functions::type( 'string' ),
],
3,
'slashedstring/'
@@ -155,7 +159,7 @@ public function testTemplateDirPath() {
$this->wpMockFunction(
'plugin_dir_url',
[
- 'slashedstring/login-with-google.php'
+ 'slashedstring/login-with-google.php',
]
);
@@ -170,15 +174,15 @@ public function testTemplateDirPath() {
* @covers ::run
*/
public function testPluginURL() {
- $this->containerMock->expects( $this->exactly( 6 ) )
- ->method( 'get' )
- ->withAnyParameters()
- ->willReturn( $this->moduleMock );
+ $this->container_mock->expects( $this->exactly( 6 ) )
+ ->method( 'get' )
+ ->withAnyParameters()
+ ->willReturn( $this->module_mock );
$this->wpMockFunction(
'trailingslashit',
[
- WP_Mock\Functions::type( 'string' )
+ WP_Mock\Functions::type( 'string' ),
],
3,
'slashedstring/'
@@ -188,9 +192,9 @@ public function testPluginURL() {
'plugin_dir_url',
[
'args' => [
- 'slashedstring/login-with-google.php'
+ 'slashedstring/login-with-google.php',
],
- 'return_arg' => 0
+ 'return_arg' => 0,
]
);
@@ -205,15 +209,15 @@ public function testPluginURL() {
* @covers ::run
*/
public function testAssetsDirPath() {
- $this->containerMock->expects( $this->exactly( 6 ) )
- ->method( 'get' )
- ->withAnyParameters()
- ->willReturn( $this->moduleMock );
+ $this->container_mock->expects( $this->exactly( 6 ) )
+ ->method( 'get' )
+ ->withAnyParameters()
+ ->willReturn( $this->module_mock );
$this->wpMockFunction(
'trailingslashit',
[
- WP_Mock\Functions::type( 'string' )
+ WP_Mock\Functions::type( 'string' ),
],
3,
'slashedstring/'
@@ -222,7 +226,7 @@ public function testAssetsDirPath() {
$this->wpMockFunction(
'plugin_dir_url',
[
- 'slashedstring/login-with-google.php'
+ 'slashedstring/login-with-google.php',
]
);
@@ -237,15 +241,16 @@ public function testAssetsDirPath() {
* @covers ::run
*/
public function testHooksAddedOnRun() {
- $this->containerMock->expects( $this->exactly( 6 ) )
- ->method( 'get' )
- ->withAnyParameters()
- ->willReturn( $this->moduleMock );
+
+ $this->container_mock->expects( $this->exactly( 6 ) )
+ ->method( 'get' )
+ ->withAnyParameters()
+ ->willReturn( $this->module_mock );
$this->wpMockFunction(
'trailingslashit',
[
- WP_Mock\Functions::type( 'string' )
+ WP_Mock\Functions::type( 'string' ),
],
3,
'slashedstring/'
@@ -254,7 +259,7 @@ public function testHooksAddedOnRun() {
$this->wpMockFunction(
'plugin_dir_url',
[
- 'slashedstring/login-with-google.php'
+ 'slashedstring/login-with-google.php',
]
);
@@ -272,11 +277,11 @@ public function testHooksAddedOnRun() {
*/
public function testLoadTranslation() {
- $this->moduleMock->expects( $this->never() )
- ->method( 'init' );
+ $this->module_mock->expects( $this->never() )
+ ->method( 'init' );
- $this->containerMock->expects( $this->never() )
- ->method( 'define_services' );
+ $this->container_mock->expects( $this->never() )
+ ->method( 'define_services' );
$this->wpMockFunction(
'get_locale',
@@ -301,7 +306,7 @@ function () {
[
'login-with-google',
false,
- 'path-to-test/languages/en_US'
+ 'path-to-test/languages/en_US',
]
);
@@ -316,6 +321,6 @@ function () {
public function testContainer() {
$container = $this->testee->container();
- $this->assertSame( $container, $this->containerMock );
+ $this->assertSame( $container, $this->container_mock );
}
}
diff --git a/tests/php/Unit/Utils/AuthenticatorTest.php b/tests/php/Unit/Utils/AuthenticatorTest.php
index 0c56f6ca..8284031e 100644
--- a/tests/php/Unit/Utils/AuthenticatorTest.php
+++ b/tests/php/Unit/Utils/AuthenticatorTest.php
@@ -35,20 +35,22 @@ class AuthenticatorTest extends TestCase {
/**
* @var Settings
*/
- private $settingsMock;
+ private $settings_mock;
/**
* @return void
*/
public function setUp(): void {
- $this->settingsMock = $this->createMock( Settings::class );
- $this->testee = new Testee( $this->settingsMock );
+
+ $this->settings_mock = $this->createMock( Settings::class );
+ $this->testee = new Testee( $this->settings_mock );
}
/**
* @covers ::__construct
*/
public function testInstance() {
+
$this->assertInstanceOf( Testee::class, $this->testee );
}
@@ -56,8 +58,9 @@ public function testInstance() {
* @covers ::authenticate
*/
public function testAuthenticateException() {
+
$user = [
- 'name' => 'Test'
+ 'name' => 'Test',
];
$user = (object) $user;
@@ -132,11 +135,11 @@ public function testAuthenticateFilterApplied() {
'test'
);
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'unique_username' )
- ->once()
- ->withArgs( ['test'] );
+ $helper_mock->expects( 'unique_username' )
+ ->once()
+ ->withArgs( [ 'test' ] );
WP_Mock::onFilter( 'rtcamp.google_register_user' )->with( $user )->reply( $wp_user );
@@ -148,7 +151,7 @@ public function testAuthenticateFilterApplied() {
* @covers ::register
*/
public function testRegisterThrowsExceptionForRegistrationDisabled() {
- $this->settingsMock->registration_enabled = false;
+ $this->settings_mock->registration_enabled = false;
$this->wpMockFunction(
'get_option',
@@ -169,12 +172,14 @@ public function testRegisterThrowsExceptionForRegistrationDisabled() {
* @covers ::register
*/
public function testRegisterThrowsExceptionForInvalidEmailDomain() {
- $user = (object) [
+
+ $user = (object) [
'email' => 'test@example.com',
'login' => 'test',
];
- $this->settingsMock->registration_enabled = true;
- $this->settingsMock->whitelisted_domains = 'somedomain.com';
+
+ $this->settings_mock->registration_enabled = true;
+ $this->settings_mock->whitelisted_domains = 'somedomain.com';
$this->expectException( \Exception::class );
$this->testee->register( $user );
@@ -185,19 +190,20 @@ public function testRegisterThrowsExceptionForInvalidEmailDomain() {
* @covers ::can_register_with_email
*/
public function testRegisterReturnsUserObject() {
+
$user = (object) [
'email' => 'test@example.com',
'login' => 'test',
];
- $this->settingsMock->registration_enabled = true;
- $this->settingsMock->whitelisted_domains = 'example.com,somedomain.com';
+ $this->settings_mock->registration_enabled = true;
+ $this->settings_mock->whitelisted_domains = 'example.com,somedomain.com';
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'unique_username' )
- ->once()
- ->withArgs( ['test'] )
- ->andReturn( 'test' );
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'unique_username' )
+ ->once()
+ ->withArgs( [ 'test' ] )
+ ->andReturn( 'test' );
$this->wpMockFunction(
'wp_generate_password',
@@ -215,7 +221,7 @@ public function testRegisterReturnsUserObject() {
'user_email' => 'test@example.com',
'first_name' => '',
'last_name' => '',
- ]
+ ],
],
1,
100
@@ -246,20 +252,21 @@ public function testRegisterReturnsUserObject() {
* @covers ::can_register_with_email
*/
public function testRegisterReturnsUserObjectWithFirstNameOnly() {
+
$user = (object) [
'email' => 'test@example.com',
'login' => 'test',
'given_name' => 'Test',
];
- $this->settingsMock->registration_enabled = true;
- $this->settingsMock->whitelisted_domains = 'example.com,somedomain.com';
+ $this->settings_mock->registration_enabled = true;
+ $this->settings_mock->whitelisted_domains = 'example.com,somedomain.com';
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'unique_username' )
- ->once()
- ->withArgs( ['test'] )
- ->andReturn( 'test' );
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'unique_username' )
+ ->once()
+ ->withArgs( [ 'test' ] )
+ ->andReturn( 'test' );
$this->wpMockFunction(
'wp_generate_password',
@@ -277,7 +284,7 @@ public function testRegisterReturnsUserObjectWithFirstNameOnly() {
'user_email' => 'test@example.com',
'first_name' => 'Test',
'last_name' => '',
- ]
+ ],
],
1,
100
@@ -308,6 +315,7 @@ public function testRegisterReturnsUserObjectWithFirstNameOnly() {
* @covers ::can_register_with_email
*/
public function testRegisterReturnsUserObjectWithFirstLastName() {
+
$user = (object) [
'email' => 'test@example.com',
'login' => 'test',
@@ -315,14 +323,14 @@ public function testRegisterReturnsUserObjectWithFirstLastName() {
'family_name' => 'User',
];
- $this->settingsMock->registration_enabled = true;
- $this->settingsMock->whitelisted_domains = 'example.com,somedomain.com';
+ $this->settings_mock->registration_enabled = true;
+ $this->settings_mock->whitelisted_domains = 'example.com,somedomain.com';
- $helperMock = Mockery::mock( 'alias:' . Helper::class );
- $helperMock->expects( 'unique_username' )
- ->once()
- ->withArgs( ['test'] )
- ->andReturn( 'test' );
+ $helper_mock = Mockery::mock( 'alias:' . Helper::class );
+ $helper_mock->expects( 'unique_username' )
+ ->once()
+ ->withArgs( [ 'test' ] )
+ ->andReturn( 'test' );
$this->wpMockFunction(
'wp_generate_password',
@@ -340,7 +348,7 @@ public function testRegisterReturnsUserObjectWithFirstLastName() {
'user_email' => 'test@example.com',
'first_name' => 'Test',
'last_name' => 'User',
- ]
+ ],
],
1,
100
@@ -370,6 +378,7 @@ public function testRegisterReturnsUserObjectWithFirstLastName() {
* @covers ::set_auth_cookies
*/
public function testSetAuthCookies() {
+
$wp_user = Mockery::mock( \WP_User::class );
$wp_user->ID = 100;
$wp_user->user_login = 'test';
@@ -392,7 +401,7 @@ public function testSetAuthCookies() {
$this->wpMockFunction(
'wp_set_auth_cookie',
[
- 100
+ 100,
],
1
);
diff --git a/tests/php/Unit/Utils/GoogleClientTest.php b/tests/php/Unit/Utils/GoogleClientTest.php
index 8a3b24bb..9e4a6d86 100644
--- a/tests/php/Unit/Utils/GoogleClientTest.php
+++ b/tests/php/Unit/Utils/GoogleClientTest.php
@@ -32,16 +32,20 @@ class GoogleClientTest extends TestCase {
* @return void
*/
public function setUp(): void {
- $this->testee = new Testee( [
- 'client_id' => 'cid',
- 'client_secret' => 'csc',
- ] );
+
+ $this->testee = new Testee(
+ [
+ 'client_id' => 'cid',
+ 'client_secret' => 'csc',
+ ]
+ );
}
/**
* @covers ::__construct
*/
public function testConstruct() {
+
$this->assertSame( 'cid', $this->getTesteeProperty( 'client_id', $this->testee ) );
$this->assertSame( 'csc', $this->getTesteeProperty( 'client_secret', $this->testee ) );
$this->assertSame( '', $this->getTesteeProperty( 'redirect_uri', $this->testee ) );
@@ -51,6 +55,7 @@ public function testConstruct() {
* @covers ::__call
*/
public function testCallWithUser() {
+
$this->expectException( Exception::class );
$this->testee->__call( 'user', null );
}
@@ -59,6 +64,7 @@ public function testCallWithUser() {
* @covers ::__call
*/
public function testCallWithEmails() {
+
$this->expectException( Exception::class );
$this->testee->__call( 'emails', null );
}
@@ -68,6 +74,7 @@ public function testCallWithEmails() {
* @covers ::gt_redirect_url
*/
public function testCallWithOtherMethods() {
+
WP_Mock::expectFilterNotAdded( 'rtcamp.github_redirect_url', '' );
$this->testee->__call( 'some_other_method', null );
@@ -81,6 +88,7 @@ public function testCallWithOtherMethods() {
* @covers ::access_token
*/
public function testSetAccessToken() {
+
WP_Mock::expectFilter( 'rtcamp.google_redirect_url', '' );
$this->wpMockFunction(
@@ -98,7 +106,7 @@ public function testSetAccessToken() {
'code' => 'abc',
'grant_type' => 'authorization_code',
],
- ]
+ ],
],
1,
'response'
@@ -107,7 +115,7 @@ public function testSetAccessToken() {
$this->wpMockFunction(
'wp_remote_retrieve_response_code',
[
- 'response'
+ 'response',
],
1,
200
@@ -121,13 +129,13 @@ public function testSetAccessToken() {
1,
function() {
$token = (object) [
- 'access_token' => 'AccessToken'
+ 'access_token' => 'AccessToken',
];
- return json_encode( $token );
+ return wp_json_encode( $token );
}
);
- $obj = $this->testee->set_access_token( 'abc' );
+ $obj = $this->testee->set_access_token( 'abc' );
$token = $this->getTesteeProperty( 'access_token', $this->testee );
$this->assertSame( $this->testee, $obj );
@@ -139,6 +147,7 @@ function() {
* @covers ::set_access_token
*/
public function testSetAccessTokenThrowsException() {
+
WP_Mock::expectFilter( 'rtcamp.google_redirect_url', '' );
$this->wpMockFunction(
@@ -156,7 +165,7 @@ public function testSetAccessTokenThrowsException() {
'code' => 'abc',
'grant_type' => 'authorization_code',
],
- ]
+ ],
],
1,
'response'
@@ -165,7 +174,7 @@ public function testSetAccessTokenThrowsException() {
$this->wpMockFunction(
'wp_remote_retrieve_response_code',
[
- 'response'
+ 'response',
],
1,
400
@@ -179,11 +188,12 @@ public function testSetAccessTokenThrowsException() {
* @covers ::access_token
*/
public function testAccessTokenThrowsExceptionForNon200Code() {
- $ghClient = $this->createPartialMock( Testee::class, [ 'gt_redirect_url' ] );
- $ghClient->expects( $this->once() )->method( 'gt_redirect_url' )->willReturn( '' );
- $ghClient->client_id = 'cid';
- $ghClient->client_secret = 'csc';
+ $gh_client = $this->createPartialMock( Testee::class, [ 'gt_redirect_url' ] );
+ $gh_client->expects( $this->once() )->method( 'gt_redirect_url' )->willReturn( '' );
+
+ $gh_client->client_id = 'cid';
+ $gh_client->client_secret = 'csc';
$this->wpMockFunction(
'wp_remote_post',
@@ -200,7 +210,7 @@ public function testAccessTokenThrowsExceptionForNon200Code() {
'code' => 'abc',
'grant_type' => 'authorization_code',
],
- ]
+ ],
],
1,
'response'
@@ -209,26 +219,27 @@ public function testAccessTokenThrowsExceptionForNon200Code() {
$this->wpMockFunction(
'wp_remote_retrieve_response_code',
[
- 'response'
+ 'response',
],
1,
400
);
$this->expectException( Exception::class );
- $ghClient->access_token( 'abc' );
+ $gh_client->access_token( 'abc' );
}
/**
* @covers ::user
*/
public function testUserReturnsObject() {
+
$this->setTesteeProperty( $this->testee, 'access_token', 'someToken' );
$this->wpMockFunction(
'trailingslashit',
[
- 'https://www.googleapis.com'
+ 'https://www.googleapis.com',
],
1,
'https://www.googleapis.com/'
@@ -242,7 +253,7 @@ public function testUserReturnsObject() {
'headers' => [
'Accept' => 'application/json',
],
- ]
+ ],
],
1,
'response'
@@ -251,7 +262,7 @@ public function testUserReturnsObject() {
$this->wpMockFunction(
'wp_remote_retrieve_response_code',
[
- 'response'
+ 'response',
],
1,
200
@@ -268,11 +279,12 @@ function() {
'email' => 'user@domain.com',
'login' => 'login',
];
- return json_encode( $token );
+ return wp_json_encode( $token );
}
);
$user = $this->testee->user();
+
$this->assertInstanceOf( \stdClass::class, $user );
$this->assertSame( $user->email, 'user@domain.com' );
$this->assertSame( $user->login, 'login' );
@@ -283,12 +295,13 @@ function() {
* @covers ::user
*/
public function testUserThrowsException() {
+
$this->setTesteeProperty( $this->testee, 'access_token', 'someToken' );
$this->wpMockFunction(
'trailingslashit',
[
- 'https://www.googleapis.com'
+ 'https://www.googleapis.com',
],
1,
'https://www.googleapis.com/'
@@ -302,7 +315,7 @@ public function testUserThrowsException() {
'headers' => [
'Accept' => 'application/json',
],
- ]
+ ],
],
1,
'response'
@@ -311,7 +324,7 @@ public function testUserThrowsException() {
$this->wpMockFunction(
'wp_remote_retrieve_response_code',
[
- 'response'
+ 'response',
],
1,
404
@@ -325,12 +338,16 @@ public function testUserThrowsException() {
* @covers ::authorization_url
*/
public function testAuthorizationURL() {
+
$scope = [ 'email', 'profile', 'openid' ];
+
WP_Mock::onFilter( 'rtcamp.google_scope' )->with( $scope )->reply( $scope );
- $ghClient = $this->createPartialMock( Testee::class, [ 'gt_redirect_url', 'state' ] );
- $ghClient->expects( $this->once() )->method( 'gt_redirect_url' )->willReturn( '' );
- $ghClient->expects( $this->once() )->method( 'state' )->willReturn( 'abcd' );
- $ghClient->client_id = 'cid';
+
+ $gh_client = $this->createPartialMock( Testee::class, [ 'gt_redirect_url', 'state' ] );
+ $gh_client->expects( $this->once() )->method( 'gt_redirect_url' )->willReturn( '' );
+ $gh_client->expects( $this->once() )->method( 'state' )->willReturn( 'abcd' );
+
+ $gh_client->client_id = 'cid';
$client_args = [
'client_id' => 'cid',
@@ -345,6 +362,6 @@ public function testAuthorizationURL() {
$expected = 'https://accounts.google.com/o/oauth2/auth?client_id=cid&redirect_uri=&state=abcd&scope=email+profile+openid&access_type=online&response_type=code';
- $this->assertSame( $expected, $ghClient->authorization_url() );
+ $this->assertSame( $expected, $gh_client->authorization_url() );
}
}
diff --git a/tests/php/Unit/Utils/TokenVerifierTest.php b/tests/php/Unit/Utils/TokenVerifierTest.php
index 1ed359b8..9875798d 100644
--- a/tests/php/Unit/Utils/TokenVerifierTest.php
+++ b/tests/php/Unit/Utils/TokenVerifierTest.php
@@ -35,24 +35,27 @@ class TokenVerifierTest extends TestCase {
/**
* @var Settings
*/
- private $settingsMock;
+ private $settings_mock;
/**
* @return void
*/
public function setUp(): void {
- $this->settingsMock = $this->createMock( Settings::class );
- $this->testee = new Testee( $this->settingsMock );
+
+ $this->settings_mock = $this->createMock( Settings::class );
+ $this->testee = new Testee( $this->settings_mock );
}
/**
* @covers ::__construct
*/
public function testInstance() {
+
$this->assertInstanceOf( Testee::class, $this->testee );
}
public function testCertsURL() {
+
$this->assertSame( 'https://www.googleapis.com/oauth2/v1/certs', $this->testee::CERTS_URL );
}
@@ -60,9 +63,11 @@ public function testCertsURL() {
* @covers ::get_supported_algorithm
*/
public function testGetSupportedAlgorithmDefault() {
+
\WP_Mock::expectFilter( 'rtcamp.default_algorithm', OPENSSL_ALGO_SHA256, '' );
+
$expected = OPENSSL_ALGO_SHA256;
- $algo = $this->testee::get_supported_algorithm();
+ $algo = $this->testee::get_supported_algorithm();
$this->assertSame( $expected, $algo );
}
@@ -71,8 +76,9 @@ public function testGetSupportedAlgorithmDefault() {
* @covers ::get_supported_algorithm
*/
public function testGetSHA256Algo() {
+
$expected = OPENSSL_ALGO_SHA256;
- $algo = $this->testee::get_supported_algorithm( 'RS256' );
+ $algo = $this->testee::get_supported_algorithm( 'RS256' );
$this->assertSame( $expected, $algo );
}
@@ -81,6 +87,7 @@ public function testGetSHA256Algo() {
* @covers ::base64_encode_url
*/
public function testBase64EncodeURL() {
+
$str = 'some+random/string=';
$result = $this->testee->base64_encode_url( $str );
@@ -91,6 +98,7 @@ public function testBase64EncodeURL() {
* @covers ::base64_decode_url
*/
public function testBase64DecodeURL() {
+
$str = 'c29tZStyYW5kb20vc3RyaW5nPQ';
$result = $this->testee->base64_decode_url( $str );
@@ -101,9 +109,11 @@ public function testBase64DecodeURL() {
* @covers ::current_user
*/
public function testCurrentUser() {
+
$wp_user = (object) [
'name' => 'Test',
];
+
$this->setTesteeProperty( $this->testee, 'current_user', $wp_user );
$result = $this->testee->current_user();
@@ -114,6 +124,7 @@ public function testCurrentUser() {
* @covers ::get_public_key
*/
public function testPublicKeyIsNull() {
+
$pk = $this->testee->get_public_key( null );
$this->assertNull( $pk );
@@ -123,10 +134,11 @@ public function testPublicKeyIsNull() {
* @covers ::get_public_key
*/
public function testPublicKeyCachedValue() {
+
$this->wpMockFunction(
'get_transient',
[
- 'lwg_pk_my_public_key'
+ 'lwg_pk_my_public_key',
],
1,
'abcd'
@@ -141,10 +153,11 @@ public function testPublicKeyCachedValue() {
* @covers ::get_public_key
*/
public function testPublicKeyIsNullForNon200Response() {
+
$this->wpMockFunction(
'get_transient',
[
- 'lwg_pk_my_public_key'
+ 'lwg_pk_my_public_key',
],
1,
null
@@ -153,7 +166,7 @@ public function testPublicKeyIsNullForNon200Response() {
$this->wpMockFunction(
'wp_remote_get',
[
- $this->testee::CERTS_URL
+ $this->testee::CERTS_URL,
],
1,
'certificate'
@@ -178,10 +191,11 @@ public function testPublicKeyIsNullForNon200Response() {
* @covers ::get_max_age
*/
public function testPublicKeyRetrievalFromResponse() {
+
$this->wpMockFunction(
'get_transient',
[
- 'lwg_pk_my_public_key'
+ 'lwg_pk_my_public_key',
],
1,
null
@@ -190,7 +204,7 @@ public function testPublicKeyRetrievalFromResponse() {
$this->wpMockFunction(
'wp_remote_get',
[
- $this->testee::CERTS_URL
+ $this->testee::CERTS_URL,
],
1,
'certificate'
@@ -206,6 +220,7 @@ public function testPublicKeyRetrievalFromResponse() {
);
$headers = \Mockery::mock( \Requests_Utility_CaseInsensitiveDictionary::class );
+
$headers->expects( 'offsetExists' )->withArgs( [ 'cache-control' ] )->andReturn( true );
$headers->expects( 'offsetGet' )->withArgs( [ 'cache-control' ] )->andReturn( 'public, max-age=600' );
@@ -213,7 +228,7 @@ public function testPublicKeyRetrievalFromResponse() {
'my_public_key' => 'thisissomerandomkey',
];
- $body = json_encode( $body );
+ $body = wp_json_encode( $body );
$this->wpMockFunction(
'wp_remote_retrieve_headers',
@@ -238,13 +253,14 @@ public function testPublicKeyRetrievalFromResponse() {
[
'lwg_pk_my_public_key',
'thisissomerandomkey',
- 300
+ 300,
],
1,
true
);
$pk = $this->testee->get_public_key( 'my_public_key' );
+
$this->assertSame( 'thisissomerandomkey', $pk );
$this->assertConditionsMet();
}
@@ -253,12 +269,13 @@ public function testPublicKeyRetrievalFromResponse() {
* @covers ::set_transient
*/
public function testSetTransient() {
+
$this->wpMockFunction(
'set_transient',
[
'key',
'val',
- 200
+ 200,
]
);
diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php
index 112893e5..ff838cfa 100644
--- a/tests/php/bootstrap.php
+++ b/tests/php/bootstrap.php
@@ -8,20 +8,22 @@
* file that was distributed with this source code.
*/
-declare(strict_types=1);
+declare( strict_types=1 );
$vendor = dirname( __DIR__, 2 ) . '/vendor/';
-if (!file_exists($vendor . 'autoload.php')) {
- die('Please install via Composer before running tests.');
+if ( ! file_exists( $vendor . 'autoload.php' ) ) {
+ die( 'Please install via Composer before running tests.' );
}
require_once __DIR__ . '/stubs/hooks.php';
require_once $vendor . 'autoload.php';
require_once __DIR__ . '/TestCase.php';
-WP_Mock::setUsePatchwork(true);
+
+WP_Mock::setUsePatchwork( true );
WP_Mock::bootstrap();
-unset($vendor);
+
+unset( $vendor );
if ( ! defined( 'GH_PLUGIN_DIR' ) ) {
define( 'GH_PLUGIN_DIR', dirname( __DIR__, 2 ) );
diff --git a/tests/php/stubs/hooks.php b/tests/php/stubs/hooks.php
index c530401d..490ee0bc 100644
--- a/tests/php/stubs/hooks.php
+++ b/tests/php/stubs/hooks.php
@@ -9,6 +9,7 @@ function remove_filter( $tag, $callback, $priority = 10, $args = 0 ) { }
}
if ( ! function_exists( 'apply_filters_deprecated' ) ) {
+
function apply_filters_deprecated( string $tag, array $args, string $version, string $replacement = '', string $message = '' ) {
return $args[0] ?? [];
}