diff --git a/Document/AuthCodeManager.php b/Document/AuthCodeManager.php index bdcc2ad1..b6eff4d7 100644 --- a/Document/AuthCodeManager.php +++ b/Document/AuthCodeManager.php @@ -14,7 +14,7 @@ namespace FOS\OAuthServerBundle\Document; use Doctrine\ODM\MongoDB\DocumentManager; -use Doctrine\ODM\MongoDB\DocumentRepository; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use FOS\OAuthServerBundle\Model\AuthCodeInterface; use FOS\OAuthServerBundle\Model\AuthCodeManager as BaseAuthCodeManager; @@ -46,6 +46,11 @@ public function __construct(DocumentManager $dm, $class) $this->class = $class; } + public function getDocumentManager(): DocumentManager + { + return $this->dm; + } + /** * {@inheritdoc} */ diff --git a/Document/ClientManager.php b/Document/ClientManager.php index 73a95d63..ad4e9d1c 100644 --- a/Document/ClientManager.php +++ b/Document/ClientManager.php @@ -14,7 +14,7 @@ namespace FOS\OAuthServerBundle\Document; use Doctrine\ODM\MongoDB\DocumentManager; -use Doctrine\ODM\MongoDB\DocumentRepository; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use FOS\OAuthServerBundle\Model\ClientInterface; use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager; @@ -46,6 +46,16 @@ public function __construct(DocumentManager $dm, $class) $this->class = $class; } + public function getRepository(): DocumentRepository + { + return $this->repository; + } + + public function getDocumentManager(): DocumentManager + { + return $this->dm; + } + /** * {@inheritdoc} */ diff --git a/Entity/AuthCodeManager.php b/Entity/AuthCodeManager.php index 048a9cee..04b51c7d 100644 --- a/Entity/AuthCodeManager.php +++ b/Entity/AuthCodeManager.php @@ -39,6 +39,11 @@ public function __construct(EntityManagerInterface $em, $class) $this->class = $class; } + public function getEntityManager(): EntityManagerInterface + { + return $this->em; + } + /** * {@inheritdoc} */ diff --git a/Entity/ClientManager.php b/Entity/ClientManager.php index 346c9732..ed80a9e3 100644 --- a/Entity/ClientManager.php +++ b/Entity/ClientManager.php @@ -79,4 +79,14 @@ public function deleteClient(ClientInterface $client) $this->em->remove($client); $this->em->flush(); } + + public function getEntityManager(): EntityManagerInterface + { + return $this->em; + } + + public function getRepository(): EntityRepository + { + return $this->repository; + } } diff --git a/Entity/TokenManager.php b/Entity/TokenManager.php index 4a87c17f..4843618a 100644 --- a/Entity/TokenManager.php +++ b/Entity/TokenManager.php @@ -94,4 +94,14 @@ public function deleteExpired() return $qb->getQuery()->execute(); } + + public function getEntityManager(): EntityManagerInterface + { + return $this->em; + } + + public function getRepository(): EntityRepository + { + return $this->repository; + } } diff --git a/Form/Handler/AuthorizeFormHandler.php b/Form/Handler/AuthorizeFormHandler.php index b0681345..f8adbae4 100644 --- a/Form/Handler/AuthorizeFormHandler.php +++ b/Form/Handler/AuthorizeFormHandler.php @@ -137,4 +137,14 @@ private function getCurrentRequest() return $this->requestStack->getCurrentRequest(); } + + public function getForm(): FormInterface + { + return $this->form; + } + + public function getRequest() + { + return $this->requestStack; + } } diff --git a/Tests/Command/CreateClientCommandTest.php b/Tests/Command/CreateClientCommandTest.php index 6230dad8..9ca70b78 100644 --- a/Tests/Command/CreateClientCommandTest.php +++ b/Tests/Command/CreateClientCommandTest.php @@ -80,7 +80,7 @@ public function testItShouldCreateClient($client): void ], ]); - $this->assertSame(0, $commandTester->getStatusCode()); + self::assertSame(0, $commandTester->getStatusCode()); $output = $commandTester->getDisplay(); diff --git a/Tests/Controller/AuthorizeControllerTest.php b/Tests/Controller/AuthorizeControllerTest.php index 6d4d24ab..393593df 100644 --- a/Tests/Controller/AuthorizeControllerTest.php +++ b/Tests/Controller/AuthorizeControllerTest.php @@ -325,7 +325,7 @@ public function testAuthorizeActionWillRenderTemplate(): void ->willReturn($response) ; - $this->assertSame($response, $this->instance->authorizeAction($this->request)); + self::assertSame($response, $this->instance->authorizeAction($this->request)); } public function testAuthorizeActionWillFinishClientAuthorization(): void @@ -395,7 +395,7 @@ public function testAuthorizeActionWillFinishClientAuthorization(): void ->willReturn($response) ; - $this->assertSame($response, $this->instance->authorizeAction($this->request)); + self::assertSame($response, $this->instance->authorizeAction($this->request)); } public function testAuthorizeActionWillEnsureLogout(): void @@ -484,7 +484,7 @@ public function testAuthorizeActionWillEnsureLogout(): void ->willReturn($response) ; - $this->assertSame($response, $this->instance->authorizeAction($this->request)); + self::assertSame($response, $this->instance->authorizeAction($this->request)); } public function testAuthorizeActionWillProcessAuthorizationForm(): void @@ -594,6 +594,6 @@ public function testAuthorizeActionWillProcessAuthorizationForm(): void ->willReturn($response) ; - $this->assertSame($response, $this->instance->authorizeAction($this->request)); + self::assertSame($response, $this->instance->authorizeAction($this->request)); } } diff --git a/Tests/DependencyInjection/FOSOAuthServerExtensionTest.php b/Tests/DependencyInjection/FOSOAuthServerExtensionTest.php index 9875cd8a..b819f7c8 100644 --- a/Tests/DependencyInjection/FOSOAuthServerExtensionTest.php +++ b/Tests/DependencyInjection/FOSOAuthServerExtensionTest.php @@ -100,8 +100,8 @@ public function testLoadAuthorizeRouting() $collection = $loader->load(__DIR__.'/../../Resources/config/routing/authorize.xml'); $authorizeRoute = $collection->get('fos_oauth_server_authorize'); - $this->assertSame('/oauth/v2/auth', $authorizeRoute->getPath()); - $this->assertSame(['GET', 'POST'], $authorizeRoute->getMethods()); + self::assertSame('/oauth/v2/auth', $authorizeRoute->getPath()); + self::assertSame(['GET', 'POST'], $authorizeRoute->getMethods()); } public function testLoadTokenRouting() @@ -111,8 +111,8 @@ public function testLoadTokenRouting() $collection = $loader->load(__DIR__.'/../../Resources/config/routing/token.xml'); $tokenRoute = $collection->get('fos_oauth_server_token'); - $this->assertSame('/oauth/v2/token', $tokenRoute->getPath()); - $this->assertSame(['GET', 'POST'], $tokenRoute->getMethods()); + self::assertSame('/oauth/v2/token', $tokenRoute->getPath()); + self::assertSame(['GET', 'POST'], $tokenRoute->getMethods()); } public function testWithoutService() @@ -127,7 +127,7 @@ public function testWithoutService() $instance = new FOSOAuthServerExtension(); $instance->load([$config], $this->container); - $this->assertSame( + self::assertSame( $this->container->getParameter('fos_oauth_server.server.options'), [] ); @@ -153,7 +153,7 @@ public function testStringSupportedScopes() $instance = new FOSOAuthServerExtension(); $instance->load([$config], $this->container); - $this->assertSame( + self::assertSame( $this->container->getParameter('fos_oauth_server.server.options'), [ 'supported_scopes' => 'scope1 scope2 scope3 scope4', @@ -181,7 +181,7 @@ public function testArraySupportedScopes() $instance = new FOSOAuthServerExtension(); $instance->load([$config], $this->container); - $this->assertSame( + self::assertSame( $this->container->getParameter('fos_oauth_server.server.options'), [ 'supported_scopes' => 'scope1 scope2 scope3 scope4', @@ -235,18 +235,18 @@ public function testShouldAliasServivesWhenCustomDriverIsUsed() ]], $container); $this->assertTrue($container->hasAlias('fos_oauth_server.storage')); - $this->assertSame('fos_oauth_server.storage.default', (string) $container->getAlias('fos_oauth_server.storage')); + self::assertSame('fos_oauth_server.storage.default', (string) $container->getAlias('fos_oauth_server.storage')); $this->assertTrue($container->hasAlias('fos_oauth_server.client_manager')); - $this->assertSame('the_client_manager_id', (string) $container->getAlias('fos_oauth_server.client_manager')); + self::assertSame('the_client_manager_id', (string) $container->getAlias('fos_oauth_server.client_manager')); $this->assertTrue($container->hasAlias('fos_oauth_server.access_token_manager')); - $this->assertSame('the_access_token_manager_id', (string) $container->getAlias('fos_oauth_server.access_token_manager')); + self::assertSame('the_access_token_manager_id', (string) $container->getAlias('fos_oauth_server.access_token_manager')); $this->assertTrue($container->hasAlias('fos_oauth_server.refresh_token_manager')); - $this->assertSame('the_refresh_token_manager_id', (string) $container->getAlias('fos_oauth_server.refresh_token_manager')); + self::assertSame('the_refresh_token_manager_id', (string) $container->getAlias('fos_oauth_server.refresh_token_manager')); $this->assertTrue($container->hasAlias('fos_oauth_server.auth_code_manager')); - $this->assertSame('the_auth_code_manager_id', (string) $container->getAlias('fos_oauth_server.auth_code_manager')); + self::assertSame('the_auth_code_manager_id', (string) $container->getAlias('fos_oauth_server.auth_code_manager')); } } diff --git a/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php b/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php index f538d59c..47a13f0c 100644 --- a/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php +++ b/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php @@ -55,12 +55,12 @@ public function setUp() : void public function testGetPosition() { - $this->assertSame('pre_auth', $this->instance->getPosition()); + self::assertSame('pre_auth', $this->instance->getPosition()); } public function testGetKey() { - $this->assertSame('fos_oauth', $this->instance->getKey()); + self::assertSame('fos_oauth', $this->instance->getKey()); } public function testCreate() @@ -130,7 +130,7 @@ protected function useDefinitionDecorator() ->willReturn(null) ; - $this->assertSame([ + self::assertSame([ 'security.authentication.provider.fos_oauth_server.'.$id, 'security.authentication.listener.fos_oauth_server.'.$id, 'fos_oauth_server.security.entry_point', @@ -182,7 +182,7 @@ protected function useChildDefinition() ->willReturn(null) ; - $this->assertSame([ + self::assertSame([ 'security.authentication.provider.fos_oauth_server.'.$id, 'security.authentication.listener.fos_oauth_server.'.$id, 'fos_oauth_server.security.entry_point', diff --git a/Tests/Document/AuthCodeManagerTest.php b/Tests/Document/AuthCodeManagerTest.php index 61293731..ffb12db8 100644 --- a/Tests/Document/AuthCodeManagerTest.php +++ b/Tests/Document/AuthCodeManagerTest.php @@ -81,13 +81,13 @@ public function setUp() : void public function testConstructWillSetParameters(): void { - $this->assertAttributeSame($this->documentManager, 'dm', $this->instance); - $this->assertAttributeSame($this->className, 'class', $this->instance); + self::assertSame($this->documentManager, $this->instance->getDocumentManager()); + self::assertSame($this->className, $this->instance->getClass()); } public function testGetClassWillReturnClassName(): void { - $this->assertSame($this->className, $this->instance->getClass()); + self::assertSame($this->className, $this->instance->getClass()); } public function testFindAuthCodeBy(): void @@ -104,7 +104,7 @@ public function testFindAuthCodeBy(): void ->willReturn($randomResult) ; - $this->assertSame($randomResult, $this->instance->findAuthCodeBy($criteria)); + self::assertSame($randomResult, $this->instance->findAuthCodeBy($criteria)); } public function testUpdateAuthCode(): void @@ -218,6 +218,6 @@ public function testDeleteExpired(): void ->willReturn($data) ; - $this->assertSame($data['n'], $this->instance->deleteExpired()); + self::assertSame($data['n'], $this->instance->deleteExpired()); } } diff --git a/Tests/Document/ClientManagerTest.php b/Tests/Document/ClientManagerTest.php index 611e3eb8..11ef3373 100644 --- a/Tests/Document/ClientManagerTest.php +++ b/Tests/Document/ClientManagerTest.php @@ -17,6 +17,7 @@ use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use FOS\OAuthServerBundle\Document\ClientManager; use FOS\OAuthServerBundle\Model\ClientInterface; +use PHPUnit\Framework\MockObject\MockObject; /** * Class ClientManagerTest. @@ -26,7 +27,7 @@ class ClientManagerTest extends \PHPUnit\Framework\TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|DocumentManager + * @var MockObject|DocumentManager */ protected $documentManager; @@ -36,7 +37,7 @@ class ClientManagerTest extends \PHPUnit\Framework\TestCase protected $className; /** - * @var \PHPUnit_Framework_MockObject_MockObject|DocumentRepository + * @var MockObject|DocumentRepository */ protected $repository; @@ -73,19 +74,19 @@ public function setUp() : void parent::setUp(); } - public function testConstructWillSetParameters() + public function testConstructWillSetParameters(): void { - $this->assertAttributeSame($this->documentManager, 'dm', $this->instance); - $this->assertAttributeSame($this->repository, 'repository', $this->instance); - $this->assertAttributeSame($this->className, 'class', $this->instance); + self::assertSame($this->documentManager, $this->instance->getDocumentManager()); + self::assertSame($this->repository, $this->instance->getRepository()); + self::assertSame($this->className, $this->instance->getClass()); } - public function testGetClass() + public function testGetClass(): void { - $this->assertSame($this->className, $this->instance->getClass()); + self::assertSame($this->className, $this->instance->getClass()); } - public function testFindClientBy() + public function testFindClientBy(): void { $randomResult = \random_bytes(5); $criteria = [ @@ -99,7 +100,7 @@ public function testFindClientBy() ->willReturn($randomResult) ; - $this->assertSame($randomResult, $this->instance->findClientBy($criteria)); + self::assertSame($randomResult, $this->instance->findClientBy($criteria)); } public function testUpdateClient() diff --git a/Tests/Document/TokenManagerTest.php b/Tests/Document/TokenManagerTest.php index 8b65da18..2b52c0aa 100644 --- a/Tests/Document/TokenManagerTest.php +++ b/Tests/Document/TokenManagerTest.php @@ -90,7 +90,7 @@ public function testFindTokenByToken() ->willReturn($randomResult) ; - $this->assertSame($randomResult, $this->instance->findTokenByToken($randomToken)); + self::assertSame($randomResult, $this->instance->findTokenByToken($randomToken)); } public function testUpdateTokenPersistsAndFlushes() @@ -117,7 +117,7 @@ public function testUpdateTokenPersistsAndFlushes() public function testGetClass() { - $this->assertSame($this->className, $this->instance->getClass()); + self::assertSame($this->className, $this->instance->getClass()); } public function testDeleteToken() @@ -204,6 +204,6 @@ public function testDeleteExpired() ->willReturn($data) ; - $this->assertSame($data['n'], $this->instance->deleteExpired()); + self::assertSame($data['n'], $this->instance->deleteExpired()); } } diff --git a/Tests/Entity/AuthCodeManagerTest.php b/Tests/Entity/AuthCodeManagerTest.php index fec01586..58c2747e 100644 --- a/Tests/Entity/AuthCodeManagerTest.php +++ b/Tests/Entity/AuthCodeManagerTest.php @@ -20,6 +20,7 @@ use Doctrine\ORM\QueryBuilder; use FOS\OAuthServerBundle\Entity\AuthCodeManager; use FOS\OAuthServerBundle\Model\AuthCodeInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -32,7 +33,7 @@ class AuthCodeManagerTest extends TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface + * @var MockObject|EntityManagerInterface */ protected $entityManager; @@ -59,18 +60,18 @@ public function setUp() : void parent::setUp(); } - public function testConstructWillSetParameters() + public function testConstructWillSetParameters(): void { - $this->assertAttributeSame($this->entityManager, 'em', $this->instance); - $this->assertAttributeSame($this->className, 'class', $this->instance); + self::assertSame($this->entityManager, $this->instance->getEntityManager()); + self::assertSame($this->className, $this->instance->getClass()); } - public function testGetClassWillReturnClassName() + public function testGetClassWillReturnClassName(): void { - $this->assertSame($this->className, $this->instance->getClass()); + self::assertSame($this->className, $this->instance->getClass()); } - public function testFindAuthCodeBy() + public function testFindAuthCodeBy(): void { $repository = $this->getMockBuilder(ObjectRepository::class) ->disableOriginalConstructor() @@ -96,10 +97,10 @@ public function testFindAuthCodeBy() ->willReturn($randomResult) ; - $this->assertSame($randomResult, $this->instance->findAuthCodeBy($criteria)); + self::assertSame($randomResult, $this->instance->findAuthCodeBy($criteria)); } - public function testUpdateAuthCode() + public function testUpdateAuthCode(): void { $authCode = $this->getMockBuilder(AuthCodeInterface::class) ->disableOriginalConstructor() @@ -123,7 +124,7 @@ public function testUpdateAuthCode() $this->assertNull($this->instance->updateAuthCode($authCode)); } - public function testDeleteAuthCode() + public function testDeleteAuthCode(): void { $authCode = $this->getMockBuilder(AuthCodeInterface::class) ->disableOriginalConstructor() @@ -147,7 +148,7 @@ public function testDeleteAuthCode() $this->assertNull($this->instance->deleteAuthCode($authCode)); } - public function testDeleteExpired() + public function testDeleteExpired(): void { $randomResult = \random_bytes(10); @@ -215,6 +216,6 @@ public function testDeleteExpired() ->willReturn($randomResult) ; - $this->assertSame($randomResult, $this->instance->deleteExpired()); + self::assertSame($randomResult, $this->instance->deleteExpired()); } } diff --git a/Tests/Entity/ClientManagerTest.php b/Tests/Entity/ClientManagerTest.php index 8cab127b..7a7d6f84 100644 --- a/Tests/Entity/ClientManagerTest.php +++ b/Tests/Entity/ClientManagerTest.php @@ -17,6 +17,7 @@ use Doctrine\ORM\EntityRepository; use FOS\OAuthServerBundle\Entity\ClientManager; use FOS\OAuthServerBundle\Model\ClientInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -27,7 +28,7 @@ class ClientManagerTest extends TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface + * @var MockObject|EntityManagerInterface */ protected $entityManager; @@ -37,7 +38,7 @@ class ClientManagerTest extends TestCase protected $className; /** - * @var \PHPUnit_Framework_MockObject_MockObject|EntityRepository + * @var MockObject|EntityRepository */ protected $repository; @@ -70,19 +71,19 @@ public function setUp() : void parent::setUp(); } - public function testConstructWillSetParameters() + public function testConstructWillSetParameters(): void { - $this->assertAttributeSame($this->entityManager, 'em', $this->instance); - $this->assertAttributeSame($this->repository, 'repository', $this->instance); - $this->assertAttributeSame($this->className, 'class', $this->instance); + self::assertSame($this->entityManager, $this->instance->getEntityManager()); + self::assertSame($this->repository, $this->instance->getRepository()); + self::assertSame($this->className, $this->instance->getClass()); } - public function testGetClass() + public function testGetClass(): void { - $this->assertSame($this->className, $this->instance->getClass()); + self::assertSame($this->className, $this->instance->getClass()); } - public function testFindClientBy() + public function testFindClientBy(): void { $criteria = [ \random_bytes(5), @@ -96,10 +97,10 @@ public function testFindClientBy() ->willReturn($randomResult) ; - $this->assertSame($randomResult, $this->instance->findClientBy($criteria)); + self::assertSame($randomResult, $this->instance->findClientBy($criteria)); } - public function testUpdateClient() + public function testUpdateClient(): void { $client = $this->getMockBuilder(ClientInterface::class) ->disableOriginalConstructor() diff --git a/Tests/Entity/TokenManagerTest.php b/Tests/Entity/TokenManagerTest.php index 33382019..a5b5765c 100644 --- a/Tests/Entity/TokenManagerTest.php +++ b/Tests/Entity/TokenManagerTest.php @@ -74,14 +74,14 @@ public function setUp() : void $this->instance = new TokenManager($this->entityManager, $this->className); } - public function testConstructWillSetParameters() + public function testConstructWillSetParameters(): void { - $this->assertAttributeSame($this->entityManager, 'em', $this->instance); - $this->assertAttributeSame($this->repository, 'repository', $this->instance); - $this->assertAttributeSame($this->className, 'class', $this->instance); + self::assertSame($this->entityManager, $this->instance->getEntityManager()); + self::assertSame($this->repository, $this->instance->getRepository()); + self::assertSame($this->className, $this->instance->getClass()); } - public function testUpdateTokenPersistsAndFlushes() + public function testUpdateTokenPersistsAndFlushes(): void { $token = new AccessToken(); @@ -102,7 +102,7 @@ public function testUpdateTokenPersistsAndFlushes() public function testGetClass() { - $this->assertSame($this->className, $this->instance->getClass()); + self::assertSame($this->className, $this->instance->getClass()); } public function testFindTokenBy() @@ -120,7 +120,7 @@ public function testFindTokenBy() ->willReturn($randomResult) ; - $this->assertSame($randomResult, $this->instance->findTokenBy($criteria)); + self::assertSame($randomResult, $this->instance->findTokenBy($criteria)); } public function testUpdateToken() @@ -227,6 +227,6 @@ public function testDeleteExpired() ->willReturn($randomResult) ; - $this->assertSame($randomResult, $this->instance->deleteExpired()); + self::assertSame($randomResult, $this->instance->deleteExpired()); } } diff --git a/Tests/Form/Handler/AuthorizeFormHandlerTest.php b/Tests/Form/Handler/AuthorizeFormHandlerTest.php index 28f65e84..2895980f 100644 --- a/Tests/Form/Handler/AuthorizeFormHandlerTest.php +++ b/Tests/Form/Handler/AuthorizeFormHandlerTest.php @@ -15,7 +15,10 @@ use FOS\OAuthServerBundle\Form\Handler\AuthorizeFormHandler; use FOS\OAuthServerBundle\Form\Model\Authorize; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use ReflectionException; +use ReflectionMethod; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\ParameterBag; @@ -24,6 +27,7 @@ class AuthorizeFormHandlerTest extends TestCase { + /** @var MockObject | FormInterface */ protected $form; protected $request; @@ -32,6 +36,7 @@ class AuthorizeFormHandlerTest extends TestCase protected $requestRequest; + /** @var MockObject | ContainerInterface */ protected $container; /** @@ -82,8 +87,7 @@ public function testConstructWillAcceptRequestObjectAsRequest() $this->instance = new AuthorizeFormHandler($this->form, $request); - $this->assertAttributeSame($this->form, 'form', $this->instance); - $this->assertAttributeSame($request, 'requestStack', $this->instance); + $this->assertAttributesWereSet($request); } public function testConstructWillAcceptRequestStackObjectAsRequest() @@ -95,19 +99,16 @@ public function testConstructWillAcceptRequestStackObjectAsRequest() $this->instance = new AuthorizeFormHandler($this->form, $requestStack); - $this->assertAttributeSame($this->form, 'form', $this->instance); - $this->assertAttributeSame($requestStack, 'requestStack', $this->instance); + $this->assertAttributesWereSet($requestStack); } public function testConstructWillAcceptNullAsRequest() { $this->instance = new AuthorizeFormHandler($this->form, null); - $this->assertAttributeSame($this->form, 'form', $this->instance); - $this->assertAttributeSame(null, 'requestStack', $this->instance); + $this->assertAttributesWereSet(null); $this->instance = new AuthorizeFormHandler($this->form); - $this->assertAttributeSame($this->form, 'form', $this->instance); - $this->assertAttributeSame(null, 'requestStack', $this->instance); + $this->assertAttributesWereSet(null); } public function testConstructWillThrowException() @@ -135,7 +136,7 @@ public function testIsAcceptedWillProxyValueToFormData() ->willReturn($data) ; - $this->assertSame($data->accepted, $this->instance->isAccepted()); + self::assertSame($data->accepted, $this->instance->isAccepted()); } public function testIsRejectedWillNegateAcceptedValueFromFormData() @@ -171,13 +172,13 @@ public function testGetScopeWillProxyValueToFormData() ->willReturn($data) ; - $this->assertSame($data->scope, $this->instance->getScope()); + self::assertSame($data->scope, $this->instance->getScope()); } public function testGetCurrentRequestWillReturnRequestObject() { $method = $this->getReflectionMethod('getCurrentRequest'); - $this->assertSame($this->request, $method->invoke($this->instance)); + self::assertSame($this->request, $method->invoke($this->instance)); } public function testGetCurrentRequestWillReturnCurrentRequestFromRequestStack() @@ -198,7 +199,7 @@ public function testGetCurrentRequestWillReturnCurrentRequestFromRequestStack() ; $method = $this->getReflectionMethod('getCurrentRequest'); - $this->assertSame($request, $method->invoke($this->instance)); + self::assertSame($request, $method->invoke($this->instance)); } public function testGetCurrentRequestWillReturnRequestServiceFromContainerIfNoneIsSet() @@ -216,7 +217,7 @@ public function testGetCurrentRequestWillReturnRequestServiceFromContainerIfNone ; $method = $this->getReflectionMethod('getCurrentRequest'); - $this->assertSame($randomData, $method->invoke($this->instance)); + self::assertSame($randomData, $method->invoke($this->instance)); } /** @@ -252,7 +253,7 @@ public function testOnSuccessWillReplaceGETSuperGlobal() $this->assertNull($method->invoke($this->instance)); - $this->assertSame($expectedSuperGlobalValue, $_GET); + self::assertSame($expectedSuperGlobalValue, $_GET); } public function testProcessWillReturnFalseIfRequestIsNull() @@ -436,7 +437,7 @@ public function testProcessWillHandleRequestOnPostAndWillProcessDataIfFormIsVali ->willReturn($formData) ; - $this->assertSame([], $_GET); + self::assertSame([], $_GET); $expectedSuperGlobalValue = [ 'client_id' => $query->client_id, @@ -448,15 +449,16 @@ public function testProcessWillHandleRequestOnPostAndWillProcessDataIfFormIsVali $this->assertTrue($this->instance->process()); - $this->assertSame($expectedSuperGlobalValue, $_GET); + self::assertSame($expectedSuperGlobalValue, $_GET); } + /** - * @param string $methodName - * - * @return \ReflectionMethod + * @param $methodName + * @return ReflectionMethod + * @throws ReflectionException */ - protected function getReflectionMethod($methodName) + protected function getReflectionMethod($methodName): ReflectionMethod { $reflectionObject = new \ReflectionObject($this->instance); $reflectionMethod = $reflectionObject->getMethod($methodName); @@ -464,4 +466,13 @@ protected function getReflectionMethod($methodName) return $reflectionMethod; } + + /** + * @param MockObject $request + */ + private function assertAttributesWereSet(?MockObject $request): void + { + self::assertSame($this->form, $this->instance->getForm()); + self::assertSame($request, $this->instance->getRequest()); + } } diff --git a/Tests/Form/Type/AuthorizeFormTypeTest.php b/Tests/Form/Type/AuthorizeFormTypeTest.php index 0afa5d6d..0f734ad0 100644 --- a/Tests/Form/Type/AuthorizeFormTypeTest.php +++ b/Tests/Form/Type/AuthorizeFormTypeTest.php @@ -16,6 +16,7 @@ use FOS\OAuthServerBundle\Form\Model\Authorize; use FOS\OAuthServerBundle\Form\Type\AuthorizeFormType; use FOS\OAuthServerBundle\Util\LegacyFormHelper; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\Forms; use Symfony\Component\Form\Test\TypeTestCase; @@ -42,7 +43,7 @@ protected function setUp() : void $this->instance = new AuthorizeFormType(); } - public function testSubmit() + public function testSubmit(): void { $accepted = true; $formData = [ @@ -55,13 +56,13 @@ public function testSubmit() $authorize = new Authorize($accepted, $formData); - $form = $this->factory->create(LegacyFormHelper::getType('FOS\OAuthServerBundle\Form\Type\AuthorizeFormType'), $authorize); + $form = $this->factory->create(LegacyFormHelper::getType(AuthorizeFormType::class), $authorize); $form->submit($formData); $this->assertTrue($form->isSynchronized()); - $this->assertSame($authorize, $form->getData()); - $this->assertSame($accepted, $authorize->accepted); + self::assertSame($authorize, $form->getData()); + self::assertSame($accepted, $authorize->accepted); $view = $form->createView(); $children = $view->children; @@ -71,9 +72,9 @@ public function testSubmit() } } - public function testConfigureOptionsWillSetDefaultsOnTheOptionsResolver() + public function testConfigureOptionsWillSetDefaultsOnTheOptionsResolver(): void { - /** @var \PHPUnit_Framework_MockObject_MockObject|OptionsResolver $resolver */ + /** @var MockObject|OptionsResolver $resolver */ $resolver = $this->getMockBuilder(OptionsResolver::class) ->disableOriginalConstructor() ->getMock() @@ -83,7 +84,7 @@ public function testConfigureOptionsWillSetDefaultsOnTheOptionsResolver() ->expects($this->once()) ->method('setDefaults') ->with([ - 'data_class' => 'FOS\OAuthServerBundle\Form\Model\Authorize', + 'data_class' => Authorize::class, ]) ->willReturn($resolver) ; @@ -91,14 +92,14 @@ public function testConfigureOptionsWillSetDefaultsOnTheOptionsResolver() $this->assertNull($this->instance->configureOptions($resolver)); } - public function testGetName() + public function testGetName(): void { - $this->assertSame('fos_oauth_server_authorize', $this->instance->getName()); + self::assertSame('fos_oauth_server_authorize', $this->instance->getName()); } - public function testGetBlockPrefix() + public function testGetBlockPrefix(): void { - $this->assertSame('fos_oauth_server_authorize', $this->instance->getBlockPrefix()); + self::assertSame('fos_oauth_server_authorize', $this->instance->getBlockPrefix()); } protected function getTypes() diff --git a/Tests/Model/TokenTest.php b/Tests/Model/TokenTest.php index 053032c3..3a072758 100644 --- a/Tests/Model/TokenTest.php +++ b/Tests/Model/TokenTest.php @@ -35,7 +35,7 @@ public function testHasExpired($expiresAt, $expect) $token = new Token(); $token->setExpiresAt($expiresAt); - $this->assertSame($expect, $token->hasExpired()); + self::assertSame($expect, $token->hasExpired()); } public static function getTestHasExpiredData() @@ -51,7 +51,7 @@ public function testExpiresIn() { $token = new Token(); - $this->assertSame(PHP_INT_MAX, $token->getExpiresIn()); + self::assertSame(PHP_INT_MAX, $token->getExpiresIn()); } public function testExpiresInWithExpiresAt() @@ -59,6 +59,6 @@ public function testExpiresInWithExpiresAt() $token = new Token(); $token->setExpiresAt(time() + 60); - $this->assertSame(60, $token->getExpiresIn()); + self::assertSame(60, $token->getExpiresIn()); } } diff --git a/Tests/Propel/AuthCodeManagerTest.php b/Tests/Propel/AuthCodeManagerTest.php index b571ef2a..87a25c14 100644 --- a/Tests/Propel/AuthCodeManagerTest.php +++ b/Tests/Propel/AuthCodeManagerTest.php @@ -38,7 +38,7 @@ public function setUp() : void public function testConstruct(): void { - $this->assertSame(self::AUTH_CODE_CLASS, $this->manager->getClass()); + self::assertSame(self::AUTH_CODE_CLASS, $this->manager->getClass()); } public function testCreateClass() @@ -87,7 +87,7 @@ public function testFindAuthCode() $return = $this->manager->findAuthCodeBy(['token' => '12345']); $this->assertNotNull($return); - $this->assertSame($authCode, $return); + self::assertSame($authCode, $return); } public function testFindAuthCodeByToken() @@ -96,7 +96,7 @@ public function testFindAuthCodeByToken() $return = $this->manager->findAuthCodeByToken('12345'); $this->assertNotNull($return); - $this->assertSame($authCode, $return); + self::assertSame($authCode, $return); } public function testFindAuthCodeByTokenReturnsNullIfNotFound() @@ -123,11 +123,11 @@ public function testDeleteExpired() $a1 = $this->createAuthCode('12345', time() + 100); $a2 = $this->createAuthCode('67890', time() - 100); - $this->assertSame(2, AuthCodeQuery::create()->count()); + self::assertSame(2, AuthCodeQuery::create()->count()); $nb = $this->manager->deleteExpired(); - $this->assertSame(1, $nb); + self::assertSame(1, $nb); $this->assertTrue($a1->equals(AuthCodeQuery::create()->findOne())); } diff --git a/Tests/Propel/AuthCodeTest.php b/Tests/Propel/AuthCodeTest.php index e8993bc4..6b68952d 100644 --- a/Tests/Propel/AuthCodeTest.php +++ b/Tests/Propel/AuthCodeTest.php @@ -33,7 +33,7 @@ public function testHasExpired($expiresAt, $expect) $token = new AuthCode(); $token->setExpiresAt($expiresAt); - $this->assertSame($expect, $token->hasExpired()); + self::assertSame($expect, $token->hasExpired()); } public static function getTestHasExpiredData() @@ -49,7 +49,7 @@ public function testExpiresIn() { $token = new AuthCode(); - $this->assertSame(PHP_INT_MAX, $token->getExpiresIn()); + self::assertSame(PHP_INT_MAX, $token->getExpiresIn()); } public function testExpiresInWithExpiresAt() @@ -57,6 +57,6 @@ public function testExpiresInWithExpiresAt() $token = new AuthCode(); $token->setExpiresAt(time() + 60); - $this->assertSame(60, $token->getExpiresIn()); + self::assertSame(60, $token->getExpiresIn()); } } diff --git a/Tests/Propel/ClientManagerTest.php b/Tests/Propel/ClientManagerTest.php index d5cbd655..c6109ebc 100644 --- a/Tests/Propel/ClientManagerTest.php +++ b/Tests/Propel/ClientManagerTest.php @@ -33,7 +33,7 @@ public function setUp() : void public function testConstruct() { - $this->assertSame(self::CLIENT_CLASS, $this->manager->getClass()); + self::assertSame(self::CLIENT_CLASS, $this->manager->getClass()); } public function testCreateClass() @@ -43,7 +43,7 @@ public function testCreateClass() public function testUpdate() { - $client = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Client') + $client = $this->getMockBuilder(Client::class) ->disableOriginalConstructor() ->getMock() ; @@ -57,7 +57,8 @@ public function testUpdate() public function testDelete() { - $client = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Client') + /** @var Client $client */ + $client = $this->getMockBuilder(Client::class) ->disableOriginalConstructor() ->getMock() ; @@ -94,7 +95,7 @@ public function testFindClient() $return = $this->manager->findClientBy(['id' => '1', 'randomId' => '2345']); $this->assertNotNull($return); - $this->assertSame($client, $return); + self::assertSame($client, $return); } public function testFindClientByPublicId() @@ -103,7 +104,7 @@ public function testFindClientByPublicId() $return = $this->manager->findClientByPublicId('1_12345'); $this->assertNotNull($return); - $this->assertSame($client, $return); + self::assertSame($client, $return); } public function testFindClientByPublicIdReturnsNullIfNotFound() diff --git a/Tests/Propel/ClientTest.php b/Tests/Propel/ClientTest.php index f10cb282..e33bb5da 100644 --- a/Tests/Propel/ClientTest.php +++ b/Tests/Propel/ClientTest.php @@ -27,10 +27,10 @@ public function testConstructor() $types = $client->getAllowedGrantTypes(); $this->assertCount(1, $types); - $this->assertSame(OAuth2::GRANT_TYPE_AUTH_CODE, $types[0]); + self::assertSame(OAuth2::GRANT_TYPE_AUTH_CODE, $types[0]); } - public function testCheckSecretWithInvalidArgument() + public function testCheckSecretWithInvalidArgument(): void { $client = new Client(); @@ -39,7 +39,7 @@ public function testCheckSecretWithInvalidArgument() $this->assertFalse($client->checkSecret(null)); } - public function testCheckSecret() + public function testCheckSecret(): void { $client = new Client(); $client->setSecret('foo'); diff --git a/Tests/Propel/TokenManagerTest.php b/Tests/Propel/TokenManagerTest.php index bc6f9835..5eeeadb4 100644 --- a/Tests/Propel/TokenManagerTest.php +++ b/Tests/Propel/TokenManagerTest.php @@ -38,7 +38,7 @@ public function setUp() : void public function testConstruct() { - $this->assertSame(self::TOKEN_CLASS, $this->manager->getClass()); + self::assertSame(self::TOKEN_CLASS, $this->manager->getClass()); } public function testCreateClass() @@ -100,7 +100,7 @@ public function testFindToken() $return = $this->manager->findTokenBy(['token' => '12345']); $this->assertNotNull($return); - $this->assertSame($token, $return); + self::assertSame($token, $return); } public function testFindTokenByToken() @@ -109,7 +109,7 @@ public function testFindTokenByToken() $return = $this->manager->findTokenByToken('12345'); $this->assertNotNull($return); - $this->assertSame($token, $return); + self::assertSame($token, $return); } public function testFindTokenByTokenReturnsNullIfNotFound() @@ -124,11 +124,11 @@ public function testDeleteExpired() $a1 = $this->createToken('12345', time() + 100); $a2 = $this->createToken('67890', time() - 100); - $this->assertSame(2, TokenQuery::create()->count()); + self::assertSame(2, TokenQuery::create()->count()); $nb = $this->manager->deleteExpired(); - $this->assertSame(1, $nb); + self::assertSame(1, $nb); $this->assertTrue($a1->equals(TokenQuery::create()->findOne())); } diff --git a/Tests/Propel/TokenTest.php b/Tests/Propel/TokenTest.php index 6ad9e931..5effb30f 100644 --- a/Tests/Propel/TokenTest.php +++ b/Tests/Propel/TokenTest.php @@ -28,15 +28,15 @@ class TokenTest extends PropelTestCase * @param mixed $expiresAt * @param mixed $expect */ - public function testHasExpired($expiresAt, $expect) + public function testHasExpired($expiresAt, $expect): void { $token = new Token(); $token->setExpiresAt($expiresAt); - $this->assertSame($expect, $token->hasExpired()); + self::assertSame($expect, $token->hasExpired()); } - public static function getTestHasExpiredData() + public static function getTestHasExpiredData(): array { return [ [time() + 60, false], @@ -45,19 +45,19 @@ public static function getTestHasExpiredData() ]; } - public function testExpiresIn() + public function testExpiresIn(): void { $token = new Token(); - $this->assertSame(PHP_INT_MAX, $token->getExpiresIn()); + self::assertSame(PHP_INT_MAX, $token->getExpiresIn()); } - public function testExpiresInWithExpiresAt() + public function testExpiresInWithExpiresAt(): void { $token = new Token(); $token->setExpiresAt(time() + 60); - $this->assertSame(60, $token->getExpiresIn()); + self::assertSame(60, $token->getExpiresIn()); } } diff --git a/Tests/Security/Authentication/Provider/OAuthProviderTest.php b/Tests/Security/Authentication/Provider/OAuthProviderTest.php index 885d2007..a14cca65 100644 --- a/Tests/Security/Authentication/Provider/OAuthProviderTest.php +++ b/Tests/Security/Authentication/Provider/OAuthProviderTest.php @@ -93,13 +93,13 @@ public function testAuthenticateReturnsTokenIfValid(): void $result = $this->provider->authenticate($token); - $this->assertSame($this->user, $result->getUser()); - $this->assertSame($token->getToken(), $result->getToken()); + self::assertSame($this->user, $result->getUser()); + self::assertSame($token->getToken(), $result->getToken()); $this->assertTrue($result->isAuthenticated()); $this->assertCount(1, $result->getRoleNames()); $roles = $result->getRoleNames(); - $this->assertSame('ROLE_USER', $roles[0]); + self::assertSame('ROLE_USER', $roles[0]); } public function testAuthenticateReturnsTokenIfValidEvenIfNullData(): void @@ -144,9 +144,9 @@ public function testAuthenticateTransformsScopesAsRoles(): void $roles = $result->getRoleNames(); $this->assertCount(2, $roles); //$this->assertInstanceOf(\Symfony\Component\Security\Core\Role::class, $roles[0]); - $this->assertSame('ROLE_FOO', $roles[0]); + self::assertSame('ROLE_FOO', $roles[0]); //$this->assertInstanceOf(Role::class, $roles[1]); - $this->assertSame('ROLE_BAR', $roles[1]); + self::assertSame('ROLE_BAR', $roles[1]); } public function testAuthenticateWithNullScope(): void diff --git a/Tests/Security/Authentification/Token/OAuthTokenTest.php b/Tests/Security/Authentification/Token/OAuthTokenTest.php index 4e343fbd..d5d5b72f 100644 --- a/Tests/Security/Authentification/Token/OAuthTokenTest.php +++ b/Tests/Security/Authentification/Token/OAuthTokenTest.php @@ -31,7 +31,7 @@ public function setUp() : void parent::setUp(); } - public function testSetTokenWillSetToken() + public function testSetTokenWillSetToken(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -39,10 +39,10 @@ public function testSetTokenWillSetToken() ; $this->assertNull($this->instance->setToken($token)); - $this->assertAttributeSame($token, 'token', $this->instance); + self::assertSame($token, $this->instance->getToken()); } - public function testGetTokenWillReturnToken() + public function testGetTokenWillReturnToken(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -51,10 +51,10 @@ public function testGetTokenWillReturnToken() $this->assertNull($this->instance->getToken()); $this->assertNull($this->instance->setToken($token)); - $this->assertSame($token, $this->instance->getToken()); + self::assertSame($token, $this->instance->getToken()); } - public function testGetCredentialsWillReturnToken() + public function testGetCredentialsWillReturnToken(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -63,6 +63,6 @@ public function testGetCredentialsWillReturnToken() $this->assertNull($this->instance->getCredentials()); $this->assertNull($this->instance->setToken($token)); - $this->assertSame($token, $this->instance->getCredentials()); + self::assertSame($token, $this->instance->getCredentials()); } } diff --git a/Tests/Security/Firewall/OAuthListenerTest.php b/Tests/Security/Firewall/OAuthListenerTest.php index 87561c43..22e3aaaf 100644 --- a/Tests/Security/Firewall/OAuthListenerTest.php +++ b/Tests/Security/Firewall/OAuthListenerTest.php @@ -17,6 +17,7 @@ use FOS\OAuthServerBundle\Security\Firewall\OAuthListener; use FOS\OAuthServerBundle\Tests\TestCase; use OAuth2\OAuth2; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; @@ -28,6 +29,7 @@ class OAuthListenerTest extends TestCase protected $authManager; + /** @var MockObject */ protected $securityContext; protected $event; @@ -93,7 +95,7 @@ public function testHandle() $token = $listener->handle($this->event); $this->assertInstanceOf(OAuthToken::class, $token); - $this->assertSame('a-token', $token->getToken()); + self::assertSame('a-token', $token->getToken()); } public function testHandleResponse() @@ -130,6 +132,6 @@ public function testHandleResponse() $ret = $listener->handle($this->event); - $this->assertSame($response, $ret); + self::assertSame($response, $ret); } } diff --git a/Tests/Storage/OAuthStorageTest.php b/Tests/Storage/OAuthStorageTest.php index ef0b4215..f14385c1 100644 --- a/Tests/Storage/OAuthStorageTest.php +++ b/Tests/Storage/OAuthStorageTest.php @@ -95,10 +95,10 @@ public function testGetClientReturnsClientWithGivenId() ->willReturn($client) ; - $this->assertSame($client, $this->storage->getClient('123_abc')); + self::assertSame($client, $this->storage->getClient('123_abc')); } - public function testGetClientReturnsNullIfNotExists() + public function testGetClientReturnsNullIfNotExists(): void { $client = new Client(); @@ -111,9 +111,9 @@ public function testGetClientReturnsNullIfNotExists() $this->assertNull($this->storage->getClient('123_abc')); } - public function testCheckClientCredentialsThrowsIfInvalidClientClass() + public function testCheckClientCredentialsThrowsIfInvalidClientClass(): void { - $client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client') + $client = $this->getMockBuilder(IOAuth2Client::class) ->disableOriginalConstructor() ->getMock() ; @@ -122,7 +122,7 @@ public function testCheckClientCredentialsThrowsIfInvalidClientClass() $this->storage->checkClientCredentials($client, 'dummy'); } - public function testCheckClientCredentialsReturnsTrueOnValidCredentials() + public function testCheckClientCredentialsReturnsTrueOnValidCredentials(): void { $client = new Client(); $client->setSecret('dummy'); @@ -130,7 +130,7 @@ public function testCheckClientCredentialsReturnsTrueOnValidCredentials() $this->assertTrue($this->storage->checkClientCredentials($client, 'dummy')); } - public function testCheckClientCredentialsReturnsFalseOnValidCredentials() + public function testCheckClientCredentialsReturnsFalseOnValidCredentials(): void { $client = new Client(); $client->setSecret('dummy'); @@ -138,7 +138,7 @@ public function testCheckClientCredentialsReturnsFalseOnValidCredentials() $this->assertFalse($this->storage->checkClientCredentials($client, 'passe')); } - public function testGetAccessTokenReturnsAccessTokenWithGivenId() + public function testGetAccessTokenReturnsAccessTokenWithGivenId(): void { $token = new AccessToken(); @@ -148,10 +148,10 @@ public function testGetAccessTokenReturnsAccessTokenWithGivenId() ->willReturn($token) ; - $this->assertSame($token, $this->storage->getAccessToken('123_abc')); + self::assertSame($token, $this->storage->getAccessToken('123_abc')); } - public function testGetAccessTokenReturnsNullIfNotExists() + public function testGetAccessTokenReturnsNullIfNotExists(): void { $token = new AccessToken(); @@ -164,9 +164,9 @@ public function testGetAccessTokenReturnsNullIfNotExists() $this->assertNull($this->storage->getAccessToken('123_abc')); } - public function testCreateAccessTokenThrowsOnInvalidClientClass() + public function testCreateAccessTokenThrowsOnInvalidClientClass(): void { - $client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client') + $client = $this->getMockBuilder(IOAuth2Client::class) ->disableOriginalConstructor() ->getMock() ; @@ -175,7 +175,7 @@ public function testCreateAccessTokenThrowsOnInvalidClientClass() $this->storage->createAccessToken('foo', $client, new User(42), 1, 'foo bar'); } - public function testCreateAccessToken() + public function testCreateAccessToken(): void { $savedToken = null; @@ -196,17 +196,17 @@ public function testCreateAccessToken() $token = $this->storage->createAccessToken('foo', $client, $user, 1, 'foo bar'); - $this->assertSame($token, $savedToken); + self::assertSame($token, $savedToken); - $this->assertSame('foo', $token->getToken()); - $this->assertSame($client, $token->getClient()); - $this->assertSame($user, $token->getData()); - $this->assertSame($user, $token->getUser()); - $this->assertSame(1, $token->getExpiresAt()); - $this->assertSame('foo bar', $token->getScope()); + self::assertSame('foo', $token->getToken()); + self::assertSame($client, $token->getClient()); + self::assertSame($user, $token->getData()); + self::assertSame($user, $token->getUser()); + self::assertSame(1, $token->getExpiresAt()); + self::assertSame('foo bar', $token->getScope()); } - public function testCreateAccessTokenWithoutUser() + public function testCreateAccessTokenWithoutUser(): void { $savedToken = null; @@ -227,10 +227,10 @@ public function testCreateAccessTokenWithoutUser() $token = $this->storage->createAccessToken('foo', $client, $user, 1, 'foo bar'); - $this->assertSame($token, $savedToken); + self::assertSame($token, $savedToken); } - public function testGetRefreshTokenReturnsRefreshTokenWithGivenId() + public function testGetRefreshTokenReturnsRefreshTokenWithGivenId(): void { $token = new RefreshToken(); @@ -240,7 +240,7 @@ public function testGetRefreshTokenReturnsRefreshTokenWithGivenId() ->willReturn($token) ; - $this->assertSame($token, $this->storage->getRefreshToken('123_abc')); + self::assertSame($token, $this->storage->getRefreshToken('123_abc')); } public function testGetRefreshTokenReturnsNullIfNotExists() @@ -254,7 +254,7 @@ public function testGetRefreshTokenReturnsNullIfNotExists() $this->assertNull($this->storage->getRefreshToken('123_abc')); } - public function testCreateRefreshTokenThrowsOnInvalidClientClass() + public function testCreateRefreshTokenThrowsOnInvalidClientClass(): void { $client = $this->getMockBuilder(IOAuth2Client::class) ->disableOriginalConstructor() @@ -265,7 +265,7 @@ public function testCreateRefreshTokenThrowsOnInvalidClientClass() $this->storage->createRefreshToken('foo', $client, 42, 1, 'foo bar'); } - public function testCreateRefreshToken() + public function testCreateRefreshToken(): void { $savedToken = null; @@ -286,17 +286,17 @@ public function testCreateRefreshToken() $token = $this->storage->createRefreshToken('foo', $client, $user, 1, 'foo bar'); - $this->assertSame($token, $savedToken); + self::assertSame($token, $savedToken); - $this->assertSame('foo', $token->getToken()); - $this->assertSame($client, $token->getClient()); - $this->assertSame($user, $token->getData()); - $this->assertSame($user, $token->getUser()); - $this->assertSame(1, $token->getExpiresAt()); - $this->assertSame('foo bar', $token->getScope()); + self::assertSame('foo', $token->getToken()); + self::assertSame($client, $token->getClient()); + self::assertSame($user, $token->getData()); + self::assertSame($user, $token->getUser()); + self::assertSame(1, $token->getExpiresAt()); + self::assertSame('foo bar', $token->getScope()); } - public function testCreateRefreshTokenWithoutUser() + public function testCreateRefreshTokenWithoutUser(): void { $savedToken = null; @@ -317,7 +317,7 @@ public function testCreateRefreshTokenWithoutUser() $token = $this->storage->createRefreshToken('foo', $client, $user, 1, 'foo bar'); - $this->assertSame($token, $savedToken); + self::assertSame($token, $savedToken); } public function testCheckRestrictedGrantTypeThrowsOnInvalidClientClass(): void @@ -332,7 +332,7 @@ public function testCheckRestrictedGrantTypeThrowsOnInvalidClientClass(): void $this->storage->checkRestrictedGrantType($client, 'foo'); } - public function testCheckRestrictedGrantType() + public function testCheckRestrictedGrantType(): void { $client = new Client(); $client->setAllowedGrantTypes(['foo', 'bar']); @@ -342,7 +342,7 @@ public function testCheckRestrictedGrantType() $this->assertFalse($this->storage->checkRestrictedGrantType($client, 'baz')); } - public function testCheckUserCredentialsThrowsOnInvalidClientClass() + public function testCheckUserCredentialsThrowsOnInvalidClientClass(): void { $client = $this->getMockBuilder(IOAuth2Client::class) ->disableOriginalConstructor() @@ -354,7 +354,7 @@ public function testCheckUserCredentialsThrowsOnInvalidClientClass() $this->storage->checkUserCredentials($client, 'Joe', 'baz'); } - public function testCheckUserCredentialsCatchesAuthenticationExceptions() + public function testCheckUserCredentialsCatchesAuthenticationExceptions(): void { $client = new Client(); @@ -370,7 +370,7 @@ public function testCheckUserCredentialsCatchesAuthenticationExceptions() $this->assertFalse($result); } - public function testCheckUserCredentialsReturnsTrueOnValidCredentials() + public function testCheckUserCredentialsReturnsTrueOnValidCredentials(): void { $client = new Client(); $user = $this->getMockBuilder(UserInterface::class) @@ -404,7 +404,7 @@ public function testCheckUserCredentialsReturnsTrueOnValidCredentials() ->willReturn($encoder) ; - $this->assertSame([ + self::assertSame([ 'data' => $user, ], $this->storage->checkUserCredentials($client, 'Joe', 'baz')); } @@ -446,7 +446,7 @@ public function testCheckUserCredentialsReturnsFalseOnInvalidCredentials(): void $this->assertFalse($this->storage->checkUserCredentials($client, 'Joe', 'baz')); } - public function testCheckUserCredentialsReturnsFalseIfUserNotExist() + public function testCheckUserCredentialsReturnsFalseIfUserNotExist(): void { $client = new Client(); @@ -459,9 +459,9 @@ public function testCheckUserCredentialsReturnsFalseIfUserNotExist() $this->assertFalse($this->storage->checkUserCredentials($client, 'Joe', 'baz')); } - public function testCreateAuthCodeThrowsOnInvalidClientClass() + public function testCreateAuthCodeThrowsOnInvalidClientClass(): void { - $client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client') + $client = $this->getMockBuilder(IOAuth2Client::class) ->disableOriginalConstructor() ->getMock() ; @@ -470,7 +470,7 @@ public function testCreateAuthCodeThrowsOnInvalidClientClass() $this->storage->createAuthCode('foo', $client, 42, 'http://www.example.com/', 1, 'foo bar'); } - public function testCreateAuthCode() + public function testCreateAuthCode(): void { $savedCode = null; @@ -491,17 +491,17 @@ public function testCreateAuthCode() $code = $this->storage->createAuthCode('foo', $client, $user, 'http://www.example.com/', 1, 'foo bar'); - $this->assertSame($code, $savedCode); + self::assertSame($code, $savedCode); - $this->assertSame('foo', $code->getToken()); - $this->assertSame($client, $code->getClient()); - $this->assertSame($user, $code->getData()); - $this->assertSame($user, $code->getUser()); - $this->assertSame(1, $code->getExpiresAt()); - $this->assertSame('foo bar', $code->getScope()); + self::assertSame('foo', $code->getToken()); + self::assertSame($client, $code->getClient()); + self::assertSame($user, $code->getData()); + self::assertSame($user, $code->getUser()); + self::assertSame(1, $code->getExpiresAt()); + self::assertSame('foo bar', $code->getScope()); } - public function testGetAuthCodeReturnsAuthCodeWithGivenId() + public function testGetAuthCodeReturnsAuthCodeWithGivenId(): void { $code = new AuthCode(); @@ -511,10 +511,10 @@ public function testGetAuthCodeReturnsAuthCodeWithGivenId() ->willReturn($code) ; - $this->assertSame($code, $this->storage->getAuthCode('123_abc')); + self::assertSame($code, $this->storage->getAuthCode('123_abc')); } - public function testGetAuthCodeReturnsNullIfNotExists() + public function testGetAuthCodeReturnsNullIfNotExists(): void { $this->authCodeManager->expects($this->once()) ->method('findAuthCodeByToken') @@ -525,7 +525,7 @@ public function testGetAuthCodeReturnsNullIfNotExists() $this->assertNull($this->storage->getAuthCode('123_abc')); } - public function testValidGrantExtension() + public function testValidGrantExtension(): void { $grantExtension = $this->getMockBuilder(GrantExtensionInterface::class) ->disableOriginalConstructor() @@ -552,7 +552,7 @@ public function testValidGrantExtension() ); } - public function testInvalidGrantExtension() + public function testInvalidGrantExtension(): void { $this->expectException(\OAuth2\OAuth2ServerException::class); @@ -563,7 +563,7 @@ public function testInvalidGrantExtension() $this->storage->checkGrantExtension($client, 'https://friendsofsymfony.com/grants/bar', [], []); } - public function testDoubleSetGrantExtension() + public function testDoubleSetGrantExtension(): void { $grantExtension = $this->getMockBuilder(GrantExtensionInterface::class) ->disableOriginalConstructor() @@ -581,10 +581,10 @@ public function testDoubleSetGrantExtension() $grantExtensionsProperty->setAccessible(true); $grantExtensions = $grantExtensionsProperty->getValue($this->storage); - $this->assertSame($grantExtension2, $grantExtensions[$uri]); + self::assertSame($grantExtension2, $grantExtensions[$uri]); } - public function testMarkAuthCodeAsUsedIfAuthCodeFound() + public function testMarkAuthCodeAsUsedIfAuthCodeFound(): void { $authCode = $this->getMockBuilder(AuthCodeInterface::class) ->disableOriginalConstructor() @@ -606,7 +606,7 @@ public function testMarkAuthCodeAsUsedIfAuthCodeFound() $this->storage->markAuthCodeAsUsed('123_abc'); } - public function testMarkAuthCodeAsUsedIfAuthCodeNotFound() + public function testMarkAuthCodeAsUsedIfAuthCodeNotFound(): void { $this->authCodeManager->expects($this->atLeastOnce()) ->method('findAuthCodeByToken') diff --git a/Tests/Util/RandomTest.php b/Tests/Util/RandomTest.php index 0e785531..bdab04fa 100644 --- a/Tests/Util/RandomTest.php +++ b/Tests/Util/RandomTest.php @@ -58,6 +58,6 @@ public function testGenerateTokenWillUseRandomBytesIfAvailable() ->willReturn($baseConvertResult) ; - $this->assertSame($baseConvertResult, Random::generateToken()); + self::assertSame($baseConvertResult, Random::generateToken()); } }