From ef009b089c5b81c1dc1e2cf7c9e1c1ecbeab35c1 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Sat, 3 Oct 2020 22:17:33 +0100 Subject: [PATCH 1/3] Make CI useful again and add type declarations This commit: - Adds type declarations to bring down the PHPStan error count - Makes the CI not dependant on a PHPStan pass so that it can run through to the unit tests - Upgrades the dev dependanies so that they can install on a modern system (i.e. without ext-mongo) - Disables the Propel tests - Updates the PHPStan configuration file --- .travis.yml | 5 +- Command/CleanCommand.php | 11 +- Command/CreateClientCommand.php | 5 +- Controller/AuthorizeController.php | 10 +- .../Compiler/GrantExtensionsCompilerPass.php | 2 +- .../Compiler/RequestStackCompilerPass.php | 2 +- DependencyInjection/Configuration.php | 5 +- .../FOSOAuthServerExtension.php | 13 +++ .../Security/Factory/OAuthFactory.php | 3 + Document/AuthCodeManager.php | 6 +- Document/ClientManager.php | 2 +- Document/TokenManager.php | 2 +- Entity/AuthCodeManager.php | 4 +- Entity/ClientManager.php | 2 +- Entity/TokenManager.php | 2 +- Event/AbstractAuthorizationEvent.php | 2 +- FOSOAuthServerBundle.php | 2 +- Form/Handler/AuthorizeFormHandler.php | 13 ++- Form/Type/AuthorizeFormType.php | 4 +- Makefile | 2 +- Model/AuthCode.php | 2 +- Model/AuthCodeInterface.php | 2 +- Model/AuthCodeManagerInterface.php | 5 +- Model/ClientInterface.php | 12 +- Model/ClientManagerInterface.php | 7 ++ Model/TokenInterface.php | 9 ++ Model/TokenManagerInterface.php | 3 + Propel/AuthCodeManager.php | 4 +- Security/EntryPoint/OAuthEntryPoint.php | 3 + Storage/GrantExtensionDispatcherInterface.php | 5 +- Storage/OAuthStorage.php | 9 +- Tests/Command/CleanCommandTest.php | 10 +- Tests/Command/CreateClientCommandTest.php | 4 +- Tests/Controller/AuthorizeControllerTest.php | 50 ++++----- .../GrantExtensionsCompilerPassTest.php | 8 +- .../Compiler/RequestStackCompilerPassTest.php | 8 +- .../DependencyInjection/ConfigurationTest.php | 16 +-- .../FOSOAuthServerExtensionTest.php | 27 +++-- .../Security/Factory/OAuthFactoryTest.php | 10 +- Tests/Document/AuthCodeManagerTest.php | 18 +-- Tests/Document/ClientManagerTest.php | 16 +-- Tests/Document/TokenManagerTest.php | 16 +-- Tests/Entity/AuthCodeManagerTest.php | 16 +-- Tests/Entity/ClientManagerTest.php | 16 +-- Tests/Entity/TokenManagerTest.php | 20 ++-- Tests/FOSOAuthServerBundleTest.php | 6 +- .../Form/Handler/AuthorizeFormHandlerTest.php | 51 +++++---- Tests/Form/Type/AuthorizeFormTypeTest.php | 13 ++- Tests/Functional/AppKernel.php | 2 +- Tests/Functional/BootTest.php | 5 +- Tests/Functional/TestBundle/Entity/User.php | 11 +- Tests/Functional/TestCase.php | 3 + Tests/Model/TokenTest.php | 9 +- Tests/Propel/AuthCodeManagerTest.php | 22 ++-- Tests/Propel/AuthCodeTest.php | 4 +- Tests/Propel/ClientManagerTest.php | 22 ++-- Tests/Propel/ClientTest.php | 6 +- Tests/Propel/PropelTestCase.php | 2 +- Tests/Propel/TokenManagerTest.php | 22 ++-- Tests/Propel/TokenTest.php | 4 +- .../Provider/OAuthProviderTest.php | 18 +-- .../Authentification/Token/OAuthTokenTest.php | 10 +- Tests/Security/Firewall/OAuthListenerTest.php | 18 ++- Tests/Storage/OAuthStorageTest.php | 105 +++++++++++------- Tests/Util/RandomTest.php | 4 +- Tests/bootstrap.php | 16 +-- Util/Random.php | 3 + composer.json | 7 +- phpstan.neon | 21 ---- phpstan.neon.dist | 29 +++++ phpunit.xml.dist | 12 +- 71 files changed, 493 insertions(+), 325 deletions(-) delete mode 100644 phpstan.neon create mode 100644 phpstan.neon.dist diff --git a/.travis.yml b/.travis.yml index 5560f7d3..b9ad4718 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,13 @@ language: php -sudo: true php: - 7.2 -service: +services: - docker - mongodb -matrix: +jobs: fast_finish: true include: - php: 7.2 diff --git a/Command/CleanCommand.php b/Command/CleanCommand.php index 7b168f12..46dfbabf 100644 --- a/Command/CleanCommand.php +++ b/Command/CleanCommand.php @@ -21,8 +21,17 @@ class CleanCommand extends Command { + /** + * @var TokenManagerInterface + */ private $accessTokenManager; + /** + * @var TokenManagerInterface + */ private $refreshTokenManager; + /** + * @var AuthCodeManagerInterface + */ private $authCodeManager; public function __construct( @@ -40,7 +49,7 @@ public function __construct( /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); diff --git a/Command/CreateClientCommand.php b/Command/CreateClientCommand.php index 0a84f736..305ed250 100644 --- a/Command/CreateClientCommand.php +++ b/Command/CreateClientCommand.php @@ -22,6 +22,9 @@ class CreateClientCommand extends Command { + /** + * @var ClientManagerInterface + */ private $clientManager; public function __construct(ClientManagerInterface $clientManager) @@ -34,7 +37,7 @@ public function __construct(ClientManagerInterface $clientManager) /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); diff --git a/Controller/AuthorizeController.php b/Controller/AuthorizeController.php index 69c10101..3c32203e 100644 --- a/Controller/AuthorizeController.php +++ b/Controller/AuthorizeController.php @@ -130,7 +130,7 @@ public function __construct( /** * Authorize. */ - public function authorizeAction(Request $request) + public function authorizeAction(Request $request): Response { $user = $this->tokenStorage->getToken()->getUser(); @@ -228,6 +228,9 @@ protected function getClient() return $this->client; } + /** + * @param array $context + */ protected function renderAuthorize(array $context): Response { return new Response( @@ -235,10 +238,7 @@ protected function renderAuthorize(array $context): Response ); } - /** - * @return Request|null - */ - private function getCurrentRequest() + private function getCurrentRequest(): Request { $request = $this->requestStack->getCurrentRequest(); if (null === $request) { diff --git a/DependencyInjection/Compiler/GrantExtensionsCompilerPass.php b/DependencyInjection/Compiler/GrantExtensionsCompilerPass.php index 31cdaca7..2a4fef81 100644 --- a/DependencyInjection/Compiler/GrantExtensionsCompilerPass.php +++ b/DependencyInjection/Compiler/GrantExtensionsCompilerPass.php @@ -23,7 +23,7 @@ */ class GrantExtensionsCompilerPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $storageDefinition = $container->findDefinition('fos_oauth_server.storage'); $className = $container->getParameterBag()->resolveValue($storageDefinition->getClass()); diff --git a/DependencyInjection/Compiler/RequestStackCompilerPass.php b/DependencyInjection/Compiler/RequestStackCompilerPass.php index a45f5ca3..1eeeb389 100644 --- a/DependencyInjection/Compiler/RequestStackCompilerPass.php +++ b/DependencyInjection/Compiler/RequestStackCompilerPass.php @@ -27,7 +27,7 @@ final class RequestStackCompilerPass implements CompilerPassInterface /** * {@inheritdoc} */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if ($container->has('request_stack')) { return; diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index fb13f78c..77ced031 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -26,6 +26,7 @@ class Configuration implements ConfigurationInterface { /** * {@inheritdoc} + * @return TreeBuilder */ public function getConfigTreeBuilder() { @@ -83,7 +84,7 @@ public function getConfigTreeBuilder() return $treeBuilder; } - private function addAuthorizeSection(ArrayNodeDefinition $node) + private function addAuthorizeSection(ArrayNodeDefinition $node): void { $node ->children() @@ -109,7 +110,7 @@ private function addAuthorizeSection(ArrayNodeDefinition $node) ; } - private function addServiceSection(ArrayNodeDefinition $node) + private function addServiceSection(ArrayNodeDefinition $node): void { $node ->addDefaultsIfNotSet() diff --git a/DependencyInjection/FOSOAuthServerExtension.php b/DependencyInjection/FOSOAuthServerExtension.php index 92773af5..e029d28a 100644 --- a/DependencyInjection/FOSOAuthServerExtension.php +++ b/DependencyInjection/FOSOAuthServerExtension.php @@ -26,6 +26,7 @@ class FOSOAuthServerExtension extends Extension { /** * {@inheritdoc} + * @return void */ public function load(array $configs, ContainerBuilder $container) { @@ -109,6 +110,9 @@ public function getAlias() return 'fos_oauth_server'; } + /** + * @return void + */ protected function remapParameters(array $config, ContainerBuilder $container, array $map) { foreach ($map as $name => $paramName) { @@ -118,6 +122,9 @@ protected function remapParameters(array $config, ContainerBuilder $container, a } } + /** + * @return void + */ protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces) { foreach ($namespaces as $ns => $map) { @@ -140,6 +147,9 @@ protected function remapParametersNamespaces(array $config, ContainerBuilder $co } } + /** + * @return void + */ protected function loadAuthorize(array $config, ContainerBuilder $container, XmlFileLoader $loader) { $loader->load('authorize.xml'); @@ -157,6 +167,9 @@ protected function loadAuthorize(array $config, ContainerBuilder $container, Xml ]); } + /** + * @return string + */ private function computeArraySupportedScopes(array $supportedScopes) { foreach ($supportedScopes as $scope) { diff --git a/DependencyInjection/Security/Factory/OAuthFactory.php b/DependencyInjection/Security/Factory/OAuthFactory.php index c638bcc3..b5f6d6ce 100644 --- a/DependencyInjection/Security/Factory/OAuthFactory.php +++ b/DependencyInjection/Security/Factory/OAuthFactory.php @@ -28,6 +28,8 @@ class OAuthFactory implements SecurityFactoryInterface { /** * {@inheritdoc} + * @param mixed $config + * @return array */ public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) { @@ -62,6 +64,7 @@ public function getKey() /** * {@inheritdoc} + * @return void */ public function addConfiguration(NodeDefinition $node) { diff --git a/Document/AuthCodeManager.php b/Document/AuthCodeManager.php index bdcc2ad1..18de142d 100644 --- a/Document/AuthCodeManager.php +++ b/Document/AuthCodeManager.php @@ -35,7 +35,7 @@ class AuthCodeManager extends BaseAuthCodeManager */ protected $class; - public function __construct(DocumentManager $dm, $class) + public function __construct(DocumentManager $dm, string $class) { // NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected /** @var DocumentRepository $repository */ @@ -65,7 +65,7 @@ public function findAuthCodeBy(array $criteria) /** * {@inheritdoc} */ - public function updateAuthCode(AuthCodeInterface $authCode) + public function updateAuthCode(AuthCodeInterface $authCode): void { $this->dm->persist($authCode); $this->dm->flush(); @@ -74,7 +74,7 @@ public function updateAuthCode(AuthCodeInterface $authCode) /** * {@inheritdoc} */ - public function deleteAuthCode(AuthCodeInterface $authCode) + public function deleteAuthCode(AuthCodeInterface $authCode): void { $this->dm->remove($authCode); $this->dm->flush(); diff --git a/Document/ClientManager.php b/Document/ClientManager.php index 73a95d63..a1f3ce40 100644 --- a/Document/ClientManager.php +++ b/Document/ClientManager.php @@ -35,7 +35,7 @@ class ClientManager extends BaseClientManager */ protected $class; - public function __construct(DocumentManager $dm, $class) + public function __construct(DocumentManager $dm, string $class) { // NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected /** @var DocumentRepository $repository */ diff --git a/Document/TokenManager.php b/Document/TokenManager.php index 9050924d..c08b6a1a 100644 --- a/Document/TokenManager.php +++ b/Document/TokenManager.php @@ -35,7 +35,7 @@ class TokenManager extends BaseTokenManager */ protected $class; - public function __construct(DocumentManager $dm, $class) + public function __construct(DocumentManager $dm, string $class) { // NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected /** @var DocumentRepository $repository */ diff --git a/Entity/AuthCodeManager.php b/Entity/AuthCodeManager.php index 355f2bd2..c3dc05d5 100644 --- a/Entity/AuthCodeManager.php +++ b/Entity/AuthCodeManager.php @@ -57,7 +57,7 @@ public function findAuthCodeBy(array $criteria) /** * {@inheritdoc} */ - public function updateAuthCode(AuthCodeInterface $authCode) + public function updateAuthCode(AuthCodeInterface $authCode): void { $this->em->persist($authCode); $this->em->flush(); @@ -66,7 +66,7 @@ public function updateAuthCode(AuthCodeInterface $authCode) /** * {@inheritdoc} */ - public function deleteAuthCode(AuthCodeInterface $authCode) + public function deleteAuthCode(AuthCodeInterface $authCode): void { $this->em->remove($authCode); $this->em->flush(); diff --git a/Entity/ClientManager.php b/Entity/ClientManager.php index 346c9732..ee27355d 100644 --- a/Entity/ClientManager.php +++ b/Entity/ClientManager.php @@ -35,7 +35,7 @@ class ClientManager extends BaseClientManager */ protected $class; - public function __construct(EntityManagerInterface $em, $class) + public function __construct(EntityManagerInterface $em, string $class) { // NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected /** @var EntityRepository $repository */ diff --git a/Entity/TokenManager.php b/Entity/TokenManager.php index 4a87c17f..98eda9b8 100644 --- a/Entity/TokenManager.php +++ b/Entity/TokenManager.php @@ -35,7 +35,7 @@ class TokenManager extends BaseTokenManager */ protected $class; - public function __construct(EntityManagerInterface $em, $class) + public function __construct(EntityManagerInterface $em, string $class) { // NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected /** @var EntityRepository $repository */ diff --git a/Event/AbstractAuthorizationEvent.php b/Event/AbstractAuthorizationEvent.php index 3620c684..0c540ceb 100644 --- a/Event/AbstractAuthorizationEvent.php +++ b/Event/AbstractAuthorizationEvent.php @@ -46,7 +46,7 @@ public function getUser(): UserInterface return $this->user; } - public function setAuthorizedClient(bool $authorized) + public function setAuthorizedClient(bool $authorized): void { $this->isAuthorizedClient = $authorized; } diff --git a/FOSOAuthServerBundle.php b/FOSOAuthServerBundle.php index 1505745d..ab676cde 100644 --- a/FOSOAuthServerBundle.php +++ b/FOSOAuthServerBundle.php @@ -28,7 +28,7 @@ public function __construct() $this->extension = new FOSOAuthServerExtension(); } - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/Form/Handler/AuthorizeFormHandler.php b/Form/Handler/AuthorizeFormHandler.php index 600c6458..05315dc5 100644 --- a/Form/Handler/AuthorizeFormHandler.php +++ b/Form/Handler/AuthorizeFormHandler.php @@ -57,16 +57,22 @@ public function __construct(FormInterface $form, $requestStack = null) * * @param ContainerInterface|null $container A ContainerInterface instance or null */ - public function setContainer(ContainerInterface $container = null) + public function setContainer(ContainerInterface $container = null): void { $this->container = $container; } + /** + * @return bool + */ public function isAccepted() { return $this->form->getData()->accepted; } + /** + * @return bool + */ public function isRejected() { return !$this->form->getData()->accepted; @@ -112,7 +118,7 @@ public function getScope() * @todo finishClientAuthorization() is a bit odd since it accepts $data * but then proceeds to ignore it and forces everything to be in $request->query */ - protected function onSuccess() + protected function onSuccess(): void { $_GET = [ 'client_id' => $this->form->getData()->client_id, @@ -123,6 +129,9 @@ protected function onSuccess() ]; } + /** + * @return ?Request + */ private function getCurrentRequest() { if (null === $this->requestStack) { diff --git a/Form/Type/AuthorizeFormType.php b/Form/Type/AuthorizeFormType.php index 47eedcf2..bcff90d3 100644 --- a/Form/Type/AuthorizeFormType.php +++ b/Form/Type/AuthorizeFormType.php @@ -23,7 +23,7 @@ */ class AuthorizeFormType extends AbstractType { - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('client_id', HiddenType::class); $builder->add('response_type', HiddenType::class); @@ -35,7 +35,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'data_class' => 'FOS\OAuthServerBundle\Form\Model\Authorize', diff --git a/Makefile b/Makefile index e4d7b1db..a9d1742f 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ ci: phpstan phpunit-coverage lint: cs-full-check phpstan phpstan: - sh -c "${QA_DOCKER_COMMAND} phpstan analyse --configuration phpstan.neon --level 6 ." + sh -c "${QA_DOCKER_COMMAND} phpstan analyse . || true" cs: sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --diff" diff --git a/Model/AuthCode.php b/Model/AuthCode.php index 4686e175..c7d78f2e 100644 --- a/Model/AuthCode.php +++ b/Model/AuthCode.php @@ -26,7 +26,7 @@ class AuthCode extends Token implements AuthCodeInterface /** * {@inheritdoc} */ - public function setRedirectUri($redirectUri) + public function setRedirectUri($redirectUri): void { $this->redirectUri = $redirectUri; } diff --git a/Model/AuthCodeInterface.php b/Model/AuthCodeInterface.php index 47154fcb..1143a148 100644 --- a/Model/AuthCodeInterface.php +++ b/Model/AuthCodeInterface.php @@ -23,5 +23,5 @@ interface AuthCodeInterface extends TokenInterface, IOAuth2AuthCode /** * @param string $redirectUri */ - public function setRedirectUri($redirectUri); + public function setRedirectUri($redirectUri): void; } diff --git a/Model/AuthCodeManagerInterface.php b/Model/AuthCodeManagerInterface.php index 23811b0d..04f22d35 100644 --- a/Model/AuthCodeManagerInterface.php +++ b/Model/AuthCodeManagerInterface.php @@ -35,6 +35,7 @@ public function getClass(); /** * Retrieve an auth code using a set of criteria. * + * @param array $criteria * @return AuthCodeInterface|null */ public function findAuthCodeBy(array $criteria); @@ -51,12 +52,12 @@ public function findAuthCodeByToken($token); /** * Update a given auth code. */ - public function updateAuthCode(AuthCodeInterface $authCode); + public function updateAuthCode(AuthCodeInterface $authCode): void; /** * Delete a given auth code. */ - public function deleteAuthCode(AuthCodeInterface $authCode); + public function deleteAuthCode(AuthCodeInterface $authCode): void; /** * Delete expired auth codes. diff --git a/Model/ClientInterface.php b/Model/ClientInterface.php index c985d847..f817f7f9 100644 --- a/Model/ClientInterface.php +++ b/Model/ClientInterface.php @@ -19,6 +19,7 @@ interface ClientInterface extends IOAuth2Client { /** * @param string $random + * @return void */ public function setRandomId($random); @@ -29,6 +30,7 @@ public function getRandomId(); /** * @param string $secret + * @return void */ public function setSecret($secret); @@ -44,12 +46,20 @@ public function checkSecret($secret); */ public function getSecret(); + /** + * @param array $redirectUris + * @return void + */ public function setRedirectUris(array $redirectUris); + /** + * @param array $grantTypes + * @return void + */ public function setAllowedGrantTypes(array $grantTypes); /** - * @return array + * @return array */ public function getAllowedGrantTypes(); } diff --git a/Model/ClientManagerInterface.php b/Model/ClientManagerInterface.php index 31b3ed38..8b42f2ad 100644 --- a/Model/ClientManagerInterface.php +++ b/Model/ClientManagerInterface.php @@ -26,6 +26,7 @@ public function createClient(); public function getClass(); /** + * @param array $criteria * @return ClientInterface|null */ public function findClientBy(array $criteria); @@ -37,7 +38,13 @@ public function findClientBy(array $criteria); */ public function findClientByPublicId($publicId); + /** + * @return void + */ public function updateClient(ClientInterface $client); + /** + * @return void + */ public function deleteClient(ClientInterface $client); } diff --git a/Model/TokenInterface.php b/Model/TokenInterface.php index 3d32ef23..23a09a8b 100644 --- a/Model/TokenInterface.php +++ b/Model/TokenInterface.php @@ -20,6 +20,7 @@ interface TokenInterface extends IOAuth2Token { /** * @param int $timestamp + * @return void */ public function setExpiresAt($timestamp); @@ -30,14 +31,19 @@ public function getExpiresAt(); /** * @param string $token + * @return void */ public function setToken($token); /** * @param string $scope + * @return void */ public function setScope($scope); + /** + * @return void + */ public function setUser(UserInterface $user); /** @@ -45,5 +51,8 @@ public function setUser(UserInterface $user); */ public function getUser(); + /** + * @return void + */ public function setClient(ClientInterface $client); } diff --git a/Model/TokenManagerInterface.php b/Model/TokenManagerInterface.php index efbd9377..aa4ba35d 100644 --- a/Model/TokenManagerInterface.php +++ b/Model/TokenManagerInterface.php @@ -32,6 +32,7 @@ public function getClass(); /** * Retrieve a token using a set of criteria. * + * @param array $criteria * @return TokenInterface|null */ public function findTokenBy(array $criteria); @@ -49,6 +50,7 @@ public function findTokenByToken($token); * Save or update a given token. * * @param TokenInterface $token the token to save or update + * @return void */ public function updateToken(TokenInterface $token); @@ -56,6 +58,7 @@ public function updateToken(TokenInterface $token); * Delete a given token. * * @param TokenInterface $token the token to delete + * @return void */ public function deleteToken(TokenInterface $token); diff --git a/Propel/AuthCodeManager.php b/Propel/AuthCodeManager.php index a9b8a7fe..3071cbb4 100644 --- a/Propel/AuthCodeManager.php +++ b/Propel/AuthCodeManager.php @@ -59,7 +59,7 @@ public function findAuthCodeBy(array $criteria) /** * {@inheritdoc} */ - public function updateAuthCode(AuthCodeInterface $authCode) + public function updateAuthCode(AuthCodeInterface $authCode): void { $authCode->save(); } @@ -67,7 +67,7 @@ public function updateAuthCode(AuthCodeInterface $authCode) /** * {@inheritdoc} */ - public function deleteAuthCode(AuthCodeInterface $authCode) + public function deleteAuthCode(AuthCodeInterface $authCode): void { $authCode->delete(); } diff --git a/Security/EntryPoint/OAuthEntryPoint.php b/Security/EntryPoint/OAuthEntryPoint.php index 3817ecff..fbb349a9 100644 --- a/Security/EntryPoint/OAuthEntryPoint.php +++ b/Security/EntryPoint/OAuthEntryPoint.php @@ -22,6 +22,9 @@ class OAuthEntryPoint implements AuthenticationEntryPointInterface { + /** + * @var OAuth2 + */ protected $serverService; public function __construct(OAuth2 $serverService) diff --git a/Storage/GrantExtensionDispatcherInterface.php b/Storage/GrantExtensionDispatcherInterface.php index 20794e9f..a993a749 100644 --- a/Storage/GrantExtensionDispatcherInterface.php +++ b/Storage/GrantExtensionDispatcherInterface.php @@ -18,5 +18,8 @@ */ interface GrantExtensionDispatcherInterface { - public function setGrantExtension($uri, GrantExtensionInterface $grantExtension); + /** + * @param string $uri + */ + public function setGrantExtension($uri, GrantExtensionInterface $grantExtension): void; } diff --git a/Storage/OAuthStorage.php b/Storage/OAuthStorage.php index 5ab6b7c9..cabb9bd7 100644 --- a/Storage/OAuthStorage.php +++ b/Storage/OAuthStorage.php @@ -65,7 +65,8 @@ class OAuthStorage implements IOAuth2RefreshTokens, IOAuth2GrantUser, IOAuth2Gra protected $encoderFactory; /** - * @var array [uri] => GrantExtensionInterface + * Map of URIs to grant extensions + * @var array */ protected $grantExtensions; @@ -86,7 +87,7 @@ public function __construct(ClientManagerInterface $clientManager, AccessTokenMa /** * {@inheritdoc} */ - public function setGrantExtension($uri, GrantExtensionInterface $grantExtension) + public function setGrantExtension($uri, GrantExtensionInterface $grantExtension): void { $this->grantExtensions[$uri] = $grantExtension; } @@ -115,6 +116,9 @@ public function getAccessToken($token) return $this->accessTokenManager->findTokenByToken($token); } + /** + * @return \FOS\OAuthServerBundle\Model\TokenInterface + */ public function createAccessToken($tokenString, IOAuth2Client $client, $data, $expires, $scope = null) { if (!$client instanceof ClientInterface) { @@ -177,6 +181,7 @@ public function getAuthCode($code) /** * {@inheritdoc} + * @return \FOS\OAuthServerBundle\Model\AuthCodeInterface */ public function createAuthCode($code, IOAuth2Client $client, $data, $redirect_uri, $expires, $scope = null) { diff --git a/Tests/Command/CleanCommandTest.php b/Tests/Command/CleanCommandTest.php index 2db156c8..214495df 100644 --- a/Tests/Command/CleanCommandTest.php +++ b/Tests/Command/CleanCommandTest.php @@ -27,17 +27,17 @@ class CleanCommandTest extends \PHPUnit\Framework\TestCase private $command; /** - * @var \PHPUnit_Framework_MockObject_MockObject|TokenManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|TokenManagerInterface */ private $accessTokenManager; /** - * @var \PHPUnit_Framework_MockObject_MockObject|TokenManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|TokenManagerInterface */ private $refreshTokenManager; /** - * @var \PHPUnit_Framework_MockObject_MockObject|AuthCodeManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|AuthCodeManagerInterface */ private $authCodeManager; @@ -64,7 +64,7 @@ protected function setUp(): void /** * Delete expired tokens for provided classes. */ - public function testItShouldRemoveExpiredToken() + public function testItShouldRemoveExpiredToken(): void { $expiredAccessTokens = 5; $this->accessTokenManager @@ -100,7 +100,7 @@ public function testItShouldRemoveExpiredToken() /** * Skip classes for deleting expired tokens that do not implement AuthCodeManagerInterface or TokenManagerInterface. */ - public function testItShouldNotRemoveExpiredTokensForOtherClasses() + public function testItShouldNotRemoveExpiredTokensForOtherClasses(): void { $this->markTestIncomplete('Needs a better way of testing this'); diff --git a/Tests/Command/CreateClientCommandTest.php b/Tests/Command/CreateClientCommandTest.php index 9cc738ef..124e09f0 100644 --- a/Tests/Command/CreateClientCommandTest.php +++ b/Tests/Command/CreateClientCommandTest.php @@ -27,7 +27,7 @@ class CreateClientCommandTest extends TestCase private $command; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ClientManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|ClientManagerInterface */ private $clientManager; @@ -53,7 +53,7 @@ protected function setUp(): void * * @param string $client a fully qualified class name */ - public function testItShouldCreateClient($client) + public function testItShouldCreateClient($client): void { $this ->clientManager diff --git a/Tests/Controller/AuthorizeControllerTest.php b/Tests/Controller/AuthorizeControllerTest.php index 37b0b898..04d2319a 100644 --- a/Tests/Controller/AuthorizeControllerTest.php +++ b/Tests/Controller/AuthorizeControllerTest.php @@ -38,52 +38,52 @@ class AuthorizeControllerTest extends \PHPUnit\Framework\TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|RequestStack + * @var \PHPUnit\Framework\MockObject\MockObject|RequestStack */ protected $requestStack; /** - * @var \PHPUnit_Framework_MockObject_MockObject|SessionInterface + * @var \PHPUnit\Framework\MockObject\MockObject|SessionInterface */ protected $session; /** - * @var \PHPUnit_Framework_MockObject_MockObject|Form + * @var \PHPUnit\Framework\MockObject\MockObject|Form */ protected $form; /** - * @var \PHPUnit_Framework_MockObject_MockObject|AuthorizeFormHandler + * @var \PHPUnit\Framework\MockObject\MockObject|AuthorizeFormHandler */ protected $authorizeFormHandler; /** - * @var \PHPUnit_Framework_MockObject_MockObject|OAuth2 + * @var \PHPUnit\Framework\MockObject\MockObject|OAuth2 */ protected $oAuth2Server; /** - * @var \PHPUnit_Framework_MockObject_MockObject|TokenStorageInterface + * @var \PHPUnit\Framework\MockObject\MockObject|TokenStorageInterface */ protected $tokenStorage; /** - * @var \PHPUnit_Framework_MockObject_MockObject|TwigEnvironment + * @var \PHPUnit\Framework\MockObject\MockObject|TwigEnvironment */ protected $twig; /** - * @var \PHPUnit_Framework_MockObject_MockObject|UrlGeneratorInterface + * @var \PHPUnit\Framework\MockObject\MockObject|UrlGeneratorInterface */ protected $router; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ClientManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|ClientManagerInterface */ protected $clientManager; /** - * @var \PHPUnit_Framework_MockObject_MockObject|EventDispatcherInterface + * @var \PHPUnit\Framework\MockObject\MockObject|EventDispatcherInterface */ protected $eventDispatcher; @@ -93,46 +93,46 @@ class AuthorizeControllerTest extends \PHPUnit\Framework\TestCase protected $instance; /** - * @var \PHPUnit_Framework_MockObject_MockObject|Request + * @var \PHPUnit\Framework\MockObject\MockObject|Request */ protected $request; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ParameterBag + * @var \PHPUnit\Framework\MockObject\MockObject|ParameterBag */ protected $requestQuery; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ParameterBag + * @var \PHPUnit\Framework\MockObject\MockObject|ParameterBag */ protected $requestRequest; /** - * @var \PHPUnit_Framework_MockObject_MockObject|UserInterface + * @var \PHPUnit\Framework\MockObject\MockObject|UserInterface */ protected $user; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ClientInterface + * @var \PHPUnit\Framework\MockObject\MockObject|ClientInterface */ protected $client; /** - * @var \PHPUnit_Framework_MockObject_MockObject|PreAuthorizationEvent + * @var \PHPUnit\Framework\MockObject\MockObject|PreAuthorizationEvent */ protected $preAuthorizationEvent; /** - * @var \PHPUnit_Framework_MockObject_MockObject|PostAuthorizationEvent + * @var \PHPUnit\Framework\MockObject\MockObject|PostAuthorizationEvent */ protected $postAuthorizationEvent; /** - * @var \PHPUnit_Framework_MockObject_MockObject|FormView + * @var \PHPUnit\Framework\MockObject\MockObject|FormView */ protected $formView; - public function setUp() + public function setUp(): void { $this->requestStack = $this->getMockBuilder(RequestStack::class) ->disableOriginalConstructor() @@ -188,7 +188,7 @@ public function setUp() $this->session ); - /** @var \PHPUnit_Framework_MockObject_MockObject&Request $request */ + /** @var \PHPUnit\Framework\MockObject\MockObject&Request $request */ $request = $this->getMockBuilder(Request::class) ->disableOriginalConstructor() ->getMock() @@ -228,7 +228,7 @@ public function setUp() parent::setUp(); } - public function testAuthorizeActionWillThrowAccessDeniedException() + public function testAuthorizeActionWillThrowAccessDeniedException(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -253,7 +253,7 @@ public function testAuthorizeActionWillThrowAccessDeniedException() $this->instance->authorizeAction($this->request); } - public function testAuthorizeActionWillRenderTemplate() + public function testAuthorizeActionWillRenderTemplate(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -325,7 +325,7 @@ public function testAuthorizeActionWillRenderTemplate() $this->assertSame($responseBody, $this->instance->authorizeAction($this->request)->getContent()); } - public function testAuthorizeActionWillFinishClientAuthorization() + public function testAuthorizeActionWillFinishClientAuthorization(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -394,7 +394,7 @@ public function testAuthorizeActionWillFinishClientAuthorization() $this->assertSame($response, $this->instance->authorizeAction($this->request)); } - public function testAuthorizeActionWillEnsureLogout() + public function testAuthorizeActionWillEnsureLogout(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -480,7 +480,7 @@ public function testAuthorizeActionWillEnsureLogout() $this->assertSame($responseBody, $this->instance->authorizeAction($this->request)->getContent()); } - public function testAuthorizeActionWillProcessAuthorizationForm() + public function testAuthorizeActionWillProcessAuthorizationForm(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() diff --git a/Tests/DependencyInjection/Compiler/GrantExtensionsCompilerPassTest.php b/Tests/DependencyInjection/Compiler/GrantExtensionsCompilerPassTest.php index fee8584b..81ab02d2 100644 --- a/Tests/DependencyInjection/Compiler/GrantExtensionsCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/GrantExtensionsCompilerPassTest.php @@ -33,14 +33,14 @@ class GrantExtensionsCompilerPassTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { $this->instance = new GrantExtensionsCompilerPass(); parent::setUp(); } - public function testProcessWillNotDoAnythingIfTheStorageDoesNotImplementOurInterface() + public function testProcessWillNotDoAnythingIfTheStorageDoesNotImplementOurInterface(): void { $container = $this->getMockBuilder(ContainerBuilder::class) ->disableOriginalConstructor() @@ -93,7 +93,7 @@ public function testProcessWillNotDoAnythingIfTheStorageDoesNotImplementOurInter $this->assertNull($this->instance->process($container)); } - public function testProcessWillFailIfUriIsEmpty() + public function testProcessWillFailIfUriIsEmpty(): void { $container = $this->getMockBuilder(ContainerBuilder::class) ->disableOriginalConstructor() @@ -197,7 +197,7 @@ public function testProcessWillFailIfUriIsEmpty() $this->assertNull($this->instance->process($container)); } - public function testProcess() + public function testProcess(): void { $container = $this->getMockBuilder(ContainerBuilder::class) ->disableOriginalConstructor() diff --git a/Tests/DependencyInjection/Compiler/RequestStackCompilerPassTest.php b/Tests/DependencyInjection/Compiler/RequestStackCompilerPassTest.php index b471fcc7..90e8da12 100644 --- a/Tests/DependencyInjection/Compiler/RequestStackCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/RequestStackCompilerPassTest.php @@ -31,11 +31,11 @@ class RequestStackCompilerPassTest extends \PHPUnit\Framework\TestCase protected $instance; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder + * @var \PHPUnit\Framework\MockObject\MockObject|ContainerBuilder */ protected $container; - public function setUp() + public function setUp(): void { $this->container = $this->getMockBuilder(ContainerBuilder::class) ->disableOriginalConstructor() @@ -51,7 +51,7 @@ public function setUp() parent::setUp(); } - public function testProcessWithoutRequestStackDoesNothing() + public function testProcessWithoutRequestStackDoesNothing(): void { $this->container ->expects($this->once()) @@ -63,7 +63,7 @@ public function testProcessWithoutRequestStackDoesNothing() $this->assertNull($this->instance->process($this->container)); } - public function testProcess() + public function testProcess(): void { $this->container ->expects($this->once()) diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 0c072192..52fb2607 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -20,14 +20,14 @@ class ConfigurationTest extends \PHPUnit\Framework\TestCase { - public function testShouldImplementConfigurationInterface() + public function testShouldImplementConfigurationInterface(): void { $rc = new \ReflectionClass(Configuration::class); $this->assertTrue($rc->implementsInterface(ConfigurationInterface::class)); } - public function testCouldBeConstructedWithoutAnyArguments() + public function testCouldBeConstructedWithoutAnyArguments(): void { try { new Configuration(); @@ -39,7 +39,7 @@ public function testCouldBeConstructedWithoutAnyArguments() } } - public function testShouldNotMandatoryServiceIfNotCustomDriverIsUsed() + public function testShouldNotMandatoryServiceIfNotCustomDriverIsUsed(): void { $configuration = new Configuration(); $processor = new Processor(); @@ -69,7 +69,7 @@ public function testShouldNotMandatoryServiceIfNotCustomDriverIsUsed() ], $config); } - public function testShouldMakeClientManagerServiceMandatoryIfCustomDriverIsUsed() + public function testShouldMakeClientManagerServiceMandatoryIfCustomDriverIsUsed(): void { $configuration = new Configuration(); $processor = new Processor(); @@ -86,7 +86,7 @@ public function testShouldMakeClientManagerServiceMandatoryIfCustomDriverIsUsed( ]]); } - public function testShouldMakeAccessTokenManagerServiceMandatoryIfCustomDriverIsUsed() + public function testShouldMakeAccessTokenManagerServiceMandatoryIfCustomDriverIsUsed(): void { $configuration = new Configuration(); $processor = new Processor(); @@ -106,7 +106,7 @@ public function testShouldMakeAccessTokenManagerServiceMandatoryIfCustomDriverIs ]]); } - public function testShouldMakeRefreshTokenManagerServiceMandatoryIfCustomDriverIsUsed() + public function testShouldMakeRefreshTokenManagerServiceMandatoryIfCustomDriverIsUsed(): void { $configuration = new Configuration(); $processor = new Processor(); @@ -127,7 +127,7 @@ public function testShouldMakeRefreshTokenManagerServiceMandatoryIfCustomDriverI ]]); } - public function testShouldMakeAuthCodeManagerServiceMandatoryIfCustomDriverIsUsed() + public function testShouldMakeAuthCodeManagerServiceMandatoryIfCustomDriverIsUsed(): void { $configuration = new Configuration(); $processor = new Processor(); @@ -149,7 +149,7 @@ public function testShouldMakeAuthCodeManagerServiceMandatoryIfCustomDriverIsUse ]]); } - public function testShouldLoadCustomDriverConfig() + public function testShouldLoadCustomDriverConfig(): void { $configuration = new Configuration(); $processor = new Processor(); diff --git a/Tests/DependencyInjection/FOSOAuthServerExtensionTest.php b/Tests/DependencyInjection/FOSOAuthServerExtensionTest.php index 4ffc09f7..945df62e 100644 --- a/Tests/DependencyInjection/FOSOAuthServerExtensionTest.php +++ b/Tests/DependencyInjection/FOSOAuthServerExtensionTest.php @@ -23,9 +23,12 @@ class FOSOAuthServerExtensionTest extends \PHPUnit\Framework\TestCase { + /** + * @var ContainerBuilder + */ private $container; - public function setUp() + public function setUp(): void { $parameterBag = new ParameterBag(); $this->container = new ContainerBuilder($parameterBag); @@ -33,14 +36,14 @@ public function setUp() parent::setUp(); } - public function testShouldImplementConfigurationInterface() + public function testShouldImplementConfigurationInterface(): void { $rc = new \ReflectionClass(FOSOAuthServerExtension::class); $this->assertTrue($rc->isSubclassOf(Extension::class)); } - public function testCouldBeConstructedWithoutAnyArguments() + public function testCouldBeConstructedWithoutAnyArguments(): void { try { new FOSOAuthServerExtension(); @@ -52,7 +55,7 @@ public function testCouldBeConstructedWithoutAnyArguments() } } - public function testShouldLoadAuthorizeRelatedServicesIfAuthorizationIsEnabled() + public function testShouldLoadAuthorizeRelatedServicesIfAuthorizationIsEnabled(): void { $container = new ContainerBuilder(); @@ -72,7 +75,7 @@ public function testShouldLoadAuthorizeRelatedServicesIfAuthorizationIsEnabled() $this->assertTrue($container->hasDefinition('fos_oauth_server.controller.authorize')); } - public function testShouldNotLoadAuthorizeRelatedServicesIfAuthorizationIsDisabled() + public function testShouldNotLoadAuthorizeRelatedServicesIfAuthorizationIsDisabled(): void { $container = new ContainerBuilder(); @@ -92,7 +95,7 @@ public function testShouldNotLoadAuthorizeRelatedServicesIfAuthorizationIsDisabl $this->assertFalse($container->hasDefinition('fos_oauth_server.controller.authorize')); } - public function testLoadAuthorizeRouting() + public function testLoadAuthorizeRouting(): void { $locator = new FileLocator(); $loader = new XmlFileLoader($locator); @@ -103,7 +106,7 @@ public function testLoadAuthorizeRouting() $this->assertSame(['GET', 'POST'], $authorizeRoute->getMethods()); } - public function testLoadTokenRouting() + public function testLoadTokenRouting(): void { $locator = new FileLocator(); $loader = new XmlFileLoader($locator); @@ -114,7 +117,7 @@ public function testLoadTokenRouting() $this->assertSame(['GET', 'POST'], $tokenRoute->getMethods()); } - public function testWithoutService() + public function testWithoutService(): void { $config = [ 'db_driver' => 'orm', @@ -132,7 +135,7 @@ public function testWithoutService() ); } - public function testStringSupportedScopes() + public function testStringSupportedScopes(): void { $scopes = 'scope1 scope2 scope3 scope4'; @@ -160,7 +163,7 @@ public function testStringSupportedScopes() ); } - public function testArraySupportedScopes() + public function testArraySupportedScopes(): void { $scopes = ['scope1', 'scope2', 'scope3', 'scope4']; @@ -189,7 +192,7 @@ public function testArraySupportedScopes() ); } - public function testArraySupportedScopesWithSpace() + public function testArraySupportedScopesWithSpace(): void { $scopes = ['scope1 scope2', 'scope3', 'scope4']; @@ -213,7 +216,7 @@ public function testArraySupportedScopesWithSpace() $instance->load([$config], $this->container); } - public function testShouldAliasServivesWhenCustomDriverIsUsed() + public function testShouldAliasServivesWhenCustomDriverIsUsed(): void { $container = new ContainerBuilder(); $extension = new FOSOAuthServerExtension(); diff --git a/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php b/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php index 1d8e02d3..301e1712 100644 --- a/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php +++ b/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php @@ -32,24 +32,24 @@ class OAuthFactoryTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { $this->instance = new OAuthFactory(); parent::setUp(); } - public function testGetPosition() + public function testGetPosition(): void { $this->assertSame('pre_auth', $this->instance->getPosition()); } - public function testGetKey() + public function testGetKey(): void { $this->assertSame('fos_oauth', $this->instance->getKey()); } - public function testCreate() + public function testCreate(): void { $container = $this->getMockBuilder(ContainerBuilder::class) ->disableOriginalConstructor() @@ -113,7 +113,7 @@ public function testCreate() ], $this->instance->create($container, $id, $config, $userProvider, $defaultEntryPoint)); } - public function testAddConfigurationDoesNothing() + public function testAddConfigurationDoesNothing(): void { $nodeDefinition = $this->getMockBuilder(NodeDefinition::class) ->disableOriginalConstructor() diff --git a/Tests/Document/AuthCodeManagerTest.php b/Tests/Document/AuthCodeManagerTest.php index f3a86281..68c5a6b2 100644 --- a/Tests/Document/AuthCodeManagerTest.php +++ b/Tests/Document/AuthCodeManagerTest.php @@ -30,12 +30,12 @@ class AuthCodeManagerTest extends \PHPUnit\Framework\TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|DocumentManager + * @var \PHPUnit\Framework\MockObject\MockObject|DocumentManager */ protected $documentManager; /** - * @var \PHPUnit_Framework_MockObject_MockObject|DocumentRepository + * @var \PHPUnit\Framework\MockObject\MockObject|DocumentRepository */ protected $repository; @@ -49,7 +49,7 @@ class AuthCodeManagerTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { if (!class_exists('\Doctrine\ODM\MongoDB\DocumentManager')) { $this->markTestSkipped('Doctrine MongoDB ODM has to be installed for this test to run.'); @@ -77,18 +77,18 @@ public function setUp() parent::setUp(); } - public function testConstructWillSetParameters() + public function testConstructWillSetParameters(): void { $this->assertAttributeSame($this->documentManager, 'dm', $this->instance); $this->assertAttributeSame($this->className, 'class', $this->instance); } - public function testGetClassWillReturnClassName() + public function testGetClassWillReturnClassName(): void { $this->assertSame($this->className, $this->instance->getClass()); } - public function testFindAuthCodeBy() + public function testFindAuthCodeBy(): void { $randomResult = \random_bytes(10); $criteria = [ @@ -105,7 +105,7 @@ public function testFindAuthCodeBy() $this->assertSame($randomResult, $this->instance->findAuthCodeBy($criteria)); } - public function testUpdateAuthCode() + public function testUpdateAuthCode(): void { $authCode = $this->getMockBuilder(AuthCodeInterface::class) ->disableOriginalConstructor() @@ -129,7 +129,7 @@ public function testUpdateAuthCode() $this->assertNull($this->instance->updateAuthCode($authCode)); } - public function testDeleteAuthCode() + public function testDeleteAuthCode(): void { $authCode = $this->getMockBuilder(AuthCodeInterface::class) ->disableOriginalConstructor() @@ -153,7 +153,7 @@ public function testDeleteAuthCode() $this->assertNull($this->instance->deleteAuthCode($authCode)); } - public function testDeleteExpired() + public function testDeleteExpired(): void { $queryBuilder = $this->getMockBuilder(Builder::class) ->disableOriginalConstructor() diff --git a/Tests/Document/ClientManagerTest.php b/Tests/Document/ClientManagerTest.php index 4af23fc8..1bf8bcf4 100644 --- a/Tests/Document/ClientManagerTest.php +++ b/Tests/Document/ClientManagerTest.php @@ -26,7 +26,7 @@ class ClientManagerTest extends \PHPUnit\Framework\TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|DocumentManager + * @var \PHPUnit\Framework\MockObject\MockObject|DocumentManager */ protected $documentManager; @@ -36,7 +36,7 @@ class ClientManagerTest extends \PHPUnit\Framework\TestCase protected $className; /** - * @var \PHPUnit_Framework_MockObject_MockObject|DocumentRepository + * @var \PHPUnit\Framework\MockObject\MockObject|DocumentRepository */ protected $repository; @@ -45,7 +45,7 @@ class ClientManagerTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { if (!class_exists('\Doctrine\ODM\MongoDB\DocumentManager')) { $this->markTestSkipped('Doctrine MongoDB ODM has to be installed for this test to run.'); @@ -73,19 +73,19 @@ public function setUp() 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); } - public function testGetClass() + public function testGetClass(): void { $this->assertSame($this->className, $this->instance->getClass()); } - public function testFindClientBy() + public function testFindClientBy(): void { $randomResult = \random_bytes(5); $criteria = [ @@ -102,7 +102,7 @@ public function testFindClientBy() $this->assertSame($randomResult, $this->instance->findClientBy($criteria)); } - public function testUpdateClient() + public function testUpdateClient(): void { $client = $this->getMockBuilder(ClientInterface::class) ->disableOriginalConstructor() @@ -126,7 +126,7 @@ public function testUpdateClient() $this->assertNull($this->instance->updateClient($client)); } - public function testDeleteClient() + public function testDeleteClient(): void { $client = $this->getMockBuilder(ClientInterface::class) ->disableOriginalConstructor() diff --git a/Tests/Document/TokenManagerTest.php b/Tests/Document/TokenManagerTest.php index ff166d34..a2c93372 100644 --- a/Tests/Document/TokenManagerTest.php +++ b/Tests/Document/TokenManagerTest.php @@ -35,12 +35,12 @@ class TokenManagerTest extends \PHPUnit\Framework\TestCase protected $className; /** - * @var \PHPUnit_Framework_MockObject_MockObject|DocumentManager + * @var \PHPUnit\Framework\MockObject\MockObject|DocumentManager */ protected $documentManager; /** - * @var \PHPUnit_Framework_MockObject_MockObject|DocumentRepository + * @var \PHPUnit\Framework\MockObject\MockObject|DocumentRepository */ protected $repository; @@ -49,7 +49,7 @@ class TokenManagerTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { if (!class_exists('\Doctrine\ODM\MongoDB\DocumentManager')) { $this->markTestSkipped('Doctrine MongoDB ODM has to be installed for this test to run.'); @@ -75,7 +75,7 @@ public function setUp() $this->instance = new TokenManager($this->documentManager, $this->className); } - public function testFindTokenByToken() + public function testFindTokenByToken(): void { $randomToken = \random_bytes(5); $randomResult = \random_bytes(5); @@ -92,7 +92,7 @@ public function testFindTokenByToken() $this->assertSame($randomResult, $this->instance->findTokenByToken($randomToken)); } - public function testUpdateTokenPersistsAndFlushes() + public function testUpdateTokenPersistsAndFlushes(): void { $token = $this->getMockBuilder(AccessToken::class) ->disableOriginalConstructor() @@ -114,12 +114,12 @@ public function testUpdateTokenPersistsAndFlushes() $this->assertNull($this->instance->updateToken($token)); } - public function testGetClass() + public function testGetClass(): void { $this->assertSame($this->className, $this->instance->getClass()); } - public function testDeleteToken() + public function testDeleteToken(): void { $token = $this->getMockBuilder(AccessToken::class) ->disableOriginalConstructor() @@ -143,7 +143,7 @@ public function testDeleteToken() $this->assertNull($this->instance->deleteToken($token)); } - public function testDeleteExpired() + public function testDeleteExpired(): void { $queryBuilder = $this->getMockBuilder(Builder::class) ->disableOriginalConstructor() diff --git a/Tests/Entity/AuthCodeManagerTest.php b/Tests/Entity/AuthCodeManagerTest.php index ccdd9409..eedacf70 100644 --- a/Tests/Entity/AuthCodeManagerTest.php +++ b/Tests/Entity/AuthCodeManagerTest.php @@ -31,7 +31,7 @@ class AuthCodeManagerTest extends \PHPUnit\Framework\TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface */ protected $entityManager; @@ -45,7 +45,7 @@ class AuthCodeManagerTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class) ->disableOriginalConstructor() @@ -58,18 +58,18 @@ public function setUp() parent::setUp(); } - public function testConstructWillSetParameters() + public function testConstructWillSetParameters(): void { $this->assertAttributeSame($this->entityManager, 'em', $this->instance); $this->assertAttributeSame($this->className, 'class', $this->instance); } - public function testGetClassWillReturnClassName() + public function testGetClassWillReturnClassName(): void { $this->assertSame($this->className, $this->instance->getClass()); } - public function testFindAuthCodeBy() + public function testFindAuthCodeBy(): void { $repository = $this->getMockBuilder(ObjectRepository::class) ->disableOriginalConstructor() @@ -98,7 +98,7 @@ public function testFindAuthCodeBy() $this->assertSame($randomResult, $this->instance->findAuthCodeBy($criteria)); } - public function testUpdateAuthCode() + public function testUpdateAuthCode(): void { $authCode = $this->getMockBuilder(AuthCodeInterface::class) ->disableOriginalConstructor() @@ -122,7 +122,7 @@ public function testUpdateAuthCode() $this->assertNull($this->instance->updateAuthCode($authCode)); } - public function testDeleteAuthCode() + public function testDeleteAuthCode(): void { $authCode = $this->getMockBuilder(AuthCodeInterface::class) ->disableOriginalConstructor() @@ -146,7 +146,7 @@ public function testDeleteAuthCode() $this->assertNull($this->instance->deleteAuthCode($authCode)); } - public function testDeleteExpired() + public function testDeleteExpired(): void { $randomResult = \random_bytes(10); diff --git a/Tests/Entity/ClientManagerTest.php b/Tests/Entity/ClientManagerTest.php index d575d320..e4958aa7 100644 --- a/Tests/Entity/ClientManagerTest.php +++ b/Tests/Entity/ClientManagerTest.php @@ -26,7 +26,7 @@ class ClientManagerTest extends \PHPUnit\Framework\TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface */ protected $entityManager; @@ -36,7 +36,7 @@ class ClientManagerTest extends \PHPUnit\Framework\TestCase protected $className; /** - * @var \PHPUnit_Framework_MockObject_MockObject|EntityRepository + * @var \PHPUnit\Framework\MockObject\MockObject|EntityRepository */ protected $repository; @@ -45,7 +45,7 @@ class ClientManagerTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class) ->disableOriginalConstructor() @@ -69,19 +69,19 @@ public function setUp() 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); } - public function testGetClass() + public function testGetClass(): void { $this->assertSame($this->className, $this->instance->getClass()); } - public function testFindClientBy() + public function testFindClientBy(): void { $criteria = [ \random_bytes(5), @@ -98,7 +98,7 @@ public function testFindClientBy() $this->assertSame($randomResult, $this->instance->findClientBy($criteria)); } - public function testUpdateClient() + public function testUpdateClient(): void { $client = $this->getMockBuilder(ClientInterface::class) ->disableOriginalConstructor() @@ -122,7 +122,7 @@ public function testUpdateClient() $this->assertNull($this->instance->updateClient($client)); } - public function testDeleteClient() + public function testDeleteClient(): void { $client = $this->getMockBuilder(ClientInterface::class) ->disableOriginalConstructor() diff --git a/Tests/Entity/TokenManagerTest.php b/Tests/Entity/TokenManagerTest.php index acdeca16..1cc2d834 100644 --- a/Tests/Entity/TokenManagerTest.php +++ b/Tests/Entity/TokenManagerTest.php @@ -32,12 +32,12 @@ class TokenManagerTest extends \PHPUnit\Framework\TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface */ protected $entityManager; /** - * @var \PHPUnit_Framework_MockObject_MockObject|EntityRepository + * @var \PHPUnit\Framework\MockObject\MockObject|EntityRepository */ protected $repository; @@ -51,7 +51,7 @@ class TokenManagerTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { $this->className = AccessToken::class; $this->repository = $this->getMockBuilder(EntityRepository::class) @@ -73,14 +73,14 @@ public function setUp() $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); } - public function testUpdateTokenPersistsAndFlushes() + public function testUpdateTokenPersistsAndFlushes(): void { $token = new AccessToken(); @@ -99,12 +99,12 @@ public function testUpdateTokenPersistsAndFlushes() $this->assertNull($this->instance->updateToken($token)); } - public function testGetClass() + public function testGetClass(): void { $this->assertSame($this->className, $this->instance->getClass()); } - public function testFindTokenBy() + public function testFindTokenBy(): void { $randomResult = \random_bytes(5); @@ -122,7 +122,7 @@ public function testFindTokenBy() $this->assertSame($randomResult, $this->instance->findTokenBy($criteria)); } - public function testUpdateToken() + public function testUpdateToken(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -146,7 +146,7 @@ public function testUpdateToken() $this->assertNull($this->instance->updateToken($token)); } - public function testDeleteToken() + public function testDeleteToken(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -170,7 +170,7 @@ public function testDeleteToken() $this->assertNull($this->instance->deleteToken($token)); } - public function testDeleteExpired() + public function testDeleteExpired(): void { $randomResult = \random_bytes(10); diff --git a/Tests/FOSOAuthServerBundleTest.php b/Tests/FOSOAuthServerBundleTest.php index 16482cf9..ba6bb025 100644 --- a/Tests/FOSOAuthServerBundleTest.php +++ b/Tests/FOSOAuthServerBundleTest.php @@ -26,11 +26,11 @@ protected function setUp(): void parent::setUp(); } - public function testConstruction() + public function testConstruction(): void { $bundle = new FOSOAuthServerBundle(); - /** @var ContainerBuilder|\PHPUnit_Framework_MockObject_MockObject $containerBuilder */ + /** @var ContainerBuilder|\PHPUnit\Framework\MockObject\MockObject $containerBuilder */ $containerBuilder = $this->getMockBuilder(ContainerBuilder::class) ->disableOriginalConstructor() ->setMethods([ @@ -40,7 +40,7 @@ public function testConstruction() ->getMock() ; - /** @var SecurityExtension|\PHPUnit_Framework_MockObject_MockObject $securityExtension */ + /** @var SecurityExtension|\PHPUnit\Framework\MockObject\MockObject $securityExtension */ $securityExtension = $this->getMockBuilder(SecurityExtension::class) ->disableOriginalConstructor() ->getMock() diff --git a/Tests/Form/Handler/AuthorizeFormHandlerTest.php b/Tests/Form/Handler/AuthorizeFormHandlerTest.php index dffb6161..dd211252 100644 --- a/Tests/Form/Handler/AuthorizeFormHandlerTest.php +++ b/Tests/Form/Handler/AuthorizeFormHandlerTest.php @@ -29,14 +29,25 @@ */ class AuthorizeFormHandlerTest extends \PHPUnit\Framework\TestCase { + /** + * @var FormInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected $form; - + /** + * @var Request&\PHPUnit\Framework\MockObject\MockObject + */ protected $request; - + /** + * @var ParameterBag&\PHPUnit\Framework\MockObject\MockObject + */ protected $requestQuery; - + /** + * @var ParameterBag&\PHPUnit\Framework\MockObject\MockObject + */ protected $requestRequest; - + /** + * @var ContainerInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected $container; /** @@ -44,7 +55,7 @@ class AuthorizeFormHandlerTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { $this->form = $this->getMockBuilder(FormInterface::class) ->disableOriginalConstructor() @@ -78,7 +89,7 @@ public function setUp() parent::setUp(); } - public function testConstructWillAcceptRequestObjectAsRequest() + public function testConstructWillAcceptRequestObjectAsRequest(): void { $request = $this->getMockBuilder(Request::class) ->disableOriginalConstructor() @@ -91,7 +102,7 @@ public function testConstructWillAcceptRequestObjectAsRequest() $this->assertAttributeSame($request, 'requestStack', $this->instance); } - public function testConstructWillAcceptRequestStackObjectAsRequest() + public function testConstructWillAcceptRequestStackObjectAsRequest(): void { $requestStack = $this->getMockBuilder(RequestStack::class) ->disableOriginalConstructor() @@ -104,7 +115,7 @@ public function testConstructWillAcceptRequestStackObjectAsRequest() $this->assertAttributeSame($requestStack, 'requestStack', $this->instance); } - public function testConstructWillAcceptNullAsRequest() + public function testConstructWillAcceptNullAsRequest(): void { $this->instance = new AuthorizeFormHandler($this->form, null); $this->assertAttributeSame($this->form, 'form', $this->instance); @@ -115,7 +126,7 @@ public function testConstructWillAcceptNullAsRequest() $this->assertAttributeSame(null, 'requestStack', $this->instance); } - public function testConstructWillThrowException() + public function testConstructWillThrowException(): void { $exceptionMessage = sprintf( 'Argument 2 of %s must be an instanceof RequestStack or Request', @@ -128,7 +139,7 @@ public function testConstructWillThrowException() new AuthorizeFormHandler($this->form, new \stdClass()); } - public function testIsAcceptedWillProxyValueToFormData() + public function testIsAcceptedWillProxyValueToFormData(): void { $data = new \stdClass(); $data->accepted = \random_bytes(10); @@ -143,7 +154,7 @@ public function testIsAcceptedWillProxyValueToFormData() $this->assertSame($data->accepted, $this->instance->isAccepted()); } - public function testIsRejectedWillNegateAcceptedValueFromFormData() + public function testIsRejectedWillNegateAcceptedValueFromFormData(): void { $dataWithAcceptedValueFalse = new \stdClass(); $dataWithAcceptedValueFalse->accepted = false; @@ -164,7 +175,7 @@ public function testIsRejectedWillNegateAcceptedValueFromFormData() $this->assertFalse($this->instance->isRejected()); } - public function testGetScopeWillProxyValueToFormData() + public function testGetScopeWillProxyValueToFormData(): void { $data = new \stdClass(); $data->scope = \random_bytes(10); @@ -179,13 +190,13 @@ public function testGetScopeWillProxyValueToFormData() $this->assertSame($data->scope, $this->instance->getScope()); } - public function testGetCurrentRequestWillReturnRequestObject() + public function testGetCurrentRequestWillReturnRequestObject(): void { $method = $this->getReflectionMethod('getCurrentRequest'); $this->assertSame($this->request, $method->invoke($this->instance)); } - public function testGetCurrentRequestWillReturnCurrentRequestFromRequestStack() + public function testGetCurrentRequestWillReturnCurrentRequestFromRequestStack(): void { $requestStack = $this->getMockBuilder(RequestStack::class) ->disableOriginalConstructor() @@ -206,7 +217,7 @@ public function testGetCurrentRequestWillReturnCurrentRequestFromRequestStack() $this->assertSame($request, $method->invoke($this->instance)); } - public function testGetCurrentRequestWillReturnRequestServiceFromContainerIfNoneIsSet() + public function testGetCurrentRequestWillReturnRequestServiceFromContainerIfNoneIsSet(): void { $this->instance = new AuthorizeFormHandler($this->form, null); $this->instance->setContainer($this->container); @@ -227,7 +238,7 @@ public function testGetCurrentRequestWillReturnRequestServiceFromContainerIfNone /** * @TODO Fix this behavior. This method MUST not modify $_GET. */ - public function testOnSuccessWillReplaceGETSuperGlobal() + public function testOnSuccessWillReplaceGETSuperGlobal(): void { $method = $this->getReflectionMethod('onSuccess'); @@ -260,7 +271,7 @@ public function testOnSuccessWillReplaceGETSuperGlobal() $this->assertSame($expectedSuperGlobalValue, $_GET); } - public function testProcessWillReturnFalseIfRequestIsNull() + public function testProcessWillReturnFalseIfRequestIsNull(): void { $this->instance = new AuthorizeFormHandler($this->form, null); $this->instance->setContainer($this->container); @@ -275,7 +286,7 @@ public function testProcessWillReturnFalseIfRequestIsNull() $this->assertFalse($this->instance->process()); } - public function testProcessWillSetFormData() + public function testProcessWillSetFormData(): void { $this->requestRequest ->expects($this->once()) @@ -309,7 +320,7 @@ public function testProcessWillSetFormData() $this->assertFalse($this->instance->process()); } - public function testProcessWillHandleRequestOnPost() + public function testProcessWillHandleRequestOnPost(): void { $this->requestRequest ->expects($this->once()) @@ -371,7 +382,7 @@ public function testProcessWillHandleRequestOnPost() $this->assertFalse($this->instance->process()); } - public function testProcessWillHandleRequestOnPostAndWillProcessDataIfFormIsValid() + public function testProcessWillHandleRequestOnPostAndWillProcessDataIfFormIsValid(): void { $this->requestRequest ->expects($this->once()) diff --git a/Tests/Form/Type/AuthorizeFormTypeTest.php b/Tests/Form/Type/AuthorizeFormTypeTest.php index 2ff1e089..74185fbd 100644 --- a/Tests/Form/Type/AuthorizeFormTypeTest.php +++ b/Tests/Form/Type/AuthorizeFormTypeTest.php @@ -41,7 +41,7 @@ protected function setUp(): void $this->instance = new AuthorizeFormType(); } - public function testSubmit() + public function testSubmit(): void { $accepted = true; $formData = [ @@ -70,9 +70,9 @@ public function testSubmit() } } - public function testConfigureOptionsWillSetDefaultsOnTheOptionsResolver() + public function testConfigureOptionsWillSetDefaultsOnTheOptionsResolver(): void { - /** @var \PHPUnit_Framework_MockObject_MockObject|OptionsResolver $resolver */ + /** @var \PHPUnit\Framework\MockObject\MockObject|OptionsResolver $resolver */ $resolver = $this->getMockBuilder(OptionsResolver::class) ->disableOriginalConstructor() ->getMock() @@ -90,16 +90,19 @@ 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()); } - public function testGetBlockPrefix() + public function testGetBlockPrefix(): void { $this->assertSame('fos_oauth_server_authorize', $this->instance->getBlockPrefix()); } + /** + * @return array + */ protected function getTypes() { return [ diff --git a/Tests/Functional/AppKernel.php b/Tests/Functional/AppKernel.php index e97ffc18..bca57e59 100644 --- a/Tests/Functional/AppKernel.php +++ b/Tests/Functional/AppKernel.php @@ -41,7 +41,7 @@ public function getCacheDir() return sys_get_temp_dir().'/FOSOAuthServerBundle/'; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); } diff --git a/Tests/Functional/BootTest.php b/Tests/Functional/BootTest.php index 331f88c0..393c5bd9 100644 --- a/Tests/Functional/BootTest.php +++ b/Tests/Functional/BootTest.php @@ -20,7 +20,7 @@ class BootTest extends TestCase * * @param string $env */ - public function testBoot($env) + public function testBoot($env): void { try { $kernel = static::createKernel(['env' => $env]); @@ -33,6 +33,9 @@ public function testBoot($env) } } + /** + * @return array + */ public function getTestBootData() { return [ diff --git a/Tests/Functional/TestBundle/Entity/User.php b/Tests/Functional/TestBundle/Entity/User.php index 61363bec..edbe343d 100644 --- a/Tests/Functional/TestBundle/Entity/User.php +++ b/Tests/Functional/TestBundle/Entity/User.php @@ -25,15 +25,17 @@ class User implements UserInterface * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") + * @var ?int */ protected $id; /** * @ORM\Column(type="string") + * @var ?string */ protected $password; - public function getId() + public function getId(): ?int { return $this->id; } @@ -43,18 +45,19 @@ public function getRoles() return ['ROLE_USER']; } - public function getPassword() + public function getPassword(): ?string { return $this->password; } - public function setPassword($password) + public function setPassword(?string $password): void { $this->password = $password; } public function getSalt() { + return null; } public function getUsername() @@ -62,7 +65,7 @@ public function getUsername() return $this->getId(); } - public function eraseCredentials() + public function eraseCredentials(): void { } } diff --git a/Tests/Functional/TestCase.php b/Tests/Functional/TestCase.php index a8e1612f..3061ee51 100644 --- a/Tests/Functional/TestCase.php +++ b/Tests/Functional/TestCase.php @@ -35,6 +35,9 @@ protected function tearDown(): void static::$kernel = null; } + /** + * @param array $options + */ protected static function createKernel(array $options = []) { $env = @$options['env'] ?: 'test'; diff --git a/Tests/Model/TokenTest.php b/Tests/Model/TokenTest.php index 053032c3..fcad561f 100644 --- a/Tests/Model/TokenTest.php +++ b/Tests/Model/TokenTest.php @@ -30,7 +30,7 @@ class TokenTest extends TestCase * @param mixed $expiresAt * @param mixed $expect */ - public function testHasExpired($expiresAt, $expect) + public function testHasExpired($expiresAt, $expect): void { $token = new Token(); $token->setExpiresAt($expiresAt); @@ -38,6 +38,9 @@ public function testHasExpired($expiresAt, $expect) $this->assertSame($expect, $token->hasExpired()); } + /** + * @return array + */ public static function getTestHasExpiredData() { return [ @@ -47,14 +50,14 @@ public static function getTestHasExpiredData() ]; } - public function testExpiresIn() + public function testExpiresIn(): void { $token = new Token(); $this->assertSame(PHP_INT_MAX, $token->getExpiresIn()); } - public function testExpiresInWithExpiresAt() + public function testExpiresInWithExpiresAt(): void { $token = new Token(); $token->setExpiresAt(time() + 60); diff --git a/Tests/Propel/AuthCodeManagerTest.php b/Tests/Propel/AuthCodeManagerTest.php index 4d49a57e..a8b1be60 100644 --- a/Tests/Propel/AuthCodeManagerTest.php +++ b/Tests/Propel/AuthCodeManagerTest.php @@ -28,7 +28,7 @@ class AuthCodeManagerTest extends PropelTestCase protected $manager; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -36,17 +36,17 @@ public function setUp() AuthCodeQuery::create()->deleteAll(); } - public function testConstruct() + public function testConstruct(): void { $this->assertSame(self::AUTH_CODE_CLASS, $this->manager->getClass()); } - public function testCreateClass() + public function testCreateClass(): void { $this->assertInstanceOf(self::AUTH_CODE_CLASS, $this->manager->createAuthCode()); } - public function testUpdate() + public function testUpdate(): void { $authCode = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\AuthCode') ->disableOriginalConstructor() @@ -60,7 +60,7 @@ public function testUpdate() $this->manager->updateAuthCode($authCode); } - public function testDelete() + public function testDelete(): void { $authCode = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\AuthCode') ->disableOriginalConstructor() @@ -74,14 +74,14 @@ public function testDelete() $this->manager->deleteAuthCode($authCode); } - public function testFindAuthCodeReturnsNullIfNotFound() + public function testFindAuthCodeReturnsNullIfNotFound(): void { $authCode = $this->manager->findAuthCodeBy(['token' => '12345']); $this->assertNull($authCode); } - public function testFindAuthCode() + public function testFindAuthCode(): void { $authCode = $this->createAuthCode('12345'); $return = $this->manager->findAuthCodeBy(['token' => '12345']); @@ -90,7 +90,7 @@ public function testFindAuthCode() $this->assertSame($authCode, $return); } - public function testFindAuthCodeByToken() + public function testFindAuthCodeByToken(): void { $authCode = $this->createAuthCode('12345'); $return = $this->manager->findAuthCodeByToken('12345'); @@ -99,14 +99,14 @@ public function testFindAuthCodeByToken() $this->assertSame($authCode, $return); } - public function testFindAuthCodeByTokenReturnsNullIfNotFound() + public function testFindAuthCodeByTokenReturnsNullIfNotFound(): void { $return = $this->manager->findAuthCodeByToken('12345'); $this->assertNull($return); } - public function testFindAuthCodeWithInvalidData() + public function testFindAuthCodeWithInvalidData(): void { $token = $this->manager->findAuthCodeBy(['foo' => '12345']); $this->assertNull($token); @@ -118,7 +118,7 @@ public function testFindAuthCodeWithInvalidData() $this->assertNull($token); } - public function testDeleteExpired() + public function testDeleteExpired(): void { $a1 = $this->createAuthCode('12345', time() + 100); $a2 = $this->createAuthCode('67890', time() - 100); diff --git a/Tests/Propel/AuthCodeTest.php b/Tests/Propel/AuthCodeTest.php index e8993bc4..95ee9041 100644 --- a/Tests/Propel/AuthCodeTest.php +++ b/Tests/Propel/AuthCodeTest.php @@ -45,14 +45,14 @@ public static function getTestHasExpiredData() ]; } - public function testExpiresIn() + public function testExpiresIn(): void { $token = new AuthCode(); $this->assertSame(PHP_INT_MAX, $token->getExpiresIn()); } - public function testExpiresInWithExpiresAt() + public function testExpiresInWithExpiresAt(): void { $token = new AuthCode(); $token->setExpiresAt(time() + 60); diff --git a/Tests/Propel/ClientManagerTest.php b/Tests/Propel/ClientManagerTest.php index 16bea8c6..60c44fee 100644 --- a/Tests/Propel/ClientManagerTest.php +++ b/Tests/Propel/ClientManagerTest.php @@ -23,7 +23,7 @@ class ClientManagerTest extends PropelTestCase protected $manager; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -31,17 +31,17 @@ public function setUp() ClientQuery::create()->deleteAll(); } - public function testConstruct() + public function testConstruct(): void { $this->assertSame(self::CLIENT_CLASS, $this->manager->getClass()); } - public function testCreateClass() + public function testCreateClass(): void { $this->assertInstanceOf(self::CLIENT_CLASS, $this->manager->createClient()); } - public function testUpdate() + public function testUpdate(): void { $client = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Client') ->disableOriginalConstructor() @@ -55,7 +55,7 @@ public function testUpdate() $this->manager->updateClient($client); } - public function testDelete() + public function testDelete(): void { $client = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Client') ->disableOriginalConstructor() @@ -69,14 +69,14 @@ public function testDelete() $this->manager->deleteClient($client); } - public function testFindClientReturnsNullIfNotFound() + public function testFindClientReturnsNullIfNotFound(): void { $client = $this->manager->findClientBy(['id' => '1', 'randomId' => '2345']); $this->assertNull($client); } - public function testFindClientWithInvalidCriteria() + public function testFindClientWithInvalidCriteria(): void { $client = $this->manager->findClientBy(['randomId' => '2345']); $this->assertNull($client); @@ -88,7 +88,7 @@ public function testFindClientWithInvalidCriteria() $this->assertNull($client); } - public function testFindClient() + public function testFindClient(): void { $client = $this->createClient('2345'); $return = $this->manager->findClientBy(['id' => '1', 'randomId' => '2345']); @@ -97,7 +97,7 @@ public function testFindClient() $this->assertSame($client, $return); } - public function testFindClientByPublicId() + public function testFindClientByPublicId(): void { $client = $this->createClient('12345'); $return = $this->manager->findClientByPublicId('1_12345'); @@ -106,14 +106,14 @@ public function testFindClientByPublicId() $this->assertSame($client, $return); } - public function testFindClientByPublicIdReturnsNullIfNotFound() + public function testFindClientByPublicIdReturnsNullIfNotFound(): void { $return = $this->manager->findClientByPublicId('1_12345'); $this->assertNull($return); } - public function testFindClientByPublicIdReturnsNullIfInvalidPublicId() + public function testFindClientByPublicIdReturnsNullIfInvalidPublicId(): void { $return = $this->manager->findClientByPublicId('1'); $this->assertNull($return); diff --git a/Tests/Propel/ClientTest.php b/Tests/Propel/ClientTest.php index f10cb282..c2f3d2b9 100644 --- a/Tests/Propel/ClientTest.php +++ b/Tests/Propel/ClientTest.php @@ -18,7 +18,7 @@ class ClientTest extends PropelTestCase { - public function testConstructor() + public function testConstructor(): void { $client = new Client(); @@ -30,7 +30,7 @@ public function testConstructor() $this->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/PropelTestCase.php b/Tests/Propel/PropelTestCase.php index c0b65fba..7ad41b66 100644 --- a/Tests/Propel/PropelTestCase.php +++ b/Tests/Propel/PropelTestCase.php @@ -17,7 +17,7 @@ class PropelTestCase extends TestCase { - public function setUp() + public function setUp(): void { if (!class_exists('\Propel')) { $this->markTestSkipped('Propel is not installed.'); diff --git a/Tests/Propel/TokenManagerTest.php b/Tests/Propel/TokenManagerTest.php index 6de63827..58b73610 100644 --- a/Tests/Propel/TokenManagerTest.php +++ b/Tests/Propel/TokenManagerTest.php @@ -28,7 +28,7 @@ class TokenManagerTest extends PropelTestCase protected $manager; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -36,18 +36,18 @@ public function setUp() TokenQuery::create()->deleteAll(); } - public function testConstruct() + public function testConstruct(): void { $this->assertSame(self::TOKEN_CLASS, $this->manager->getClass()); } - public function testCreateClass() + public function testCreateClass(): void { $this->manager = new TokenManager('Token'); $this->assertInstanceOf('Token', $this->manager->createToken()); } - public function testUpdate() + public function testUpdate(): void { $token = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Token') ->disableOriginalConstructor() @@ -61,7 +61,7 @@ public function testUpdate() $this->manager->updateToken($token); } - public function testDelete() + public function testDelete(): void { $token = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Token') ->disableOriginalConstructor() @@ -75,14 +75,14 @@ public function testDelete() $this->manager->deleteToken($token); } - public function testFindTokenReturnsNullIfNotFound() + public function testFindTokenReturnsNullIfNotFound(): void { $token = $this->manager->findTokenBy(['token' => '12345']); $this->assertNull($token); } - public function testFindTokenWithInvalidData() + public function testFindTokenWithInvalidData(): void { $token = $this->manager->findTokenBy(['foo' => '12345']); $this->assertNull($token); @@ -94,7 +94,7 @@ public function testFindTokenWithInvalidData() $this->assertNull($token); } - public function testFindToken() + public function testFindToken(): void { $token = $this->createToken('12345'); $return = $this->manager->findTokenBy(['token' => '12345']); @@ -103,7 +103,7 @@ public function testFindToken() $this->assertSame($token, $return); } - public function testFindTokenByToken() + public function testFindTokenByToken(): void { $token = $this->createToken('12345'); $return = $this->manager->findTokenByToken('12345'); @@ -112,14 +112,14 @@ public function testFindTokenByToken() $this->assertSame($token, $return); } - public function testFindTokenByTokenReturnsNullIfNotFound() + public function testFindTokenByTokenReturnsNullIfNotFound(): void { $return = $this->manager->findTokenByToken('12345'); $this->assertNull($return); } - public function testDeleteExpired() + public function testDeleteExpired(): void { $a1 = $this->createToken('12345', time() + 100); $a2 = $this->createToken('67890', time() - 100); diff --git a/Tests/Propel/TokenTest.php b/Tests/Propel/TokenTest.php index 6ad9e931..4be57774 100644 --- a/Tests/Propel/TokenTest.php +++ b/Tests/Propel/TokenTest.php @@ -45,14 +45,14 @@ public static function getTestHasExpiredData() ]; } - public function testExpiresIn() + public function testExpiresIn(): void { $token = new Token(); $this->assertSame(PHP_INT_MAX, $token->getExpiresIn()); } - public function testExpiresInWithExpiresAt() + public function testExpiresInWithExpiresAt(): void { $token = new Token(); $token->setExpiresAt(time() + 60); diff --git a/Tests/Security/Authentication/Provider/OAuthProviderTest.php b/Tests/Security/Authentication/Provider/OAuthProviderTest.php index 01865280..da106c93 100644 --- a/Tests/Security/Authentication/Provider/OAuthProviderTest.php +++ b/Tests/Security/Authentication/Provider/OAuthProviderTest.php @@ -24,12 +24,12 @@ class OAuthProviderTest extends \PHPUnit\Framework\TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|UserInterface + * @var \PHPUnit\Framework\MockObject\MockObject|UserInterface */ protected $user; /** - * @var \PHPUnit_Framework_MockObject_MockObject|UserProviderInterface + * @var \PHPUnit\Framework\MockObject\MockObject|UserProviderInterface */ protected $userProvider; @@ -39,7 +39,7 @@ class OAuthProviderTest extends \PHPUnit\Framework\TestCase protected $provider; /** - * @var \PHPUnit_Framework_MockObject_MockObject|OAuth2 + * @var \PHPUnit\Framework\MockObject\MockObject|OAuth2 */ protected $serverService; @@ -48,7 +48,7 @@ class OAuthProviderTest extends \PHPUnit\Framework\TestCase */ protected $userChecker; - public function setUp() + public function setUp(): void { $this->user = $this->getMockBuilder(UserInterface::class) ->disableOriginalConstructor() @@ -70,7 +70,7 @@ public function setUp() $this->provider = new OAuthProvider($this->userProvider, $this->serverService, $this->userChecker); } - public function testAuthenticateReturnsTokenIfValid() + public function testAuthenticateReturnsTokenIfValid(): void { $token = new OAuthToken(); $token->setToken('x'); @@ -99,7 +99,7 @@ public function testAuthenticateReturnsTokenIfValid() $this->assertSame('ROLE_USER', $roles[0]); } - public function testAuthenticateReturnsTokenIfValidEvenIfNullData() + public function testAuthenticateReturnsTokenIfValidEvenIfNullData(): void { $token = new OAuthToken(); $token->setToken('x'); @@ -119,7 +119,7 @@ public function testAuthenticateReturnsTokenIfValidEvenIfNullData() $this->assertCount(0, $result->getRoleNames()); } - public function testAuthenticateTransformsScopesAsRoles() + public function testAuthenticateTransformsScopesAsRoles(): void { $token = new OAuthToken(); $token->setToken('x'); @@ -144,7 +144,7 @@ public function testAuthenticateTransformsScopesAsRoles() $this->assertSame('ROLE_BAR', $roles[1]); } - public function testAuthenticateWithNullScope() + public function testAuthenticateWithNullScope(): void { $this->markTestIncomplete('Scope is not nullable'); @@ -167,7 +167,7 @@ public function testAuthenticateWithNullScope() $this->assertCount(0, $result->getRoleNames()); } - public function testAuthenticateWithEmptyScope() + public function testAuthenticateWithEmptyScope(): void { $token = new OAuthToken(); $token->setToken('x'); diff --git a/Tests/Security/Authentification/Token/OAuthTokenTest.php b/Tests/Security/Authentification/Token/OAuthTokenTest.php index 31f41bdb..d43c858a 100644 --- a/Tests/Security/Authentification/Token/OAuthTokenTest.php +++ b/Tests/Security/Authentification/Token/OAuthTokenTest.php @@ -23,14 +23,14 @@ class OAuthTokenTest extends \PHPUnit\Framework\TestCase */ protected $instance; - public function setUp() + public function setUp(): void { $this->instance = new OAuthToken(); parent::setUp(); } - public function testSetTokenWillSetToken() + public function testSetTokenWillSetToken(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -38,10 +38,10 @@ public function testSetTokenWillSetToken() ; $this->assertNull($this->instance->setToken($token)); - $this->assertAttributeSame($token, 'token', $this->instance); + $this->assertSame($token, $this->instance->getToken()); } - public function testGetTokenWillReturnToken() + public function testGetTokenWillReturnToken(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() @@ -53,7 +53,7 @@ public function testGetTokenWillReturnToken() $this->assertSame($token, $this->instance->getToken()); } - public function testGetCredentialsWillReturnToken() + public function testGetCredentialsWillReturnToken(): void { $token = $this->getMockBuilder(TokenInterface::class) ->disableOriginalConstructor() diff --git a/Tests/Security/Firewall/OAuthListenerTest.php b/Tests/Security/Firewall/OAuthListenerTest.php index 61f62c27..2d63a4e8 100644 --- a/Tests/Security/Firewall/OAuthListenerTest.php +++ b/Tests/Security/Firewall/OAuthListenerTest.php @@ -23,15 +23,27 @@ class OAuthListenerTest extends TestCase { + /** + * @var OAuth2&\PHPUnit\Framework\MockObject\MockObject + */ protected $serverService; + /** + * @var AuthenticationManagerInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected $authManager; + /** + * @var mixed&\PHPUnit\Framework\MockObject\MockObject + */ protected $securityContext; + /** + * @var RequestEvent&\PHPUnit\Framework\MockObject\MockObject + */ protected $event; - public function setUp() + public function setUp(): void { $this->serverService = $this->getMockBuilder(OAuth2::class) ->disableOriginalConstructor() @@ -64,7 +76,7 @@ public function setUp() ; } - public function testHandle() + public function testHandle(): void { $listener = new OAuthListener($this->securityContext, $this->authManager, $this->serverService); @@ -93,7 +105,7 @@ public function testHandle() $this->assertSame('a-token', $token->getToken()); } - public function testHandleResponse() + public function testHandleResponse(): void { $listener = new OAuthListener($this->securityContext, $this->authManager, $this->serverService); diff --git a/Tests/Storage/OAuthStorageTest.php b/Tests/Storage/OAuthStorageTest.php index f628327b..ca70e609 100644 --- a/Tests/Storage/OAuthStorageTest.php +++ b/Tests/Storage/OAuthStorageTest.php @@ -29,21 +29,36 @@ class OAuthStorageTest extends \PHPUnit\Framework\TestCase { + /** + * @var ClientManagerInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected $clientManager; - + /** + * @var AccessTokenManagerInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected $accessTokenManager; - + /** + * @var RefreshTokenManagerInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected $refreshTokenManager; - + /** + * @var AuthCodeManagerInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected $authCodeManager; - + /** + * @var UserProviderInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected $userProvider; - + /** + * @var EncoderFactoryInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected $encoderFactory; - + /** + * @var OAuthStorage + */ protected $storage; - public function setUp() + public function setUp(): void { $this->clientManager = $this->getMockBuilder(ClientManagerInterface::class) ->disableOriginalConstructor() @@ -73,7 +88,7 @@ public function setUp() $this->storage = new OAuthStorage($this->clientManager, $this->accessTokenManager, $this->refreshTokenManager, $this->authCodeManager, $this->userProvider, $this->encoderFactory); } - public function testGetClientReturnsClientWithGivenId() + public function testGetClientReturnsClientWithGivenId(): void { $client = new Client(); @@ -86,7 +101,7 @@ public function testGetClientReturnsClientWithGivenId() $this->assertSame($client, $this->storage->getClient('123_abc')); } - public function testGetClientReturnsNullIfNotExists() + public function testGetClientReturnsNullIfNotExists(): void { $client = new Client(); @@ -99,7 +114,7 @@ public function testGetClientReturnsNullIfNotExists() $this->assertNull($this->storage->getClient('123_abc')); } - public function testCheckClientCredentialsThrowsIfInvalidClientClass() + public function testCheckClientCredentialsThrowsIfInvalidClientClass(): void { $client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client') ->disableOriginalConstructor() @@ -110,7 +125,7 @@ public function testCheckClientCredentialsThrowsIfInvalidClientClass() $this->storage->checkClientCredentials($client, 'dummy'); } - public function testCheckClientCredentialsReturnsTrueOnValidCredentials() + public function testCheckClientCredentialsReturnsTrueOnValidCredentials(): void { $client = new Client(); $client->setSecret('dummy'); @@ -118,7 +133,7 @@ public function testCheckClientCredentialsReturnsTrueOnValidCredentials() $this->assertTrue($this->storage->checkClientCredentials($client, 'dummy')); } - public function testCheckClientCredentialsReturnsFalseOnValidCredentials() + public function testCheckClientCredentialsReturnsFalseOnValidCredentials(): void { $client = new Client(); $client->setSecret('dummy'); @@ -126,7 +141,7 @@ public function testCheckClientCredentialsReturnsFalseOnValidCredentials() $this->assertFalse($this->storage->checkClientCredentials($client, 'passe')); } - public function testGetAccessTokenReturnsAccessTokenWithGivenId() + public function testGetAccessTokenReturnsAccessTokenWithGivenId(): void { $token = new AccessToken(); @@ -139,7 +154,7 @@ public function testGetAccessTokenReturnsAccessTokenWithGivenId() $this->assertSame($token, $this->storage->getAccessToken('123_abc')); } - public function testGetAccessTokenReturnsNullIfNotExists() + public function testGetAccessTokenReturnsNullIfNotExists(): void { $token = new AccessToken(); @@ -152,7 +167,7 @@ public function testGetAccessTokenReturnsNullIfNotExists() $this->assertNull($this->storage->getAccessToken('123_abc')); } - public function testCreateAccessTokenThrowsOnInvalidClientClass() + public function testCreateAccessTokenThrowsOnInvalidClientClass(): void { $client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client') ->disableOriginalConstructor() @@ -163,7 +178,7 @@ public function testCreateAccessTokenThrowsOnInvalidClientClass() $this->storage->createAccessToken('foo', $client, new User(42), 1, 'foo bar'); } - public function testCreateAccessToken() + public function testCreateAccessToken(): void { $savedToken = null; @@ -194,7 +209,7 @@ public function testCreateAccessToken() $this->assertSame('foo bar', $token->getScope()); } - public function testCreateAccessTokenWithoutUser() + public function testCreateAccessTokenWithoutUser(): void { $savedToken = null; @@ -218,7 +233,7 @@ public function testCreateAccessTokenWithoutUser() $this->assertSame($token, $savedToken); } - public function testGetRefreshTokenReturnsRefreshTokenWithGivenId() + public function testGetRefreshTokenReturnsRefreshTokenWithGivenId(): void { $token = new RefreshToken(); @@ -231,7 +246,7 @@ public function testGetRefreshTokenReturnsRefreshTokenWithGivenId() $this->assertSame($token, $this->storage->getRefreshToken('123_abc')); } - public function testGetRefreshTokenReturnsNullIfNotExists() + public function testGetRefreshTokenReturnsNullIfNotExists(): void { $this->refreshTokenManager->expects($this->once()) ->method('findTokenByToken') @@ -242,7 +257,7 @@ public function testGetRefreshTokenReturnsNullIfNotExists() $this->assertNull($this->storage->getRefreshToken('123_abc')); } - public function testCreateRefreshTokenThrowsOnInvalidClientClass() + public function testCreateRefreshTokenThrowsOnInvalidClientClass(): void { $client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client') ->disableOriginalConstructor() @@ -253,7 +268,7 @@ public function testCreateRefreshTokenThrowsOnInvalidClientClass() $this->storage->createRefreshToken('foo', $client, 42, 1, 'foo bar'); } - public function testCreateRefreshToken() + public function testCreateRefreshToken(): void { $savedToken = null; @@ -284,7 +299,7 @@ public function testCreateRefreshToken() $this->assertSame('foo bar', $token->getScope()); } - public function testCreateRefreshTokenWithoutUser() + public function testCreateRefreshTokenWithoutUser(): void { $savedToken = null; @@ -308,7 +323,7 @@ public function testCreateRefreshTokenWithoutUser() $this->assertSame($token, $savedToken); } - public function testCheckRestrictedGrantTypeThrowsOnInvalidClientClass() + public function testCheckRestrictedGrantTypeThrowsOnInvalidClientClass(): void { $client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client') ->disableOriginalConstructor() @@ -320,7 +335,7 @@ public function testCheckRestrictedGrantTypeThrowsOnInvalidClientClass() $this->storage->checkRestrictedGrantType($client, 'foo'); } - public function testCheckRestrictedGrantType() + public function testCheckRestrictedGrantType(): void { $client = new Client(); $client->setAllowedGrantTypes(['foo', 'bar']); @@ -330,7 +345,7 @@ public function testCheckRestrictedGrantType() $this->assertFalse($this->storage->checkRestrictedGrantType($client, 'baz')); } - public function testCheckUserCredentialsThrowsOnInvalidClientClass() + public function testCheckUserCredentialsThrowsOnInvalidClientClass(): void { $client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client') ->disableOriginalConstructor() @@ -342,7 +357,7 @@ public function testCheckUserCredentialsThrowsOnInvalidClientClass() $this->storage->checkUserCredentials($client, 'Joe', 'baz'); } - public function testCheckUserCredentialsCatchesAuthenticationExceptions() + public function testCheckUserCredentialsCatchesAuthenticationExceptions(): void { $client = new Client(); @@ -358,7 +373,7 @@ public function testCheckUserCredentialsCatchesAuthenticationExceptions() $this->assertFalse($result); } - public function testCheckUserCredentialsReturnsTrueOnValidCredentials() + public function testCheckUserCredentialsReturnsTrueOnValidCredentials(): void { $client = new Client(); $user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface') @@ -397,7 +412,7 @@ public function testCheckUserCredentialsReturnsTrueOnValidCredentials() ], $this->storage->checkUserCredentials($client, 'Joe', 'baz')); } - public function testCheckUserCredentialsReturnsFalseOnInvalidCredentials() + public function testCheckUserCredentialsReturnsFalseOnInvalidCredentials(): void { $client = new Client(); $user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface') @@ -434,7 +449,7 @@ public function testCheckUserCredentialsReturnsFalseOnInvalidCredentials() $this->assertFalse($this->storage->checkUserCredentials($client, 'Joe', 'baz')); } - public function testCheckUserCredentialsReturnsFalseIfUserNotExist() + public function testCheckUserCredentialsReturnsFalseIfUserNotExist(): void { $client = new Client(); @@ -447,7 +462,7 @@ public function testCheckUserCredentialsReturnsFalseIfUserNotExist() $this->assertFalse($this->storage->checkUserCredentials($client, 'Joe', 'baz')); } - public function testCreateAuthCodeThrowsOnInvalidClientClass() + public function testCreateAuthCodeThrowsOnInvalidClientClass(): void { $client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client') ->disableOriginalConstructor() @@ -458,7 +473,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; @@ -489,7 +504,7 @@ public function testCreateAuthCode() $this->assertSame('foo bar', $code->getScope()); } - public function testGetAuthCodeReturnsAuthCodeWithGivenId() + public function testGetAuthCodeReturnsAuthCodeWithGivenId(): void { $code = new AuthCode(); @@ -502,7 +517,7 @@ public function testGetAuthCodeReturnsAuthCodeWithGivenId() $this->assertSame($code, $this->storage->getAuthCode('123_abc')); } - public function testGetAuthCodeReturnsNullIfNotExists() + public function testGetAuthCodeReturnsNullIfNotExists(): void { $this->authCodeManager->expects($this->once()) ->method('findAuthCodeByToken') @@ -513,7 +528,7 @@ public function testGetAuthCodeReturnsNullIfNotExists() $this->assertNull($this->storage->getAuthCode('123_abc')); } - public function testValidGrantExtension() + public function testValidGrantExtension(): void { $grantExtension = $this->getMockBuilder('FOS\OAuthServerBundle\Storage\GrantExtensionInterface') ->disableOriginalConstructor() @@ -533,7 +548,7 @@ public function testValidGrantExtension() $this->assertTrue($this->storage->checkGrantExtension($client, 'https://friendsofsymfony.com/grants/foo', [], [])); } - public function testInvalidGrantExtension() + public function testInvalidGrantExtension(): void { $this->expectException(\OAuth2\OAuth2ServerException::class); @@ -544,7 +559,7 @@ public function testInvalidGrantExtension() $this->storage->checkGrantExtension($client, 'https://friendsofsymfony.com/grants/bar', [], []); } - public function testDoubleSetGrantExtension() + public function testDoubleSetGrantExtension(): void { $grantExtension = $this->getMockBuilder('FOS\OAuthServerBundle\Storage\GrantExtensionInterface') ->disableOriginalConstructor() @@ -565,7 +580,7 @@ public function testDoubleSetGrantExtension() $this->assertSame($grantExtension2, $grantExtensions[$uri]); } - public function testMarkAuthCodeAsUsedIfAuthCodeFound() + public function testMarkAuthCodeAsUsedIfAuthCodeFound(): void { $authCode = $this->getMockBuilder('FOS\OAuthServerBundle\Model\AuthCodeInterface') ->disableOriginalConstructor() @@ -587,7 +602,7 @@ public function testMarkAuthCodeAsUsedIfAuthCodeFound() $this->storage->markAuthCodeAsUsed('123_abc'); } - public function testMarkAuthCodeAsUsedIfAuthCodeNotFound() + public function testMarkAuthCodeAsUsedIfAuthCodeNotFound(): void { $this->authCodeManager->expects($this->atLeastOnce()) ->method('findAuthCodeByToken') @@ -605,8 +620,14 @@ public function testMarkAuthCodeAsUsedIfAuthCodeNotFound() class User implements UserInterface { + /** + * @var string|int + */ private $username; + /** + * @param string|int $username + */ public function __construct($username) { $this->username = $username; @@ -614,22 +635,28 @@ public function __construct($username) public function getRoles() { + return []; } public function getPassword() { + return null; } public function getSalt() { + return null; } + /** + * @return string|int + */ public function getUsername() { return $this->username; } - public function eraseCredentials() + public function eraseCredentials(): void { } } diff --git a/Tests/Util/RandomTest.php b/Tests/Util/RandomTest.php index 830232a9..93ea7601 100644 --- a/Tests/Util/RandomTest.php +++ b/Tests/Util/RandomTest.php @@ -25,7 +25,7 @@ class RandomTest extends \PHPUnit\Framework\TestCase { use PHPMock; - public function setUp() + public function setUp(): void { parent::setUp(); } @@ -33,7 +33,7 @@ public function setUp() /** * @runInSeparateProcess */ - public function testGenerateTokenWillUseRandomBytesIfAvailable() + public function testGenerateTokenWillUseRandomBytesIfAvailable(): void { $hashResult = \random_bytes(32); diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index f32a19c5..9bf60548 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -22,11 +22,11 @@ \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists'); // Generate Propel base classes on the fly -if (class_exists('TypehintableBehavior')) { - $class = new \ReflectionClass('TypehintableBehavior'); - $builder = new \PropelQuickBuilder(); - $builder->getConfig()->setBuildProperty('behavior.typehintable.class', $class->getFileName()); - $builder->setSchema(file_get_contents(__DIR__.'/../Resources/config/propel/schema.xml')); - $builder->setClassTargets(['tablemap', 'peer', 'object', 'query', 'peerstub']); - $builder->build(); -} +//if (class_exists('TypehintableBehavior')) { +// $class = new \ReflectionClass('TypehintableBehavior'); +// $builder = new \PropelQuickBuilder(); +// $builder->getConfig()->setBuildProperty('behavior.typehintable.class', $class->getFileName()); +// $builder->setSchema(file_get_contents(__DIR__.'/../Resources/config/propel/schema.xml')); +// $builder->setClassTargets(['tablemap', 'peer', 'object', 'query', 'peerstub']); +// $builder->build(); +//} diff --git a/Util/Random.php b/Util/Random.php index f0c10ed5..71cb8865 100644 --- a/Util/Random.php +++ b/Util/Random.php @@ -20,6 +20,9 @@ */ class Random { + /** + * @return string + */ public static function generateToken() { $bytes = random_bytes(32); diff --git a/composer.json b/composer.json index f3dc487a..69c74836 100644 --- a/composer.json +++ b/composer.json @@ -31,14 +31,15 @@ "twig/twig": "<1.40 || >=2.0,<2.9" }, "require-dev": { + "alcaeus/mongo-php-adapter": "*", "doctrine/doctrine-bundle": "^2.0", "doctrine/mongodb-odm": "~1.0", "doctrine/orm": "~2.2", "phing/phing": "~2.4", "php-mock/php-mock-phpunit": "~1.0 || ~2.0", - "phpstan/phpstan-phpunit": "~0.9", - "phpstan/phpstan-shim": "~0.9", - "phpunit/phpunit": "~5.0 || ~6.0", + "phpstan/phpstan-phpunit": ">=0.12", + "phpstan/phpstan-symfony": ">=0.11", + "phpunit/phpunit": "^8", "propel/propel1": "~1.6", "symfony/console": "^4.4 || ^5.1", "symfony/form": "^4.4 || ^5.1", diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index c94c6e65..00000000 --- a/phpstan.neon +++ /dev/null @@ -1,21 +0,0 @@ -includes: - - vendor/phpstan/phpstan-phpunit/extension.neon -parameters: - autoload_files: - - vendor/autoload.php - excludes_analyse: - - vendor/ - - # Propel stuff seems broken as-is, ignoring for now - - Propel/ - - Tests/Propel/ - ignoreErrors: - # temporary - - '#Parameter \#1 \$httpStatusCode of class OAuth2\\OAuth2ServerException constructor expects string, int given#' - - '#Parameter \#1 \$httpCode of class OAuth2\\OAuth2AuthenticateException constructor expects string, int given#' - # how to avoid excluding these? - - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::scalarNode()#' - - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::end()#' - - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children().#' - # expected - - '#Parameter \#2 $requestStack of class FOS\OAuthServerBundle\Form\Handler\AuthorizeFormHandler constructor expects Symfony\Component\HttpFoundation\Request|Symfony\Component\HttpFoundation\RequestStack|null, stdClass given.#' diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 00000000..bcbe9ea9 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,29 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-symfony/extension.neon + - vendor/phpstan/phpstan-symfony/rules.neon +parameters: + checkMissingIterableValueType: false + excludes_analyse: + - vendor/ + # Propel stuff seems broken as-is, ignoring for now + - Propel/ + - Tests/Propel/ + ignoreErrors: + # temporary + - '#Parameter \#1 \$httpStatusCode of class OAuth2\\OAuth2ServerException constructor expects string, int given#' + - '#Parameter \#1 \$httpCode of class OAuth2\\OAuth2AuthenticateException constructor expects string, int given#' + # how to avoid excluding these? + - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::scalarNode\(\)#' + - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\).#' + # expected + - '#Parameter \#2 \$requestStack of class FOS\\OAuthServerBundle\\Form\\Handler\\AuthorizeFormHandler constructor expects Symfony\\Component\\HttpFoundation\\Request\|Symfony\\Component\\HttpFoundation\\RequestStack\|null, stdClass given.#' + # Nothing wrong with unit testing things that PHPStan is also checking + - '#Call to method PHPUnit\\Framework\\Assert::assert.*will always evaluate to.*#' + # Assertions that the result of void methods are null + - + message: '#Result of method .*\(\) \(void\) is used#' + paths: ['Tests/*'] + level: 6 + parallel: + maximumNumberOfProcesses: 1 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5192b311..769c7bbb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,17 @@ - ./Tests + Tests/Command + Tests/Controller + Tests/DependencyInjection + Tests/Document + Tests/Entity + Tests/Form + Tests/Functional + Tests/Model + Tests/Security + Tests/Storage + Tests/Util From e06aece5618f8e8f8068c5fc112dccabe39e42ab Mon Sep 17 00:00:00 2001 From: George Bateman Date: Mon, 5 Oct 2020 19:04:33 +0000 Subject: [PATCH 2/3] Exclude Propel client from CreateClientCommandTest --- Tests/Command/CreateClientCommandTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/Command/CreateClientCommandTest.php b/Tests/Command/CreateClientCommandTest.php index 124e09f0..8e1e5730 100644 --- a/Tests/Command/CreateClientCommandTest.php +++ b/Tests/Command/CreateClientCommandTest.php @@ -82,6 +82,8 @@ public function testItShouldCreateClient($client): void $this->assertContains('Client ID', $output); $this->assertContains('Client Secret', $output); + + $this->markTestIncomplete('Excluding FOS\OAuthServerBundle\Propel\Client'); } /** @@ -93,7 +95,7 @@ public function clientProvider() ['FOS\OAuthServerBundle\Document\Client'], ['FOS\OAuthServerBundle\Entity\Client'], ['FOS\OAuthServerBundle\Model\Client'], - ['FOS\OAuthServerBundle\Propel\Client'], + //['FOS\OAuthServerBundle\Propel\Client'], FIXME ]; } } From 18715ade79dbb4a83fe53801c8abc8cc7d2a36b8 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Mon, 5 Oct 2020 19:57:14 +0000 Subject: [PATCH 3/3] Satisfy php-cs-fixer --- DependencyInjection/Configuration.php | 1 + DependencyInjection/FOSOAuthServerExtension.php | 1 + DependencyInjection/Security/Factory/OAuthFactory.php | 3 +++ Model/AuthCodeManagerInterface.php | 1 + Model/ClientInterface.php | 4 ++++ Model/ClientManagerInterface.php | 1 + Model/TokenInterface.php | 3 +++ Model/TokenManagerInterface.php | 3 +++ Storage/OAuthStorage.php | 9 ++++++++- Tests/Functional/TestBundle/Entity/User.php | 2 ++ 10 files changed, 27 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 77ced031..ba0cd12c 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -26,6 +26,7 @@ class Configuration implements ConfigurationInterface { /** * {@inheritdoc} + * * @return TreeBuilder */ public function getConfigTreeBuilder() diff --git a/DependencyInjection/FOSOAuthServerExtension.php b/DependencyInjection/FOSOAuthServerExtension.php index e029d28a..a1ca72eb 100644 --- a/DependencyInjection/FOSOAuthServerExtension.php +++ b/DependencyInjection/FOSOAuthServerExtension.php @@ -26,6 +26,7 @@ class FOSOAuthServerExtension extends Extension { /** * {@inheritdoc} + * * @return void */ public function load(array $configs, ContainerBuilder $container) diff --git a/DependencyInjection/Security/Factory/OAuthFactory.php b/DependencyInjection/Security/Factory/OAuthFactory.php index b5f6d6ce..f3633932 100644 --- a/DependencyInjection/Security/Factory/OAuthFactory.php +++ b/DependencyInjection/Security/Factory/OAuthFactory.php @@ -28,7 +28,9 @@ class OAuthFactory implements SecurityFactoryInterface { /** * {@inheritdoc} + * * @param mixed $config + * * @return array */ public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) @@ -64,6 +66,7 @@ public function getKey() /** * {@inheritdoc} + * * @return void */ public function addConfiguration(NodeDefinition $node) diff --git a/Model/AuthCodeManagerInterface.php b/Model/AuthCodeManagerInterface.php index 04f22d35..81cdbab4 100644 --- a/Model/AuthCodeManagerInterface.php +++ b/Model/AuthCodeManagerInterface.php @@ -36,6 +36,7 @@ public function getClass(); * Retrieve an auth code using a set of criteria. * * @param array $criteria + * * @return AuthCodeInterface|null */ public function findAuthCodeBy(array $criteria); diff --git a/Model/ClientInterface.php b/Model/ClientInterface.php index f817f7f9..eae2d15b 100644 --- a/Model/ClientInterface.php +++ b/Model/ClientInterface.php @@ -19,6 +19,7 @@ interface ClientInterface extends IOAuth2Client { /** * @param string $random + * * @return void */ public function setRandomId($random); @@ -30,6 +31,7 @@ public function getRandomId(); /** * @param string $secret + * * @return void */ public function setSecret($secret); @@ -48,12 +50,14 @@ public function getSecret(); /** * @param array $redirectUris + * * @return void */ public function setRedirectUris(array $redirectUris); /** * @param array $grantTypes + * * @return void */ public function setAllowedGrantTypes(array $grantTypes); diff --git a/Model/ClientManagerInterface.php b/Model/ClientManagerInterface.php index 8b42f2ad..047f29db 100644 --- a/Model/ClientManagerInterface.php +++ b/Model/ClientManagerInterface.php @@ -27,6 +27,7 @@ public function getClass(); /** * @param array $criteria + * * @return ClientInterface|null */ public function findClientBy(array $criteria); diff --git a/Model/TokenInterface.php b/Model/TokenInterface.php index 23a09a8b..3e9b834e 100644 --- a/Model/TokenInterface.php +++ b/Model/TokenInterface.php @@ -20,6 +20,7 @@ interface TokenInterface extends IOAuth2Token { /** * @param int $timestamp + * * @return void */ public function setExpiresAt($timestamp); @@ -31,12 +32,14 @@ public function getExpiresAt(); /** * @param string $token + * * @return void */ public function setToken($token); /** * @param string $scope + * * @return void */ public function setScope($scope); diff --git a/Model/TokenManagerInterface.php b/Model/TokenManagerInterface.php index aa4ba35d..0eaef174 100644 --- a/Model/TokenManagerInterface.php +++ b/Model/TokenManagerInterface.php @@ -33,6 +33,7 @@ public function getClass(); * Retrieve a token using a set of criteria. * * @param array $criteria + * * @return TokenInterface|null */ public function findTokenBy(array $criteria); @@ -50,6 +51,7 @@ public function findTokenByToken($token); * Save or update a given token. * * @param TokenInterface $token the token to save or update + * * @return void */ public function updateToken(TokenInterface $token); @@ -58,6 +60,7 @@ public function updateToken(TokenInterface $token); * Delete a given token. * * @param TokenInterface $token the token to delete + * * @return void */ public function deleteToken(TokenInterface $token); diff --git a/Storage/OAuthStorage.php b/Storage/OAuthStorage.php index cabb9bd7..5e811083 100644 --- a/Storage/OAuthStorage.php +++ b/Storage/OAuthStorage.php @@ -65,7 +65,8 @@ class OAuthStorage implements IOAuth2RefreshTokens, IOAuth2GrantUser, IOAuth2Gra protected $encoderFactory; /** - * Map of URIs to grant extensions + * Map of URIs to grant extensions. + * * @var array */ protected $grantExtensions; @@ -117,6 +118,11 @@ public function getAccessToken($token) } /** + * @param mixed $tokenString + * @param mixed $data + * @param mixed $expires + * @param mixed|null $scope + * * @return \FOS\OAuthServerBundle\Model\TokenInterface */ public function createAccessToken($tokenString, IOAuth2Client $client, $data, $expires, $scope = null) @@ -181,6 +187,7 @@ public function getAuthCode($code) /** * {@inheritdoc} + * * @return \FOS\OAuthServerBundle\Model\AuthCodeInterface */ public function createAuthCode($code, IOAuth2Client $client, $data, $redirect_uri, $expires, $scope = null) diff --git a/Tests/Functional/TestBundle/Entity/User.php b/Tests/Functional/TestBundle/Entity/User.php index edbe343d..f3b24b32 100644 --- a/Tests/Functional/TestBundle/Entity/User.php +++ b/Tests/Functional/TestBundle/Entity/User.php @@ -25,12 +25,14 @@ class User implements UserInterface * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") + * * @var ?int */ protected $id; /** * @ORM\Column(type="string") + * * @var ?string */ protected $password;