From e726e95af961d7d9dabffc7d2616c677c1b59766 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 4 May 2024 10:46:45 +0200 Subject: [PATCH] constructor argument promotion and cleanup test type declarations --- CHANGELOG.md | 6 +-- src/CacheManager.php | 18 ++----- .../Compiler/HashGeneratorPass.php | 2 +- src/DependencyInjection/Configuration.php | 19 +++---- src/EventListener/AttributesListener.php | 2 +- src/EventListener/CacheControlListener.php | 23 ++++----- src/EventListener/InvalidationListener.php | 24 +++------ src/EventListener/SwitchUserListener.php | 8 ++- src/EventListener/TagListener.php | 34 ++++--------- src/EventListener/UserContextListener.php | 49 +++++++------------ .../QueryStringRequestMatcher.php | 14 +++--- .../ExpressionResponseMatcher.php | 15 +++--- .../NonErrorResponseMatcher.php | 2 +- .../ResponseMatcherInterface.php | 4 +- src/Http/RuleMatcher.php | 12 ++--- src/Http/RuleMatcherInterface.php | 4 +- src/Http/SymfonyResponseTagger.php | 2 +- ...ontextInvalidationSessionLogoutHandler.php | 8 ++- src/Twig/CacheTagExtension.php | 13 ++--- src/UserContext/RequestMatcher.php | 12 ++--- src/UserContext/RoleProvider.php | 2 +- src/UserContextInvalidator.php | 15 ++---- tests/Functional/Command/ClearCommandTest.php | 6 +-- tests/Functional/Command/CommandTestCase.php | 2 +- .../Command/InvalidatePathCommandTest.php | 2 +- .../Command/InvalidateRegexCommandTest.php | 2 +- .../Command/InvalidateTagCommandTest.php | 2 +- .../Command/RefreshPathCommandTest.php | 2 +- .../ServersFromEnvTest.php | 7 +-- .../DependencyInjection/ServiceTest.php | 6 +-- .../ServicesPublicPass.php | 2 +- .../CacheControlListenerTest.php | 4 +- .../FlashMessageListenerTest.php | 8 +-- .../EventListener/SwitchUserListenerTest.php | 9 ++-- .../EventListener/UserContextListenerTest.php | 2 +- .../Controller/FlashMessageController.php | 4 +- .../Controller/TagAttributeController.php | 8 ++- tests/Functional/Fixtures/app/AppKernel.php | 4 +- tests/Functional/SessionHelperTrait.php | 2 +- tests/Unit/CacheManagerTest.php | 13 ++--- .../Command/BaseInvalidateCommandTest.php | 2 +- tests/Unit/Command/ClearCommandTest.php | 6 +-- .../Command/InvalidatePathCommandTest.php | 4 +- .../Command/InvalidateRegexCommandTest.php | 4 +- .../Unit/Command/InvalidateTagCommandTest.php | 4 +- tests/Unit/Command/RefreshPathCommandTest.php | 4 +- .../CacheControlListenerTest.php | 34 ++++++------- .../InvalidationListenerTest.php | 37 +++++--------- .../EventListener/UserContextListenerTest.php | 42 +++++++--------- .../ExpressionResponseMatcherTest.php | 4 +- .../NonErrorResponseMatcherTest.php | 4 +- tests/Unit/Http/RuleMatcherTest.php | 4 +- tests/Unit/Http/SymfonyResponseTaggerTest.php | 2 +- tests/Unit/UserContext/RequestMatcherTest.php | 4 +- tests/Unit/UserContext/RoleProviderTest.php | 4 +- 55 files changed, 204 insertions(+), 328 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26402d72..c1cce94d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,9 @@ Changelog Remove all configuration you have at `fos_http_cache.tags.annotations` * Make `fastly` and `cloudflare` clients lazy loaded to support Symfony secrets that are only available at runtime, but not yet when the container is built. -* Removed deprecated `FOS\HttpCacheBundle\UserContext\AnonymousRequestMatcher`, use the - `FOS\HttpCache\UserContext\AnonymousRequestMatcher` class. -* Removed deprecated `ContextInvalidationLogoutHandler`, use `ContextInvalidationSessionLogoutHandler` instead. +* Removed deprecated `FOS\HttpCacheBundle\UserContext\AnonymousRequestMatcher`, use the class from the `FOSHttpCache` + component instead: `FOS\HttpCache\UserContext\AnonymousRequestMatcher`. +* Removed obsolete `ContextInvalidationLogoutHandler`, use `ContextInvalidationSessionLogoutHandler` instead. * Fixed service loading to not fail when Twig is not available. 2.x diff --git a/src/CacheManager.php b/src/CacheManager.php index aa5ea041..1965b852 100644 --- a/src/CacheManager.php +++ b/src/CacheManager.php @@ -24,26 +24,16 @@ */ class CacheManager extends CacheInvalidator { - private ProxyClient $cache; - - private UrlGeneratorInterface $urlGenerator; - /** * What type of urls to generate. */ private int $generateUrlType = UrlGeneratorInterface::ABSOLUTE_PATH; - /** - * Constructor. - * - * @param ProxyClient $cache HTTP cache proxy client - * @param UrlGeneratorInterface $urlGenerator Symfony route generator - */ - public function __construct(ProxyClient $cache, UrlGeneratorInterface $urlGenerator) - { + public function __construct( + private readonly ProxyClient $cache, + private readonly UrlGeneratorInterface $urlGenerator + ) { parent::__construct($cache); - $this->cache = $cache; - $this->urlGenerator = $urlGenerator; } /** diff --git a/src/DependencyInjection/Compiler/HashGeneratorPass.php b/src/DependencyInjection/Compiler/HashGeneratorPass.php index 85d0f901..4d093679 100644 --- a/src/DependencyInjection/Compiler/HashGeneratorPass.php +++ b/src/DependencyInjection/Compiler/HashGeneratorPass.php @@ -46,7 +46,7 @@ public function process(ContainerBuilder $container): void } krsort($prioritisedTags, SORT_NUMERIC); - $prioritisedProviders = call_user_func_array('array_merge', $prioritisedTags); + $prioritisedProviders = array_merge(...$prioritisedTags); $providers = []; foreach ($prioritisedProviders as $id) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 627075e6..dea4c2f0 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -11,6 +11,7 @@ namespace FOS\HttpCacheBundle\DependencyInjection; +use DateTime; use FOS\HttpCache\ProxyClient\Varnish; use FOS\HttpCache\SymfonyCache\PurgeListener; use FOS\HttpCache\SymfonyCache\PurgeTagsListener; @@ -35,17 +36,9 @@ */ final class Configuration implements ConfigurationInterface { - /** - * @var bool - */ - private $debug; - - /** - * @param bool $debug Whether to use the debug mode - */ - public function __construct($debug) - { - $this->debug = $debug; + public function __construct( + private readonly bool $debug + ) { } public function getConfigTreeBuilder(): TreeBuilder @@ -113,7 +106,7 @@ function ($v) { } if (isset($v['proxy_client']['default']) - && in_array($v['proxy_client']['default'], ['varnish', 'symfony', 'noop']) + && \in_array($v['proxy_client']['default'], ['varnish', 'symfony', 'noop']) ) { $v['user_context']['logout_handler']['enabled'] = true; @@ -325,7 +318,7 @@ private function addCacheControlSection(ArrayNodeDefinition $rootNode): void ->scalarNode('last_modified') ->validate() ->ifTrue(function ($v) { - if (is_string($v)) { + if (\is_string($v)) { new \DateTime($v); } diff --git a/src/EventListener/AttributesListener.php b/src/EventListener/AttributesListener.php index 2fe6e165..4b3b602e 100644 --- a/src/EventListener/AttributesListener.php +++ b/src/EventListener/AttributesListener.php @@ -18,7 +18,7 @@ final class AttributesListener implements EventSubscriberInterface { public function __construct( - private ControllerResolverInterface $controllerResolver + private readonly ControllerResolverInterface $controllerResolver ) { } diff --git a/src/EventListener/CacheControlListener.php b/src/EventListener/CacheControlListener.php index 681daeaa..52cdba85 100644 --- a/src/EventListener/CacheControlListener.php +++ b/src/EventListener/CacheControlListener.php @@ -48,20 +48,15 @@ final class CacheControlListener implements EventSubscriberInterface */ private array $rulesMap = []; - /** - * If not empty, add a debug header with that name to all responses, - * telling the cache proxy to add debug output. - * - * @var string|false Name of the header or false to add no header - */ - private string|false $debugHeader; - - /** - * @param string|false $debugHeader Header to set to trigger debugging, or false to send no header - */ - public function __construct(string|false $debugHeader = false) - { - $this->debugHeader = $debugHeader; + public function __construct( + /** + * If not empty, add a debug header with that name to all responses, + * telling the cache proxy to add debug output. + * + * @var string|false Name of the header or false to add no header + */ + private readonly string|false $debugHeader = false + ) { } public static function getSubscribedEvents(): array diff --git a/src/EventListener/InvalidationListener.php b/src/EventListener/InvalidationListener.php index 24aac5df..7cc3a7b9 100644 --- a/src/EventListener/InvalidationListener.php +++ b/src/EventListener/InvalidationListener.php @@ -35,24 +35,12 @@ */ final class InvalidationListener extends AbstractRuleListener implements EventSubscriberInterface { - private CacheManager $cacheManager; - private UrlGeneratorInterface $urlGenerator; - private ?ExpressionLanguage $expressionLanguage; - private RuleMatcherInterface $mustInvalidateRule; - - /** - * Constructor. - */ public function __construct( - CacheManager $cacheManager, - UrlGeneratorInterface $urlGenerator, - RuleMatcherInterface $mustInvalidateRule, - ?ExpressionLanguage $expressionLanguage = null + private readonly CacheManager $cacheManager, + private readonly UrlGeneratorInterface $urlGenerator, + private readonly RuleMatcherInterface $mustInvalidateRule, + private ?ExpressionLanguage $expressionLanguage = null ) { - $this->cacheManager = $cacheManager; - $this->urlGenerator = $urlGenerator; - $this->mustInvalidateRule = $mustInvalidateRule; - $this->expressionLanguage = $expressionLanguage; } /** @@ -76,7 +64,7 @@ public function onKernelTerminate(TerminateEvent $event): void try { $this->cacheManager->flush(); - } catch (ExceptionCollection $e) { + } catch (ExceptionCollection) { // swallow exception // there is the fos_http_cache.event_listener.log to log them } @@ -89,7 +77,7 @@ public function onKernelException(): void { try { $this->cacheManager->flush(); - } catch (ExceptionCollection $e) { + } catch (ExceptionCollection) { // swallow exception // there is the fos_http_cache.event_listener.log to log them } diff --git a/src/EventListener/SwitchUserListener.php b/src/EventListener/SwitchUserListener.php index ebb7ed9d..bcb09006 100644 --- a/src/EventListener/SwitchUserListener.php +++ b/src/EventListener/SwitchUserListener.php @@ -18,11 +18,9 @@ final class SwitchUserListener implements EventSubscriberInterface { - private UserContextInvalidator $invalidator; - - public function __construct(UserContextInvalidator $invalidator) - { - $this->invalidator = $invalidator; + public function __construct( + private readonly UserContextInvalidator $invalidator + ) { } public static function getSubscribedEvents(): array diff --git a/src/EventListener/TagListener.php b/src/EventListener/TagListener.php index 1a949ea6..4658122a 100644 --- a/src/EventListener/TagListener.php +++ b/src/EventListener/TagListener.php @@ -29,27 +29,13 @@ */ final class TagListener extends AbstractRuleListener implements EventSubscriberInterface { - private CacheManager $cacheManager; - private SymfonyResponseTagger $symfonyResponseTagger; - private ?ExpressionLanguage $expressionLanguage; - private RuleMatcherInterface $mustInvalidateRule; - private RuleMatcherInterface $cacheableRule; - - /** - * Constructor. - */ public function __construct( - CacheManager $cacheManager, - SymfonyResponseTagger $tagHandler, - RuleMatcherInterface $cacheableRule, - RuleMatcherInterface $mustInvalidateRule, - ?ExpressionLanguage $expressionLanguage = null + private readonly CacheManager $cacheManager, + private readonly SymfonyResponseTagger $symfonyResponseTagger, + private readonly RuleMatcherInterface $cacheableRule, + private readonly RuleMatcherInterface $mustInvalidateRule, + private ?ExpressionLanguage $expressionLanguage = null ) { - $this->cacheManager = $cacheManager; - $this->symfonyResponseTagger = $tagHandler; - $this->cacheableRule = $cacheableRule; - $this->mustInvalidateRule = $mustInvalidateRule; - $this->expressionLanguage = $expressionLanguage; } /** @@ -115,19 +101,19 @@ private function getAttributeTags(Request $request): array return []; } - $tags = []; + $tagArrays = []; foreach ($tagConfigurations as $tagConfiguration) { if (null !== $tagConfiguration->getExpression()) { - $tags[] = $this->evaluateTag( + $tagArrays[] = [$this->evaluateTag( $tagConfiguration->getExpression(), $request - ); + )]; } else { - $tags = array_merge($tags, $tagConfiguration->getTags()); + $tagArrays[] = $tagConfiguration->getTags(); } } - return $tags; + return array_merge(...$tagArrays); } /** diff --git a/src/EventListener/UserContextListener.php b/src/EventListener/UserContextListener.php index 9c822139..347e7215 100644 --- a/src/EventListener/UserContextListener.php +++ b/src/EventListener/UserContextListener.php @@ -36,45 +36,30 @@ */ final class UserContextListener implements EventSubscriberInterface { - private RequestMatcherInterface $requestMatcher; - private HashGenerator $hashGenerator; - - /** - * If the response tagger is set, the hash lookup response is tagged with the session id for later invalidation. - */ - private ?ResponseTagger $responseTagger; - private array $options; - /** - * Whether the application has a session listener and therefore could - * require the AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER. - */ - private bool $hasSessionListener; - private bool $wasAnonymous = false; - /** - * Used to exclude anonymous requests (no authentication nor session) from user hash sanity check. - * It prevents issues when the hash generator that is used returns a customized value for anonymous users, - * that differs from the documented, hardcoded one. - */ - private ?RequestMatcherInterface $anonymousRequestMatcher; - public function __construct( - RequestMatcherInterface $requestMatcher, - HashGenerator $hashGenerator, - ?RequestMatcherInterface $anonymousRequestMatcher = null, - ?ResponseTagger $responseTagger = null, + private readonly RequestMatcherInterface $requestMatcher, + private readonly HashGenerator $hashGenerator, + /** + * Used to exclude anonymous requests (no authentication nor session) from user hash sanity check. + * It prevents issues when the hash generator that is used returns a customized value for anonymous users, + * that differs from the documented, hardcoded one. + */ + private readonly ?RequestMatcherInterface $anonymousRequestMatcher = null, + /** + * If the response tagger is set, the hash lookup response is tagged with the session id for later invalidation. + */ + private readonly ?ResponseTagger $responseTagger = null, array $options = [], - bool $hasSessionListener = true + /** + * Whether the application has a session listener and therefore could + * require the AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER. + */ + private readonly bool $hasSessionListener = true ) { - $this->requestMatcher = $requestMatcher; - $this->hashGenerator = $hashGenerator; - $this->anonymousRequestMatcher = $anonymousRequestMatcher; - $this->responseTagger = $responseTagger; - $this->hasSessionListener = $hasSessionListener; - $resolver = new OptionsResolver(); $resolver->setDefaults([ 'user_identifier_headers' => ['Cookie', 'Authorization'], diff --git a/src/Http/RequestMatcher/QueryStringRequestMatcher.php b/src/Http/RequestMatcher/QueryStringRequestMatcher.php index c28f4d4b..274cacea 100644 --- a/src/Http/RequestMatcher/QueryStringRequestMatcher.php +++ b/src/Http/RequestMatcher/QueryStringRequestMatcher.php @@ -19,14 +19,12 @@ */ final class QueryStringRequestMatcher implements RequestMatcherInterface { - /** - * @var string Regular expression to match the query string part of the request url - */ - private string $queryString; - - public function __construct(string $queryString) - { - $this->queryString = $queryString; + public function __construct( + /** + * @var string Regular expression to match the query string part of the request url + */ + private readonly string $queryString + ) { } public function matches(Request $request): bool diff --git a/src/Http/ResponseMatcher/ExpressionResponseMatcher.php b/src/Http/ResponseMatcher/ExpressionResponseMatcher.php index 8af9d232..1b3d4451 100644 --- a/src/Http/ResponseMatcher/ExpressionResponseMatcher.php +++ b/src/Http/ResponseMatcher/ExpressionResponseMatcher.php @@ -16,18 +16,15 @@ final class ExpressionResponseMatcher implements ResponseMatcherInterface { - private ?ExpressionLanguage $expressionLanguage; - private string $expression; - - public function __construct(string $expression, ?ExpressionLanguage $expressionLanguage = null) - { - $this->expression = $expression; - $this->expressionLanguage = $expressionLanguage; + public function __construct( + private readonly string $expression, + private ?ExpressionLanguage $expressionLanguage = null + ) { } - public function matches(Response $response) + public function matches(Response $response): bool { - return $this->getExpressionLanguage()->evaluate( + return (bool) $this->getExpressionLanguage()->evaluate( $this->expression, ['response' => $response] ); diff --git a/src/Http/ResponseMatcher/NonErrorResponseMatcher.php b/src/Http/ResponseMatcher/NonErrorResponseMatcher.php index 8fc17eee..2469f71f 100644 --- a/src/Http/ResponseMatcher/NonErrorResponseMatcher.php +++ b/src/Http/ResponseMatcher/NonErrorResponseMatcher.php @@ -21,7 +21,7 @@ */ final class NonErrorResponseMatcher implements ResponseMatcherInterface { - public function matches(Response $response) + public function matches(Response $response): bool { return $response->getStatusCode() >= 200 && $response->getStatusCode() < 400; diff --git a/src/Http/ResponseMatcher/ResponseMatcherInterface.php b/src/Http/ResponseMatcher/ResponseMatcherInterface.php index 5facffa8..826a96e2 100644 --- a/src/Http/ResponseMatcher/ResponseMatcherInterface.php +++ b/src/Http/ResponseMatcher/ResponseMatcherInterface.php @@ -17,8 +17,6 @@ interface ResponseMatcherInterface { /** * Determines whether the response matches the rule. - * - * @return bool */ - public function matches(Response $response); + public function matches(Response $response): bool; } diff --git a/src/Http/RuleMatcher.php b/src/Http/RuleMatcher.php index 4b752c60..60f88e66 100644 --- a/src/Http/RuleMatcher.php +++ b/src/Http/RuleMatcher.php @@ -25,19 +25,13 @@ */ final class RuleMatcher implements RuleMatcherInterface { - private ?RequestMatcherInterface $requestMatcher; - - private ?ResponseMatcherInterface $responseMatcher; - public function __construct( - ?RequestMatcherInterface $requestMatcher = null, - ?ResponseMatcherInterface $responseMatcher = null + private readonly ?RequestMatcherInterface $requestMatcher = null, + private readonly ?ResponseMatcherInterface $responseMatcher = null ) { - $this->requestMatcher = $requestMatcher; - $this->responseMatcher = $responseMatcher; } - public function matches(Request $request, Response $response) + public function matches(Request $request, Response $response): bool { if ($this->requestMatcher && !$this->requestMatcher->matches($request)) { return false; diff --git a/src/Http/RuleMatcherInterface.php b/src/Http/RuleMatcherInterface.php index 28b13a37..73e6e3a2 100644 --- a/src/Http/RuleMatcherInterface.php +++ b/src/Http/RuleMatcherInterface.php @@ -24,8 +24,6 @@ interface RuleMatcherInterface { /** * Check whether the request and response both match. - * - * @return bool True if request and response match, false otherwise */ - public function matches(Request $request, Response $response); + public function matches(Request $request, Response $response): bool; } diff --git a/src/Http/SymfonyResponseTagger.php b/src/Http/SymfonyResponseTagger.php index 924488c5..0a8cb9a6 100644 --- a/src/Http/SymfonyResponseTagger.php +++ b/src/Http/SymfonyResponseTagger.php @@ -25,7 +25,7 @@ class SymfonyResponseTagger extends ResponseTagger * * @return $this */ - public function tagSymfonyResponse(Response $response, $replace = false) + public function tagSymfonyResponse(Response $response, bool $replace = false): static { if (!$this->hasTags()) { return $this; diff --git a/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php b/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php index c77a42fa..2cb23c8b 100644 --- a/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php +++ b/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php @@ -17,11 +17,9 @@ final class ContextInvalidationSessionLogoutHandler implements EventSubscriberInterface { - private UserContextInvalidator $invalidator; - - public function __construct(UserContextInvalidator $invalidator) - { - $this->invalidator = $invalidator; + public function __construct( + private readonly UserContextInvalidator $invalidator + ) { } public function onLogout(LogoutEvent $event): void diff --git a/src/Twig/CacheTagExtension.php b/src/Twig/CacheTagExtension.php index 3573e14f..1f431cd5 100644 --- a/src/Twig/CacheTagExtension.php +++ b/src/Twig/CacheTagExtension.php @@ -20,14 +20,9 @@ */ class CacheTagExtension extends AbstractExtension { - /** - * @var ResponseTagger - */ - private $responseTagger; - - public function __construct(ResponseTagger $responseTagger) - { - $this->responseTagger = $responseTagger; + public function __construct( + private readonly ResponseTagger $responseTagger + ) { } public function getFunctions(): array @@ -47,7 +42,7 @@ public function getFunctions(): array * * @param string|string[] $tag */ - public function addTag($tag): void + public function addTag(string|array $tag): void { $this->responseTagger->addTags((array) $tag); } diff --git a/src/UserContext/RequestMatcher.php b/src/UserContext/RequestMatcher.php index b60e53d2..f6f4c5b2 100644 --- a/src/UserContext/RequestMatcher.php +++ b/src/UserContext/RequestMatcher.php @@ -16,14 +16,10 @@ final class RequestMatcher implements RequestMatcherInterface { - private ?string $method; - - private ?string $accept; - - public function __construct(?string $accept = 'application/vnd.fos.user-context-hash', ?string $method = null) - { - $this->accept = $accept; - $this->method = $method; + public function __construct( + private ?string $accept = 'application/vnd.fos.user-context-hash', + private ?string $method = null + ) { } public function matches(Request $request): bool diff --git a/src/UserContext/RoleProvider.php b/src/UserContext/RoleProvider.php index d95fc78c..c1955a29 100644 --- a/src/UserContext/RoleProvider.php +++ b/src/UserContext/RoleProvider.php @@ -30,7 +30,7 @@ final class RoleProvider implements ContextProvider * a firewall context. */ public function __construct( - private ?TokenStorageInterface $tokenStorage = null + private readonly ?TokenStorageInterface $tokenStorage = null ) { } diff --git a/src/UserContextInvalidator.php b/src/UserContextInvalidator.php index a7396b32..248d6f2a 100644 --- a/src/UserContextInvalidator.php +++ b/src/UserContextInvalidator.php @@ -17,22 +17,15 @@ class UserContextInvalidator { public const USER_CONTEXT_TAG_PREFIX = 'fos_http_cache_hashlookup-'; - /** - * @var TagCapable - */ - private $tagger; - - public function __construct(TagCapable $tagger) - { - $this->tagger = $tagger; + public function __construct( + private readonly TagCapable $tagger + ) { } /** * Invalidate the user context hash. - * - * @param string $sessionId */ - public function invalidateContext($sessionId): void + public function invalidateContext(string $sessionId): void { $this->tagger->invalidateTags([static::buildTag($sessionId)]); } diff --git a/tests/Functional/Command/ClearCommandTest.php b/tests/Functional/Command/ClearCommandTest.php index b8f8997c..a8cd6323 100644 --- a/tests/Functional/Command/ClearCommandTest.php +++ b/tests/Functional/Command/ClearCommandTest.php @@ -16,7 +16,7 @@ class ClearCommandTest extends CommandTestCase { - public function testExecuteClearVerbose() + public function testExecuteClearVerbose(): void { $client = self::createClient(); @@ -39,7 +39,7 @@ public function testExecuteClearVerbose() $this->assertEquals("Sent 1 invalidation request(s)\n", $output); } - public function testExecuteBanVerbose() + public function testExecuteBanVerbose(): void { $client = self::createClient(); @@ -66,7 +66,7 @@ public function testExecuteBanVerbose() $this->assertEquals("Sent 1 invalidation request(s)\n", $output); } - public function testExecuteErrorVerbose() + public function testExecuteErrorVerbose(): void { $client = self::createClient(); diff --git a/tests/Functional/Command/CommandTestCase.php b/tests/Functional/Command/CommandTestCase.php index 62d306aa..4599a392 100644 --- a/tests/Functional/Command/CommandTestCase.php +++ b/tests/Functional/Command/CommandTestCase.php @@ -30,7 +30,7 @@ abstract class CommandTestCase extends WebTestCase * * @param int $exitCode Expected command exit code */ - protected function runCommand(KernelBrowser $client, $command, $exitCode = 0): string + protected function runCommand(KernelBrowser $client, $command, int $exitCode = 0): string { $application = new Application($client->getKernel()); $application->setAutoExit(false); diff --git a/tests/Functional/Command/InvalidatePathCommandTest.php b/tests/Functional/Command/InvalidatePathCommandTest.php index b06cc61e..e796e397 100644 --- a/tests/Functional/Command/InvalidatePathCommandTest.php +++ b/tests/Functional/Command/InvalidatePathCommandTest.php @@ -15,7 +15,7 @@ class InvalidatePathCommandTest extends CommandTestCase { - public function testExecuteVerbose() + public function testExecuteVerbose(): void { $client = self::createClient(); diff --git a/tests/Functional/Command/InvalidateRegexCommandTest.php b/tests/Functional/Command/InvalidateRegexCommandTest.php index 88307c56..ca3f77bc 100644 --- a/tests/Functional/Command/InvalidateRegexCommandTest.php +++ b/tests/Functional/Command/InvalidateRegexCommandTest.php @@ -15,7 +15,7 @@ class InvalidateRegexCommandTest extends CommandTestCase { - public function testExecuteVerbose() + public function testExecuteVerbose(): void { $client = self::createClient(); diff --git a/tests/Functional/Command/InvalidateTagCommandTest.php b/tests/Functional/Command/InvalidateTagCommandTest.php index e84d197b..43b1b04e 100644 --- a/tests/Functional/Command/InvalidateTagCommandTest.php +++ b/tests/Functional/Command/InvalidateTagCommandTest.php @@ -15,7 +15,7 @@ class InvalidateTagCommandTest extends CommandTestCase { - public function testExecuteVerbose() + public function testExecuteVerbose(): void { $client = self::createClient(); diff --git a/tests/Functional/Command/RefreshPathCommandTest.php b/tests/Functional/Command/RefreshPathCommandTest.php index 0cc78ab8..9b413604 100644 --- a/tests/Functional/Command/RefreshPathCommandTest.php +++ b/tests/Functional/Command/RefreshPathCommandTest.php @@ -15,7 +15,7 @@ class RefreshPathCommandTest extends CommandTestCase { - public function testExecuteVerbose() + public function testExecuteVerbose(): void { $client = self::createClient(); diff --git a/tests/Functional/DependencyInjection/ServersFromEnvTest.php b/tests/Functional/DependencyInjection/ServersFromEnvTest.php index d6d3e35c..bd92da78 100644 --- a/tests/Functional/DependencyInjection/ServersFromEnvTest.php +++ b/tests/Functional/DependencyInjection/ServersFromEnvTest.php @@ -12,10 +12,8 @@ class ServersFromEnvTest extends KernelTestCase { /** * Boots a special kernel with a compiler pass to make all services public for this test. - * - * @return KernelInterface A KernelInterface instance */ - protected function bootDebugKernel() + protected function bootDebugKernel(): KernelInterface { static::ensureKernelShutdown(); static::$kernel = static::createKernel(); @@ -28,7 +26,7 @@ protected function bootDebugKernel() return static::$kernel; } - public function testServersFromEnv() + public function testServersFromEnv(): void { // define the kernel config to use for this test $_ENV['KERNEL_CONFIG'] = 'config_servers_from_env.yml'; @@ -44,7 +42,6 @@ public function testServersFromEnv() $reflectionObject = new \ReflectionClass($fosHttpCache); $reflectionGetServers = $reflectionObject->getMethod('getServers'); - $reflectionGetServers->setAccessible(true); $uris = $reflectionGetServers->invoke($fosHttpCache); $servers = array_map(function ($uri) { return $uri->__toString(); }, $uris); diff --git a/tests/Functional/DependencyInjection/ServiceTest.php b/tests/Functional/DependencyInjection/ServiceTest.php index 2e859b39..cf6e7df0 100644 --- a/tests/Functional/DependencyInjection/ServiceTest.php +++ b/tests/Functional/DependencyInjection/ServiceTest.php @@ -23,10 +23,8 @@ class ServiceTest extends KernelTestCase { /** * Boots a special kernel with a compiler pass to make all services public for this test. - * - * @return KernelInterface A KernelInterface instance */ - protected function bootDebugKernel() + protected function bootDebugKernel(): KernelInterface { static::ensureKernelShutdown(); @@ -40,7 +38,7 @@ protected function bootDebugKernel() return static::$kernel; } - public function testCanBeLoaded() + public function testCanBeLoaded(): void { /** @var Container $container */ $container = $this->bootDebugKernel()->getContainer(); diff --git a/tests/Functional/DependencyInjection/ServicesPublicPass.php b/tests/Functional/DependencyInjection/ServicesPublicPass.php index 24803e84..1192e8de 100644 --- a/tests/Functional/DependencyInjection/ServicesPublicPass.php +++ b/tests/Functional/DependencyInjection/ServicesPublicPass.php @@ -7,7 +7,7 @@ class ServicesPublicPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { foreach ($container->getServiceIds() as $id) { if (strncmp('fos_http_cache.', $id, 15)) { diff --git a/tests/Functional/EventListener/CacheControlListenerTest.php b/tests/Functional/EventListener/CacheControlListenerTest.php index 2133deca..b9d8c955 100644 --- a/tests/Functional/EventListener/CacheControlListenerTest.php +++ b/tests/Functional/EventListener/CacheControlListenerTest.php @@ -18,7 +18,7 @@ class CacheControlListenerTest extends WebTestCase { use MockeryPHPUnitIntegration; - public function testIsCached() + public function testIsCached(): void { $client = static::createClient(); @@ -27,7 +27,7 @@ public function testIsCached() $this->assertEquals('public', $response->headers->get('Cache-Control'), $response->getContent()); } - public function testNotCached() + public function testNotCached(): void { $client = static::createClient(); diff --git a/tests/Functional/EventListener/FlashMessageListenerTest.php b/tests/Functional/EventListener/FlashMessageListenerTest.php index 788768ac..74f372d5 100644 --- a/tests/Functional/EventListener/FlashMessageListenerTest.php +++ b/tests/Functional/EventListener/FlashMessageListenerTest.php @@ -18,7 +18,7 @@ class FlashMessageListenerTest extends WebTestCase { use MockeryPHPUnitIntegration; - public function testFlashMessageCookieIsSet() + public function testFlashMessageCookieIsSet(): void { $client = static::createClient(); @@ -37,14 +37,14 @@ public function testFlashMessageCookieIsSet() $this->assertEquals('/', $cookie->getPath()); $this->assertNull($cookie->getDomain()); $this->assertTrue($cookie->isSecure()); - $this->assertJsonStringEqualsJsonString(json_encode(['notice' => ['Flash Message!']]), $cookie->getValue()); + $this->assertJsonStringEqualsJsonString(json_encode(['notice' => ['Flash Message!']], JSON_THROW_ON_ERROR), $cookie->getValue()); $found = true; } $this->assertTrue($found, 'Cookie "flash_cookie_name" not found in response cookies'); } - public function testFlashMessageCookieIsSetOnRedirect() + public function testFlashMessageCookieIsSetOnRedirect(): void { $client = static::createClient(); $client->followRedirects(true); @@ -64,7 +64,7 @@ public function testFlashMessageCookieIsSetOnRedirect() $this->assertEquals('/', $cookie->getPath()); $this->assertNull($cookie->getDomain()); $this->assertTrue($cookie->isSecure()); - $this->assertJsonStringEqualsJsonString(json_encode(['notice' => ['Flash Message!', 'Flash Message!']]), $cookie->getValue()); + $this->assertJsonStringEqualsJsonString(json_encode(['notice' => ['Flash Message!', 'Flash Message!']], JSON_THROW_ON_ERROR), $cookie->getValue()); $found = true; } diff --git a/tests/Functional/EventListener/SwitchUserListenerTest.php b/tests/Functional/EventListener/SwitchUserListenerTest.php index 3bbff0e9..52065811 100644 --- a/tests/Functional/EventListener/SwitchUserListenerTest.php +++ b/tests/Functional/EventListener/SwitchUserListenerTest.php @@ -26,10 +26,9 @@ class SwitchUserListenerTest extends WebTestCase use SessionHelperTrait; private const FIREWALL_NAME = 'secured_area'; - private $sessionName; - private static $overrideService = false; + private static bool $overrideService = false; - public function testSwitchUserCompatibility() + public function testSwitchUserCompatibility(): void { $client = static::createClient(); $this->loginAsAdmin($client); @@ -46,7 +45,7 @@ public function testSwitchUserCompatibility() $this->assertSame('admin', substr($client->getResponse()->getContent(), 0, 2000)); } - public function testInvalidateContext() + public function testInvalidateContext(): void { self::$overrideService = true; @@ -68,7 +67,7 @@ public function testInvalidateContext() $client->request('GET', '/secured_area/switch_user?_switch_user=user'); } - public function loginAsAdmin(KernelBrowser $client) + public function loginAsAdmin(KernelBrowser $client): void { $client->loginUser($this->createAdminUser(), self::FIREWALL_NAME); } diff --git a/tests/Functional/EventListener/UserContextListenerTest.php b/tests/Functional/EventListener/UserContextListenerTest.php index 76e19990..8a83303f 100644 --- a/tests/Functional/EventListener/UserContextListenerTest.php +++ b/tests/Functional/EventListener/UserContextListenerTest.php @@ -21,7 +21,7 @@ class UserContextListenerTest extends WebTestCase use SessionHelperTrait; #[PHPUnit\DataProvider('userHashDataProvider')] - public function testHashLookup(string $username, string $hash) + public function testHashLookup(string $username, string $hash): void { // as we tamper with the session id, make sure no previous session is around @unlink('/tmp/test.mocksess'); diff --git a/tests/Functional/Fixtures/Controller/FlashMessageController.php b/tests/Functional/Fixtures/Controller/FlashMessageController.php index 0b831fde..945baebc 100644 --- a/tests/Functional/Fixtures/Controller/FlashMessageController.php +++ b/tests/Functional/Fixtures/Controller/FlashMessageController.php @@ -17,7 +17,7 @@ class FlashMessageController extends AbstractController { - public function flashAction() + public function flashAction(): Response { $this->addFlash( 'notice', @@ -27,7 +27,7 @@ public function flashAction() return new Response('flash'); } - public function flashRedirectAction() + public function flashRedirectAction(): RedirectResponse { $this->addFlash( 'notice', diff --git a/tests/Functional/Fixtures/Controller/TagAttributeController.php b/tests/Functional/Fixtures/Controller/TagAttributeController.php index de059072..be3806f6 100644 --- a/tests/Functional/Fixtures/Controller/TagAttributeController.php +++ b/tests/Functional/Fixtures/Controller/TagAttributeController.php @@ -21,11 +21,9 @@ class TagAttributeController extends AbstractController { - private SymfonyResponseTagger $responseTagger; - - public function __construct(SymfonyResponseTagger $responseTagger) - { - $this->responseTagger = $responseTagger; + public function __construct( + private SymfonyResponseTagger $responseTagger + ) { } #[Tag('all-items')] diff --git a/tests/Functional/Fixtures/app/AppKernel.php b/tests/Functional/Fixtures/app/AppKernel.php index cff7bf7a..a7215a81 100644 --- a/tests/Functional/Fixtures/app/AppKernel.php +++ b/tests/Functional/Fixtures/app/AppKernel.php @@ -21,9 +21,9 @@ class AppKernel extends Kernel /** * @var CompilerPassInterface[] */ - private $compilerPasses = []; + private array $compilerPasses = []; - private $serviceOverride = []; + private array $serviceOverride = []; public function addServiceOverride(string $config): void { diff --git a/tests/Functional/SessionHelperTrait.php b/tests/Functional/SessionHelperTrait.php index f460fd29..05677c20 100644 --- a/tests/Functional/SessionHelperTrait.php +++ b/tests/Functional/SessionHelperTrait.php @@ -19,7 +19,7 @@ */ trait SessionHelperTrait { - private function callInRequestContext(KernelBrowser $client, callable $callable) + private function callInRequestContext(KernelBrowser $client, callable $callable): void { /** @var EventDispatcherInterface $eventDispatcher */ $eventDispatcher = self::$kernel->getContainer()->get('test.service_container')->get(EventDispatcherInterface::class); diff --git a/tests/Unit/CacheManagerTest.php b/tests/Unit/CacheManagerTest.php index c5ba8948..daaf95fb 100644 --- a/tests/Unit/CacheManagerTest.php +++ b/tests/Unit/CacheManagerTest.php @@ -17,6 +17,7 @@ use FOS\HttpCache\ProxyClient\ProxyClient; use FOS\HttpCacheBundle\CacheManager; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; +use Mockery\MockInterface; use PHPUnit\Framework\TestCase; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\VarExporter\LazyObjectInterface; @@ -25,14 +26,14 @@ class CacheManagerTest extends TestCase { use MockeryPHPUnitIntegration; - protected $proxyClient; + protected MockInterface&ProxyClient $proxyClient; public function setUp(): void { $this->proxyClient = \Mockery::mock(ProxyClient::class); } - public function testInvalidateRoute() + public function testInvalidateRoute(): void { $httpCache = \Mockery::mock(PurgeCapable::class) ->shouldReceive('purge')->once()->with('/my/route', []) @@ -59,7 +60,7 @@ public function testInvalidateRoute() ->flush(); } - public function testRefreshRoute() + public function testRefreshRoute(): void { $httpCache = \Mockery::mock(RefreshCapable::class) ->shouldReceive('refresh')->once()->with('/my/route', null) @@ -87,7 +88,7 @@ public function testRefreshRoute() ; } - public function testSkipFlushOnEmptyInvalidationsAndLazyLoaded() + public function testSkipFlushOnEmptyInvalidationsAndLazyLoaded(): void { $proxyClient = \Mockery::mock(HttpProxyClient::class, LazyObjectInterface::class) ->shouldNotReceive('flush') @@ -100,7 +101,7 @@ public function testSkipFlushOnEmptyInvalidationsAndLazyLoaded() $this->assertEquals(0, $cacheInvalidator->flush()); } - public function testFlushOnNotLazyLoaded() + public function testFlushOnNotLazyLoaded(): void { $proxyClient = \Mockery::mock(HttpProxyClient::class) ->shouldReceive('flush')->andReturn(0) @@ -113,7 +114,7 @@ public function testFlushOnNotLazyLoaded() $this->assertEquals(0, $cacheInvalidator->flush()); } - public function testFlushOnLazyLoaded() + public function testFlushOnLazyLoaded(): void { $proxyClient = \Mockery::mock(HttpProxyClient::class, LazyObjectInterface::class, PurgeCapable::class); $proxyClient->shouldReceive('flush')->andReturn(1); diff --git a/tests/Unit/Command/BaseInvalidateCommandTest.php b/tests/Unit/Command/BaseInvalidateCommandTest.php index 472c0a6b..273c722c 100644 --- a/tests/Unit/Command/BaseInvalidateCommandTest.php +++ b/tests/Unit/Command/BaseInvalidateCommandTest.php @@ -25,7 +25,7 @@ class BaseInvalidateCommandTest extends TestCase /** * @group legacy */ - public function testContainerAccess() + public function testContainerAccess(): void { $invalidator = \Mockery::mock(CacheManager::class) ->shouldReceive('invalidatePath')->once()->with('/my/path') diff --git a/tests/Unit/Command/ClearCommandTest.php b/tests/Unit/Command/ClearCommandTest.php index 3bef349f..7da0e2bf 100644 --- a/tests/Unit/Command/ClearCommandTest.php +++ b/tests/Unit/Command/ClearCommandTest.php @@ -23,7 +23,7 @@ class ClearCommandTest extends TestCase { use MockeryPHPUnitIntegration; - public function testExecuteClear() + public function testExecuteClear(): void { $invalidator = \Mockery::mock(CacheManager::class) ->shouldReceive('supports')->once()->with(CacheInvalidator::CLEAR)->andReturnTrue() @@ -44,7 +44,7 @@ public function testExecuteClear() $this->assertEquals('', $commandTester->getDisplay()); } - public function testExecuteInvalidate() + public function testExecuteInvalidate(): void { $invalidator = \Mockery::mock(CacheManager::class) ->shouldReceive('supports')->once()->with(CacheInvalidator::CLEAR)->andReturnFalse() @@ -66,7 +66,7 @@ public function testExecuteInvalidate() $this->assertEquals('', $commandTester->getDisplay()); } - public function testExecuteNotSupported() + public function testExecuteNotSupported(): void { $invalidator = \Mockery::mock(CacheManager::class) ->shouldReceive('supports')->once()->with(CacheInvalidator::CLEAR)->andReturnFalse() diff --git a/tests/Unit/Command/InvalidatePathCommandTest.php b/tests/Unit/Command/InvalidatePathCommandTest.php index acc928db..99b37d41 100644 --- a/tests/Unit/Command/InvalidatePathCommandTest.php +++ b/tests/Unit/Command/InvalidatePathCommandTest.php @@ -22,7 +22,7 @@ class InvalidatePathCommandTest extends TestCase { use MockeryPHPUnitIntegration; - public function testExecuteMissingParameters() + public function testExecuteMissingParameters(): void { $this->expectException(\RuntimeException::class); @@ -36,7 +36,7 @@ public function testExecuteMissingParameters() $commandTester->execute(['command' => $command->getName()]); } - public function testExecuteParameter() + public function testExecuteParameter(): void { $invalidator = \Mockery::mock(CacheManager::class) ->shouldReceive('invalidatePath')->once()->with('/my/path') diff --git a/tests/Unit/Command/InvalidateRegexCommandTest.php b/tests/Unit/Command/InvalidateRegexCommandTest.php index b48f8cc4..6a78b454 100644 --- a/tests/Unit/Command/InvalidateRegexCommandTest.php +++ b/tests/Unit/Command/InvalidateRegexCommandTest.php @@ -22,7 +22,7 @@ class InvalidateRegexCommandTest extends TestCase { use MockeryPHPUnitIntegration; - public function testExecuteNoParameters() + public function testExecuteNoParameters(): void { $this->expectException(\RuntimeException::class); @@ -36,7 +36,7 @@ public function testExecuteNoParameters() $commandTester->execute(['command' => $command->getName()]); } - public function testExecuteParameter() + public function testExecuteParameter(): void { $invalidator = \Mockery::mock(CacheManager::class) ->shouldReceive('invalidateRegex')->once()->with('/my.*/path') diff --git a/tests/Unit/Command/InvalidateTagCommandTest.php b/tests/Unit/Command/InvalidateTagCommandTest.php index d79fc27f..97478147 100644 --- a/tests/Unit/Command/InvalidateTagCommandTest.php +++ b/tests/Unit/Command/InvalidateTagCommandTest.php @@ -22,7 +22,7 @@ class InvalidateTagCommandTest extends TestCase { use MockeryPHPUnitIntegration; - public function testExecuteMissingParameters() + public function testExecuteMissingParameters(): void { $this->expectException(\RuntimeException::class); @@ -36,7 +36,7 @@ public function testExecuteMissingParameters() $commandTester->execute(['command' => $command->getName()]); } - public function testExecuteParameter() + public function testExecuteParameter(): void { $invalidator = \Mockery::mock(CacheManager::class) ->shouldReceive('invalidateTags')->once()->with(['my-tag']) diff --git a/tests/Unit/Command/RefreshPathCommandTest.php b/tests/Unit/Command/RefreshPathCommandTest.php index d0ad181e..05595284 100644 --- a/tests/Unit/Command/RefreshPathCommandTest.php +++ b/tests/Unit/Command/RefreshPathCommandTest.php @@ -22,7 +22,7 @@ class RefreshPathCommandTest extends TestCase { use MockeryPHPUnitIntegration; - public function testExecuteMissingParameters() + public function testExecuteMissingParameters(): void { $this->expectException(\RuntimeException::class); @@ -36,7 +36,7 @@ public function testExecuteMissingParameters() $commandTester->execute(['command' => $command->getName()]); } - public function testExecuteParameter() + public function testExecuteParameter(): void { $invalidator = \Mockery::mock(CacheManager::class) ->shouldReceive('refreshPath')->once()->with('/my/path') diff --git a/tests/Unit/EventListener/CacheControlListenerTest.php b/tests/Unit/EventListener/CacheControlListenerTest.php index b56fd556..cb9748ff 100755 --- a/tests/Unit/EventListener/CacheControlListenerTest.php +++ b/tests/Unit/EventListener/CacheControlListenerTest.php @@ -25,7 +25,7 @@ class CacheControlListenerTest extends TestCase { use MockeryPHPUnitIntegration; - public function testDefaultHeaders() + public function testDefaultHeaders(): void { $event = $this->buildEvent(); $headers = [ @@ -48,7 +48,7 @@ public function testDefaultHeaders() $this->assertEquals(strtotime('13.07.2003'), strtotime($newHeaders['last-modified'][0])); } - public function testEtagStrong() + public function testEtagStrong(): void { $event = $this->buildEvent(); $headers = [ @@ -63,7 +63,7 @@ public function testEtagStrong() $this->assertEquals('"d41d8cd98f00b204e9800998ecf8427e"', $newHeaders['etag'][0]); } - public function testEtagWeak() + public function testEtagWeak(): void { $event = $this->buildEvent(); $headers = [ @@ -78,7 +78,7 @@ public function testEtagWeak() $this->assertEquals('W/"d41d8cd98f00b204e9800998ecf8427e"', $newHeaders['etag'][0]); } - public function testExtraHeaders() + public function testExtraHeaders(): void { $event = $this->buildEvent(); $headers = [ @@ -99,7 +99,7 @@ public function testExtraHeaders() $this->assertEquals('must-revalidate, no-transform, proxy-revalidate, stale-if-error=300, stale-while-revalidate=400, private', $newHeaders['cache-control'][0]); } - public function testCompoundHeaders() + public function testCompoundHeaders(): void { $event = $this->buildEvent(); $headers = [ @@ -124,7 +124,7 @@ public function testCompoundHeaders() $this->assertEquals('max-age=900, must-revalidate, no-transform, proxy-revalidate, public, s-maxage=300, stale-if-error=300, stale-while-revalidate=400', $newHeaders['cache-control'][0]); } - public function testSetNoCacheHeaders() + public function testSetNoCacheHeaders(): void { $event = $this->buildEvent(); $headers = [ @@ -147,7 +147,7 @@ public function testSetNoCacheHeaders() $this->assertEquals('max-age=0, must-revalidate, no-cache, no-store, private, s-maxage=0', $newHeaders['cache-control'][0]); } - public function testMergeHeaders() + public function testMergeHeaders(): void { $event = $this->buildEvent(); $headers = [ @@ -187,7 +187,7 @@ public function testMergeHeaders() $this->assertEquals('Mon, 09 Sep 2013 00:00:00 GMT', $newHeaders['last-modified'][0]); } - public function testOverwriteHeaders() + public function testOverwriteHeaders(): void { $event = $this->buildEvent(); $headers = [ @@ -227,7 +227,7 @@ public function testOverwriteHeaders() $this->assertEquals('Fri, 10 Oct 2014 00:00:00 GMT', $newHeaders['last-modified'][0]); } - public function testMergePublicPrivate() + public function testMergePublicPrivate(): void { $event = $this->buildEvent(); $headers = [ @@ -249,7 +249,7 @@ public function testMergePublicPrivate() /** * The no_cache header is never actually called as its already set. */ - public function testSetOnlyNoCacheHeader() + public function testSetOnlyNoCacheHeader(): void { $event = $this->buildEvent(); $headers = [ @@ -266,7 +266,7 @@ public function testSetOnlyNoCacheHeader() $this->assertStringContainsString('no-cache', $newHeaders['cache-control'][0]); } - public function testSetOnlyNoStoreHeader() + public function testSetOnlyNoStoreHeader(): void { $event = $this->buildEvent(); $headers = [ @@ -283,7 +283,7 @@ public function testSetOnlyNoStoreHeader() $this->assertStringContainsString('no-store', $newHeaders['cache-control'][0]); } - public function testSkip() + public function testSkip(): void { $event = $this->buildEvent(); $listener = new CacheControlListener(); @@ -299,7 +299,7 @@ public function testSkip() $this->assertStringContainsString('no-cache', $newHeaders['cache-control'][0]); } - public function testVary() + public function testVary(): void { $event = $this->buildEvent(); $headers = [ @@ -319,7 +319,7 @@ public function testVary() $this->assertEquals($headers['vary'], $newHeaders['vary']); } - public function testReverseProxyTtl() + public function testReverseProxyTtl(): void { $event = $this->buildEvent(); $headers = [ @@ -334,7 +334,7 @@ public function testReverseProxyTtl() $this->assertEquals(600, $newHeaders['x-reverse-proxy-ttl'][0]); } - public function testDebugHeader() + public function testDebugHeader(): void { $listener = new CacheControlListener('X-Cache-Debug'); $matcher = \Mockery::mock(RuleMatcherInterface::class) @@ -350,7 +350,7 @@ public function testDebugHeader() $this->assertTrue(isset($newHeaders['x-cache-debug'][0])); } - public function testMatchRule() + public function testMatchRule(): void { $event = $this->buildEvent(); $request = $event->getRequest(); @@ -393,7 +393,7 @@ public function testMatchRule() /** * Unsafe methods should abort before even attempting to match rules. */ - public function testUnsafeMethod() + public function testUnsafeMethod(): void { $listener = new CacheControlListener(); $matcher = \Mockery::mock(RuleMatcherInterface::class) diff --git a/tests/Unit/EventListener/InvalidationListenerTest.php b/tests/Unit/EventListener/InvalidationListenerTest.php index 7a151482..e5fdeb30 100644 --- a/tests/Unit/EventListener/InvalidationListenerTest.php +++ b/tests/Unit/EventListener/InvalidationListenerTest.php @@ -34,25 +34,10 @@ class InvalidationListenerTest extends TestCase { use MockeryPHPUnitIntegration; - /** - * @var CacheManager|MockInterface - */ - private $cacheManager; - - /** - * @var UrlGeneratorInterface|MockInterface - */ - private $urlGenerator; - - /** - * @var RuleMatcherInterface|MockInterface - */ - private $mustInvalidateRule; - - /** - * @var InvalidationListener - */ - private $listener; + private CacheManager&MockInterface $cacheManager; + private UrlGeneratorInterface&MockInterface $urlGenerator; + private RuleMatcherInterface&MockInterface $mustInvalidateRule; + private InvalidationListener $listener; public function setUp(): void { @@ -70,7 +55,7 @@ public function setUp(): void ); } - public function testNoRoutesInvalidatedWhenResponseIsUnsuccessful() + public function testNoRoutesInvalidatedWhenResponseIsUnsuccessful(): void { $this->cacheManager ->shouldReceive('invalidateRoute')->never() @@ -83,7 +68,7 @@ public function testNoRoutesInvalidatedWhenResponseIsUnsuccessful() $this->listener->onKernelTerminate($event); } - public function testOnKernelTerminate() + public function testOnKernelTerminate(): void { $this->cacheManager ->shouldReceive('invalidatePath')->with('/retrieve/something/123') @@ -125,14 +110,14 @@ public function testOnKernelTerminate() $this->listener->onKernelTerminate($event); } - public function testOnKernelException() + public function testOnKernelException(): void { $this->cacheManager->shouldReceive('flush')->once(); $event = $this->getEvent(new Request()); $this->listener->onKernelException($event); } - public function testInvalidatePath() + public function testInvalidatePath(): void { $request = Request::create('', 'PUT'); $request->attributes->set('_invalidate_path', [ @@ -151,7 +136,7 @@ public function testInvalidatePath() $this->listener->onKernelTerminate($event); } - public function testInvalidateRoute() + public function testInvalidateRoute(): void { $request = Request::create('', 'POST'); $request->attributes->set('request_id', 123); @@ -170,7 +155,7 @@ public function testInvalidateRoute() $this->listener->onKernelTerminate($event); } - public function testOnConsoleTerminate() + public function testOnConsoleTerminate(): void { $this->cacheManager->shouldReceive('flush')->once()->andReturn(2); @@ -191,7 +176,7 @@ protected function getEvent(Request $request, ?Response $response = null): Termi return new TerminateEvent( \Mockery::mock(HttpKernelInterface::class), $request, - null !== $response ? $response : new Response() + $response ?? new Response() ); } } diff --git a/tests/Unit/EventListener/UserContextListenerTest.php b/tests/Unit/EventListener/UserContextListenerTest.php index 22b1215e..d509853a 100644 --- a/tests/Unit/EventListener/UserContextListenerTest.php +++ b/tests/Unit/EventListener/UserContextListenerTest.php @@ -15,6 +15,7 @@ use FOS\HttpCache\UserContext\HashGenerator; use FOS\HttpCacheBundle\EventListener\UserContextListener; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; +use Mockery\MockInterface; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcherInterface; @@ -28,7 +29,7 @@ class UserContextListenerTest extends TestCase { use MockeryPHPUnitIntegration; - public function testMisconfiguration() + public function testMisconfiguration(): void { $this->expectException(\InvalidArgumentException::class); @@ -43,7 +44,7 @@ public function testMisconfiguration() ); } - public function testOnKernelRequest() + public function testOnKernelRequest(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -77,7 +78,7 @@ public function testOnKernelRequest() $this->assertEquals('max-age=0, no-cache, private', $response->headers->get('Cache-Control')); } - public function testOnKernelRequestNonMaster() + public function testOnKernelRequestNonMaster(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -105,7 +106,7 @@ public function testOnKernelRequestNonMaster() $this->assertNull($event->getResponse()); } - public function testOnKernelRequestCached() + public function testOnKernelRequestCached(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -140,7 +141,7 @@ public function testOnKernelRequestCached() $this->assertEquals('max-age=30, public', $response->headers->get('Cache-Control')); } - public function testOnKernelRequestNotMatched() + public function testOnKernelRequestNotMatched(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -170,7 +171,7 @@ public function testOnKernelRequestNotMatched() $this->assertNull($response); } - public function testOnKernelRequestNotMatchedHasHeader() + public function testOnKernelRequestNotMatchedHasHeader(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -205,7 +206,7 @@ public function testOnKernelRequestNotMatchedHasHeader() $this->assertNull($response); } - public function testOnKernelResponse() + public function testOnKernelResponse(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -235,7 +236,7 @@ public function testOnKernelResponse() $this->assertStringContainsString('X-Hash', $event->getResponse()->headers->get('Vary')); } - public function testOnKernelResponseSetsNoAutoCacheHeader() + public function testOnKernelResponseSetsNoAutoCacheHeader(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -256,7 +257,7 @@ public function testOnKernelResponseSetsNoAutoCacheHeader() $this->assertEquals(1, $event->getResponse()->headers->get(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER)); } - public function testOnKernelResponseDoesNotSetNoAutoCacheHeaderWhenNoSessionListener() + public function testOnKernelResponseDoesNotSetNoAutoCacheHeaderWhenNoSessionListener(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -281,7 +282,7 @@ public function testOnKernelResponseDoesNotSetNoAutoCacheHeaderWhenNoSessionList $this->assertFalse($event->getResponse()->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER)); } - public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeader() + public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeader(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -301,7 +302,7 @@ public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeader() $this->assertEquals(1, $event->getResponse()->headers->get(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER)); } - public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeaderAndNoAddVaryOnHash() + public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeaderAndNoAddVaryOnHash(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -326,7 +327,7 @@ public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeaderAndNoAd $this->assertEquals(1, $event->getResponse()->headers->get(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER)); } - public function testOnKernelResponseDoesNotSetNoAutoCacheHeaderWhenNoCustomHeaderAndNoAddVaryOnHash() + public function testOnKernelResponseDoesNotSetNoAutoCacheHeaderWhenNoCustomHeaderAndNoAddVaryOnHash(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -351,7 +352,7 @@ public function testOnKernelResponseDoesNotSetNoAutoCacheHeaderWhenNoCustomHeade $this->assertFalse($event->getResponse()->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER)); } - public function testOnKernelResponseNotMaster() + public function testOnKernelResponseNotMaster(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -381,7 +382,7 @@ public function testOnKernelResponseNotMaster() /** * If there is no hash in the request, vary on the user identifier. */ - public function testOnKernelResponseNotCached() + public function testOnKernelResponseNotCached(): void { $request = new Request(); $request->setMethod('HEAD'); @@ -410,7 +411,7 @@ public function testOnKernelResponseNotCached() /** * If there is no hash in the request, vary on the user identifier. */ - public function testFullRequestHashOk() + public function testFullRequestHashOk(): void { $request = new Request(); $request->setMethod('GET'); @@ -451,7 +452,7 @@ public function testFullRequestHashOk() /** * If the request is an anonymous one, no hash should be generated/validated. */ - public function testFullAnonymousRequestHashNotGenerated() + public function testFullAnonymousRequestHashNotGenerated(): void { $request = new Request(); $request->setMethod('GET'); @@ -495,7 +496,7 @@ public function testFullAnonymousRequestHashNotGenerated() /** * If there is no hash in the requests but session changed, prevent setting bad cache. */ - public function testFullRequestHashChanged() + public function testFullRequestHashChanged(): void { $request = new Request(); $request->setMethod('GET'); @@ -553,12 +554,7 @@ protected function getKernelResponseEvent(Request $request, ?Response $response ); } - /** - * @param bool $match - * - * @return \Mockery\MockInterface|RequestMatcherInterface - */ - private function getRequestMatcher(Request $request, $match) + private function getRequestMatcher(Request $request, bool $match): MockInterface&RequestMatcherInterface { $requestMatcher = \Mockery::mock(RequestMatcherInterface::class); $requestMatcher->shouldReceive('matches')->with($request)->andReturn($match); diff --git a/tests/Unit/Http/ResponseMatcher/ExpressionResponseMatcherTest.php b/tests/Unit/Http/ResponseMatcher/ExpressionResponseMatcherTest.php index c4a89daf..3be76884 100644 --- a/tests/Unit/Http/ResponseMatcher/ExpressionResponseMatcherTest.php +++ b/tests/Unit/Http/ResponseMatcher/ExpressionResponseMatcherTest.php @@ -21,7 +21,7 @@ class ExpressionResponseMatcherTest extends TestCase { use MockeryPHPUnitIntegration; - public function testExpressionMatch() + public function testExpressionMatch(): void { $matcher = new ExpressionResponseMatcher('response.getStatusCode() === 200'); @@ -32,7 +32,7 @@ public function testExpressionMatch() $this->assertFalse($matcher->matches($response)); } - public function testCustomExpressionLanguage() + public function testCustomExpressionLanguage(): void { $response = new Response('', 500); $el = \Mockery::mock(ExpressionLanguage::class) diff --git a/tests/Unit/Http/ResponseMatcher/NonErrorResponseMatcherTest.php b/tests/Unit/Http/ResponseMatcher/NonErrorResponseMatcherTest.php index a31ec8ad..952162a1 100644 --- a/tests/Unit/Http/ResponseMatcher/NonErrorResponseMatcherTest.php +++ b/tests/Unit/Http/ResponseMatcher/NonErrorResponseMatcherTest.php @@ -17,7 +17,7 @@ class NonErrorResponseMatcherTest extends TestCase { - public function testSuccess() + public function testSuccess(): void { $matcher = new NonErrorResponseMatcher(); @@ -28,7 +28,7 @@ public function testSuccess() $this->assertTrue($matcher->matches($response)); } - public function testError() + public function testError(): void { $matcher = new NonErrorResponseMatcher(); diff --git a/tests/Unit/Http/RuleMatcherTest.php b/tests/Unit/Http/RuleMatcherTest.php index fb682d29..8302431d 100644 --- a/tests/Unit/Http/RuleMatcherTest.php +++ b/tests/Unit/Http/RuleMatcherTest.php @@ -20,7 +20,7 @@ class RuleMatcherTest extends TestCase { - public function testRequestMatcherCalled() + public function testRequestMatcherCalled(): void { $requestMatcher = new AttributesRequestMatcher(['_controller' => '^AcmeBundle:Default:index$']); $ruleMatcher = new RuleMatcher($requestMatcher); @@ -31,7 +31,7 @@ public function testRequestMatcherCalled() $this->assertTrue($ruleMatcher->matches($request, new Response())); } - public function testAdditionalCacheableStatus() + public function testAdditionalCacheableStatus(): void { $ruleMatcher = new RuleMatcher(new AttributesRequestMatcher([]), new CacheableResponseMatcher([400, 500])); diff --git a/tests/Unit/Http/SymfonyResponseTaggerTest.php b/tests/Unit/Http/SymfonyResponseTaggerTest.php index 6c2afd2e..1be79055 100644 --- a/tests/Unit/Http/SymfonyResponseTaggerTest.php +++ b/tests/Unit/Http/SymfonyResponseTaggerTest.php @@ -17,7 +17,7 @@ class SymfonyResponseTaggerTest extends TestCase { - public function testTagResponse() + public function testTagResponse(): void { $tags1 = ['post-1', 'posts']; $tags2 = ['post-2']; diff --git a/tests/Unit/UserContext/RequestMatcherTest.php b/tests/Unit/UserContext/RequestMatcherTest.php index 301edc62..15acaae2 100644 --- a/tests/Unit/UserContext/RequestMatcherTest.php +++ b/tests/Unit/UserContext/RequestMatcherTest.php @@ -20,7 +20,7 @@ class RequestMatcherTest extends TestCase { use MockeryPHPUnitIntegration; - public function testMatch() + public function testMatch(): void { $requestMatcher = new RequestMatcher('application/vnd.test', 'HEAD'); @@ -39,7 +39,7 @@ public function testMatch() $this->assertTrue($requestMatcher->matches($request)); } - public function testNoMatch() + public function testNoMatch(): void { $requestMatcher = new RequestMatcher('application/vnd.test', 'HEAD'); diff --git a/tests/Unit/UserContext/RoleProviderTest.php b/tests/Unit/UserContext/RoleProviderTest.php index 1cf6796f..f9f7694f 100644 --- a/tests/Unit/UserContext/RoleProviderTest.php +++ b/tests/Unit/UserContext/RoleProviderTest.php @@ -23,7 +23,7 @@ class RoleProviderTest extends TestCase { use MockeryPHPUnitIntegration; - public function testProvider() + public function testProvider(): void { $token = \Mockery::mock(TokenInterface::class); $token->shouldReceive('getRoleNames')->andReturn(['ROLE_USER']); @@ -42,7 +42,7 @@ public function testProvider() ], $userContext->getParameters()); } - public function testNotUnderFirewall() + public function testNotUnderFirewall(): void { $this->expectException(InvalidConfigurationException::class);