From 7cc8f5c4ee7c6bff8220801a6170b9ed8bbba3e6 Mon Sep 17 00:00:00 2001 From: Damien Harper Date: Thu, 14 Nov 2019 23:08:42 +0100 Subject: [PATCH] Fixes deprecation warning (#17) Also drops support for PHP 5.x --- .travis.yml | 8 ----- composer.json | 2 +- src/Command/ResetCommand.php | 2 -- src/DependencyInjection/Configuration.php | 17 +++++----- .../MabaGentleForceExtension.php | 33 ++++++++----------- .../StrategyValidationCompilerPass.php | 10 ++---- src/Listener/CompositeIncreaseResult.php | 1 - src/Listener/ConfigurationManager.php | 4 +-- src/Listener/IdentifierHelper.php | 2 +- src/Listener/ListenerConfiguration.php | 4 --- src/Listener/RequestListener.php | 1 - src/Listener/RequestMatcher.php | 8 ++--- src/Service/IdentifierBuilder.php | 1 - .../IdentifierProviderInterface.php | 2 -- src/Service/RequestIdentifierProvider.php | 8 ++--- .../ResponseModifyingStrategyInterface.php | 3 -- src/Service/Strategy/LogStrategy.php | 1 - .../Strategy/RecaptchaHeadersStrategy.php | 2 -- .../Strategy/RecaptchaTemplateStrategy.php | 3 -- src/Service/StrategyInterface.php | 1 - src/Service/StrategyManager.php | 9 ++--- .../ResponseCodeSuccessMatcher.php | 4 +-- src/Service/SuccessMatcherInterface.php | 1 - tests/Functional/Fixtures/TestKernel.php | 2 +- tests/Unit/Listener/RequestMatcherTest.php | 3 +- .../Service/Strategy/HeadersStrategyTest.php | 4 +-- 26 files changed, 40 insertions(+), 96 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5943684..318baf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,10 +12,6 @@ env: matrix: include: - - php: 5.5 - env: COMPOSER_ARGS="" - - php: 5.6 - env: COMPOSER_ARGS="" - php: 7.0 env: COMPOSER_ARGS="" - php: 7.1 @@ -25,10 +21,6 @@ matrix: - php: 7.3 env: COMPOSER_ARGS="" WITH_CS="true" - - php: 5.5 - env: COMPOSER_ARGS="--prefer-lowest" - - php: 5.6 - env: COMPOSER_ARGS="--prefer-lowest" - php: 7.0 env: COMPOSER_ARGS="--prefer-lowest" - php: 7.1 diff --git a/composer.json b/composer.json index 21403bb..f849d4b 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "keywords": ["symfony bundle", "rate limiter", "rate limiting", "rate limit", "brute force protection", "leaky bucket", "token bucket", "threshold", "throttle", "security", "dos protection", "brute-force", "bruteforce"], "type": "symfony-bundle", "require": { - "php": "^5.5|^7.0", + "php": "^7.0", "maba/gentle-force": "^0.2.1|^0.3", "symfony/framework-bundle": "^2.7.50|^3.0|^4.0", "maba/dependency-injection-extra": "^0.1.1|^1.0", diff --git a/src/Command/ResetCommand.php b/src/Command/ResetCommand.php index af4bdb9..f41268e 100644 --- a/src/Command/ResetCommand.php +++ b/src/Command/ResetCommand.php @@ -68,8 +68,6 @@ protected function execute(InputInterface $input, OutputInterface $output) } /** - * @param InputInterface $input - * @param OutputInterface $output * @param ListenerConfiguration[] $configurationList * @return ListenerConfiguration */ diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index b26769a..2973d40 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -12,8 +12,9 @@ class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('maba_gentle_force'); + $treeBuilder = new TreeBuilder('maba_gentle_force'); + // Keep compatibility with symfony/config < 4.2 + $rootNode = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('maba_gentle_force'); $children = $rootNode->children(); @@ -51,14 +52,14 @@ private function configureRedis(ArrayNodeDefinition $node) $node->validate()->ifTrue(function ($nodeConfig) { if (isset($nodeConfig['host'])) { return isset($nodeConfig['service_id']) - || (isset($nodeConfig['parameters']) && count($nodeConfig['parameters']) > 0) + || (isset($nodeConfig['parameters']) && \count($nodeConfig['parameters']) > 0) || isset($nodeConfig['options']) ; } if (isset($nodeConfig['service_id'])) { return isset($nodeConfig['host']) - || (isset($nodeConfig['parameters']) && count($nodeConfig['parameters']) > 0) + || (isset($nodeConfig['parameters']) && \count($nodeConfig['parameters']) > 0) || isset($nodeConfig['options']) ; } @@ -160,9 +161,7 @@ private function buildStatusesNode(NodeBuilder $node, $name) 'max_range' => 599, ]]); if ($validatedStatusCode === false) { - throw new InvalidConfigurationException( - sprintf('Status code %s is invalid', $statusCode) - ); + throw new InvalidConfigurationException(sprintf('Status code %s is invalid', $statusCode)); } return $validatedStatusCode; @@ -177,10 +176,10 @@ private function addSuccessMatcherValidation(ArrayNodeDefinition $node) if (isset($configuration['success_matcher'])) { $count++; } - if (count($configuration['success_statuses']) > 0) { + if (\count($configuration['success_statuses']) > 0) { $count++; } - if (count($configuration['failure_statuses']) > 0) { + if (\count($configuration['failure_statuses']) > 0) { $count++; } diff --git a/src/DependencyInjection/MabaGentleForceExtension.php b/src/DependencyInjection/MabaGentleForceExtension.php index 1c16fcb..67d6fbc 100644 --- a/src/DependencyInjection/MabaGentleForceExtension.php +++ b/src/DependencyInjection/MabaGentleForceExtension.php @@ -8,12 +8,12 @@ use Maba\GentleForce\RateLimitProvider; use Predis\Client; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\HttpKernel\KernelEvents; class MabaGentleForceExtension extends Extension @@ -96,7 +96,7 @@ private function registerRedisClient(ContainerBuilder $container, XmlFileLoader if (isset($redisConfig['host'])) { $parameters = ['host' => $redisConfig['host']]; - } elseif (isset($redisConfig['parameters']) && count($redisConfig['parameters']) > 0) { + } elseif (isset($redisConfig['parameters']) && \count($redisConfig['parameters']) > 0) { $parameters = $redisConfig['parameters']; $options = $redisConfig['options']; } @@ -114,7 +114,7 @@ private function registerListeners( $strategiesConfiguration = $config['strategies']; $availableLimitsKeys = array_keys($config['limits']); - if (count($listenerConfigList) === 0) { + if (\count($listenerConfigList) === 0) { return; } @@ -136,11 +136,8 @@ private function registerListeners( $usedStrategies[] = $strategyId; $limitsKey = $listenerConfig['limits_key']; - if (!in_array($limitsKey, $availableLimitsKeys, true)) { - throw new InvalidConfigurationException(sprintf( - 'Specified limits_key (%s) is not registered', - $limitsKey - )); + if (!\in_array($limitsKey, $availableLimitsKeys, true)) { + throw new InvalidConfigurationException(sprintf('Specified limits_key (%s) is not registered', $limitsKey)); } $pathPattern = '#' . str_replace('#', '\\#', $listenerConfig['path']) . '#'; @@ -170,14 +167,14 @@ private function buildSuccessMatcher(array $listenerConfig) return new Reference($listenerConfig['success_matcher']); } - if (count($listenerConfig['success_statuses']) > 0) { + if (\count($listenerConfig['success_statuses']) > 0) { return new Definition( ResponseCodeSuccessMatcher::class, [$listenerConfig['success_statuses']] ); } - if (count($listenerConfig['failure_statuses']) > 0) { + if (\count($listenerConfig['failure_statuses']) > 0) { return new Definition( ResponseCodeSuccessMatcher::class, [$listenerConfig['failure_statuses'], true] @@ -205,30 +202,26 @@ private function includeStrategyDefinitions( array $usedStrategies, array $config ) { - if (in_array('maba_gentle_force.strategy.log', $usedStrategies, true)) { + if (\in_array('maba_gentle_force.strategy.log', $usedStrategies, true)) { $loader->load('log_strategy.xml'); } $recaptchaNeeded = false; - if (in_array('maba_gentle_force.strategy.recaptcha_headers', $usedStrategies, true)) { + if (\in_array('maba_gentle_force.strategy.recaptcha_headers', $usedStrategies, true)) { $loader->load('recaptcha/headers.xml'); $recaptchaNeeded = true; } - if (in_array('maba_gentle_force.strategy.recaptcha_template', $usedStrategies, true)) { + if (\in_array('maba_gentle_force.strategy.recaptcha_template', $usedStrategies, true)) { $loader->load('recaptcha/template.xml'); $recaptchaNeeded = true; } if ($recaptchaNeeded) { if (!isset($config['recaptcha'])) { - throw new InvalidConfigurationException( - 'You need to configure "recaptcha" node to use any of recaptcha_* strategies' - ); + throw new InvalidConfigurationException('You need to configure "recaptcha" node to use any of recaptcha_* strategies'); } if (!class_exists('ReCaptcha\ReCaptcha')) { - throw new InvalidConfigurationException( - 'You need to install "google/recaptcha" library to use any of recaptcha_* strategies' - ); + throw new InvalidConfigurationException('You need to install "google/recaptcha" library to use any of recaptcha_* strategies'); } $loader->load('recaptcha/main.xml'); diff --git a/src/DependencyInjection/StrategyValidationCompilerPass.php b/src/DependencyInjection/StrategyValidationCompilerPass.php index 548206b..49f88e7 100644 --- a/src/DependencyInjection/StrategyValidationCompilerPass.php +++ b/src/DependencyInjection/StrategyValidationCompilerPass.php @@ -18,18 +18,12 @@ public function process(ContainerBuilder $container) foreach ($strategyIdList as $strategyId) { if (!$container->hasDefinition($strategyId)) { - throw new InvalidConfigurationException(sprintf( - 'Gentle force strategy "%s" does not exist in service container', - $strategyId - )); + throw new InvalidConfigurationException(sprintf('Gentle force strategy "%s" does not exist in service container', $strategyId)); } $definition = $container->getDefinition($strategyId); if (!$definition->isPublic()) { - throw new InvalidConfigurationException(sprintf( - 'Service "%s" must be public as this is required for gentle force strategies', - $strategyId - )); + throw new InvalidConfigurationException(sprintf('Service "%s" must be public as this is required for gentle force strategies', $strategyId)); } } } diff --git a/src/Listener/CompositeIncreaseResult.php b/src/Listener/CompositeIncreaseResult.php index d8d6283..ac1fd44 100644 --- a/src/Listener/CompositeIncreaseResult.php +++ b/src/Listener/CompositeIncreaseResult.php @@ -95,7 +95,6 @@ public function getConfigurations() } /** - * @param ListenerConfiguration $configuration * @return IncreaseResult */ public function getResultByConfiguration(ListenerConfiguration $configuration) diff --git a/src/Listener/ConfigurationManager.php b/src/Listener/ConfigurationManager.php index 62d1552..6698f12 100644 --- a/src/Listener/ConfigurationManager.php +++ b/src/Listener/ConfigurationManager.php @@ -67,7 +67,7 @@ private function isWhitelisted($request) { $controller = $request->attributes->get('_controller'); - return $controller !== null && in_array($controller, $this->whitelistedControllers, true); + return $controller !== null && \in_array($controller, $this->whitelistedControllers, true); } private function checkAndIncrease( @@ -99,7 +99,7 @@ public function resetForStrategies(Request $request, array $strategyList) $identifierHelper = $this->createIdentifierHelper($request); foreach ($this->configurationRegistry->getConfigurationList() as $configuration) { - if (in_array($configuration->getStrategyId(), $strategyList, true)) { + if (\in_array($configuration->getStrategyId(), $strategyList, true)) { $this->reset($identifierHelper, $configuration); } } diff --git a/src/Listener/IdentifierHelper.php b/src/Listener/IdentifierHelper.php index 22bff6f..6424393 100644 --- a/src/Listener/IdentifierHelper.php +++ b/src/Listener/IdentifierHelper.php @@ -41,7 +41,7 @@ public function getIdentifier(ListenerConfiguration $configuration) private function getConcreteIdentifierByType($identifierType) { - if (array_key_exists($identifierType, $this->identifiers)) { + if (\array_key_exists($identifierType, $this->identifiers)) { return $this->identifiers[$identifierType]; } diff --git a/src/Listener/ListenerConfiguration.php b/src/Listener/ListenerConfiguration.php index 48dc138..a24c0ad 100644 --- a/src/Listener/ListenerConfiguration.php +++ b/src/Listener/ListenerConfiguration.php @@ -69,7 +69,6 @@ public function getHosts() } /** - * @param array $hosts * @return $this */ public function setHosts(array $hosts) @@ -88,7 +87,6 @@ public function getMethods() } /** - * @param array $methods * @return $this */ public function setMethods(array $methods) @@ -126,7 +124,6 @@ public function getIdentifierTypes() } /** - * @param array $identifierTypes * @return $this */ public function setIdentifierTypes(array $identifierTypes) @@ -164,7 +161,6 @@ public function getSuccessMatcher() } /** - * @param SuccessMatcherInterface|null $successMatcher * @return $this */ public function setSuccessMatcher(SuccessMatcherInterface $successMatcher = null) diff --git a/src/Listener/RequestListener.php b/src/Listener/RequestListener.php index 6da6fe2..ee184c8 100644 --- a/src/Listener/RequestListener.php +++ b/src/Listener/RequestListener.php @@ -93,7 +93,6 @@ public function onRequestFinished(FinishRequestEvent $event) } /** - * @param Request $request * @return CompositeIncreaseResult|null */ private function getAndRemoveCompositeResult(Request $request) diff --git a/src/Listener/RequestMatcher.php b/src/Listener/RequestMatcher.php index 7650ddc..9b4f5c8 100644 --- a/src/Listener/RequestMatcher.php +++ b/src/Listener/RequestMatcher.php @@ -12,11 +12,11 @@ public function matches(ListenerConfiguration $configuration, Request $request) return false; } - if (count($configuration->getMethods()) > 0 && !$this->methodMatches($configuration, $request)) { + if (\count($configuration->getMethods()) > 0 && !$this->methodMatches($configuration, $request)) { return false; } - if (count($configuration->getHosts()) > 0 && !$this->hostMatches($configuration, $request)) { + if (\count($configuration->getHosts()) > 0 && !$this->hostMatches($configuration, $request)) { return false; } @@ -30,11 +30,11 @@ private function pathMatches(ListenerConfiguration $configuration, Request $requ private function methodMatches(ListenerConfiguration $configuration, Request $request) { - return in_array($request->getMethod(), $configuration->getMethods(), true); + return \in_array($request->getMethod(), $configuration->getMethods(), true); } private function hostMatches(ListenerConfiguration $configuration, Request $request) { - return in_array(strtolower($request->getHost()), $configuration->getHosts(), true); + return \in_array(strtolower($request->getHost()), $configuration->getHosts(), true); } } diff --git a/src/Service/IdentifierBuilder.php b/src/Service/IdentifierBuilder.php index ce29c35..28c87e4 100644 --- a/src/Service/IdentifierBuilder.php +++ b/src/Service/IdentifierBuilder.php @@ -5,7 +5,6 @@ class IdentifierBuilder { /** - * @param array $identifiers * @return string * * @api diff --git a/src/Service/IdentifierProvider/IdentifierProviderInterface.php b/src/Service/IdentifierProvider/IdentifierProviderInterface.php index 79b12b2..0a5a0f2 100644 --- a/src/Service/IdentifierProvider/IdentifierProviderInterface.php +++ b/src/Service/IdentifierProvider/IdentifierProviderInterface.php @@ -10,8 +10,6 @@ interface IdentifierProviderInterface { /** - * @param Request $request - * * @return string|null * * @api diff --git a/src/Service/RequestIdentifierProvider.php b/src/Service/RequestIdentifierProvider.php index bdf69f1..14502df 100644 --- a/src/Service/RequestIdentifierProvider.php +++ b/src/Service/RequestIdentifierProvider.php @@ -22,8 +22,7 @@ public function registerIdentifierProvider(IdentifierProviderInterface $identifi /** * @param string $identifierType - * @param Request $request - * @return null|string + * @return string|null * * @api */ @@ -46,10 +45,7 @@ public function getIdentifierPriority($identifierType) private function getIdentifierProvider($identifierType) { if (!isset($this->identifierProviders[$identifierType])) { - throw new InvalidArgumentException(sprintf( - 'Identifier provider for "%s" is not available', - $identifierType - )); + throw new InvalidArgumentException(sprintf('Identifier provider for "%s" is not available', $identifierType)); } return $this->identifierProviders[$identifierType]; diff --git a/src/Service/ResponseModifyingStrategyInterface.php b/src/Service/ResponseModifyingStrategyInterface.php index 1818a84..b023e06 100644 --- a/src/Service/ResponseModifyingStrategyInterface.php +++ b/src/Service/ResponseModifyingStrategyInterface.php @@ -11,9 +11,6 @@ interface ResponseModifyingStrategyInterface extends StrategyInterface { /** - * @param IncreaseResult $increaseResult - * @param Response $response - * * @api */ public function modifyResponse(IncreaseResult $increaseResult, Response $response); diff --git a/src/Service/Strategy/LogStrategy.php b/src/Service/Strategy/LogStrategy.php index d024e62..c412a18 100644 --- a/src/Service/Strategy/LogStrategy.php +++ b/src/Service/Strategy/LogStrategy.php @@ -12,7 +12,6 @@ class LogStrategy implements StrategyInterface private $level; /** - * @param LoggerInterface $logger * @param string $level */ public function __construct(LoggerInterface $logger, $level) diff --git a/src/Service/Strategy/RecaptchaHeadersStrategy.php b/src/Service/Strategy/RecaptchaHeadersStrategy.php index f71a643..c8fb301 100644 --- a/src/Service/Strategy/RecaptchaHeadersStrategy.php +++ b/src/Service/Strategy/RecaptchaHeadersStrategy.php @@ -17,10 +17,8 @@ class RecaptchaHeadersStrategy implements ResponseModifyingStrategyInterface private $unlockUrlHeaderName; /** - * @param ResponseModifyingStrategyInterface $internalStrategy * @param string $headerName * @param string $siteKey - * @param UrlGeneratorInterface $urlGenerator * @param string $unlockUrlHeaderName */ public function __construct( diff --git a/src/Service/Strategy/RecaptchaTemplateStrategy.php b/src/Service/Strategy/RecaptchaTemplateStrategy.php index ee6156e..ec6b5cf 100644 --- a/src/Service/Strategy/RecaptchaTemplateStrategy.php +++ b/src/Service/Strategy/RecaptchaTemplateStrategy.php @@ -18,9 +18,6 @@ class RecaptchaTemplateStrategy implements StrategyInterface private $template; /** - * @param EngineInterface $templating - * @param RequestStack $requestStack - * @param UrlGeneratorInterface $urlGenerator * @param string $googleRecaptchaSiteKey * @param string $template */ diff --git a/src/Service/StrategyInterface.php b/src/Service/StrategyInterface.php index a38a2aa..b09bef2 100644 --- a/src/Service/StrategyInterface.php +++ b/src/Service/StrategyInterface.php @@ -11,7 +11,6 @@ interface StrategyInterface { /** - * @param CompositeIncreaseResult $result * @return Response|null returns null if request should be proceeded * * @api diff --git a/src/Service/StrategyManager.php b/src/Service/StrategyManager.php index 21bfbca..0850721 100644 --- a/src/Service/StrategyManager.php +++ b/src/Service/StrategyManager.php @@ -21,7 +21,6 @@ public function __construct(ContainerInterface $container, array $strategies) } /** - * @param CompositeIncreaseResult $result * @return Response|null */ public function getRateLimitExceededResponse(CompositeIncreaseResult $result) @@ -48,18 +47,14 @@ public function modifyResponse( } /** - * @param ListenerConfiguration $configuration * @return StrategyInterface */ private function getStrategyForConfiguration(ListenerConfiguration $configuration) { $strategyId = $configuration->getStrategyId(); - if (!in_array($strategyId, $this->strategies, true)) { - throw new InvalidArgumentException(sprintf( - 'Given strategy (%s) was not registered with strategy manager', - $strategyId - )); + if (!\in_array($strategyId, $this->strategies, true)) { + throw new InvalidArgumentException(sprintf('Given strategy (%s) was not registered with strategy manager', $strategyId)); } /** @var StrategyInterface $strategy */ diff --git a/src/Service/SuccessMatcher/ResponseCodeSuccessMatcher.php b/src/Service/SuccessMatcher/ResponseCodeSuccessMatcher.php index 303a0d1..6d1c4a9 100644 --- a/src/Service/SuccessMatcher/ResponseCodeSuccessMatcher.php +++ b/src/Service/SuccessMatcher/ResponseCodeSuccessMatcher.php @@ -11,7 +11,6 @@ class ResponseCodeSuccessMatcher implements SuccessMatcherInterface private $inverse; /** - * @param array $statusCodes * @param bool $inverse */ public function __construct(array $statusCodes, $inverse = false) @@ -21,11 +20,10 @@ public function __construct(array $statusCodes, $inverse = false) } /** - * @param Response $response * @return bool */ public function isResponseSuccessful(Response $response) { - return $this->inverse xor in_array($response->getStatusCode(), $this->statusCodes, true); + return $this->inverse xor \in_array($response->getStatusCode(), $this->statusCodes, true); } } diff --git a/src/Service/SuccessMatcherInterface.php b/src/Service/SuccessMatcherInterface.php index a60a3da..7f64562 100644 --- a/src/Service/SuccessMatcherInterface.php +++ b/src/Service/SuccessMatcherInterface.php @@ -10,7 +10,6 @@ interface SuccessMatcherInterface { /** - * @param Response $response * @return bool * * @api diff --git a/tests/Functional/Fixtures/TestKernel.php b/tests/Functional/Fixtures/TestKernel.php index 2f692e6..1b8f15e 100644 --- a/tests/Functional/Fixtures/TestKernel.php +++ b/tests/Functional/Fixtures/TestKernel.php @@ -6,8 +6,8 @@ use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Bundle\TwigBundle\TwigBundle; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\HttpKernel\Kernel; class TestKernel extends Kernel { diff --git a/tests/Unit/Listener/RequestMatcherTest.php b/tests/Unit/Listener/RequestMatcherTest.php index ddd524e..cff65c6 100644 --- a/tests/Unit/Listener/RequestMatcherTest.php +++ b/tests/Unit/Listener/RequestMatcherTest.php @@ -4,8 +4,8 @@ use Maba\Bundle\GentleForceBundle\Listener\ListenerConfiguration; use Maba\Bundle\GentleForceBundle\Listener\RequestMatcher; -use Symfony\Component\HttpFoundation\Request; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\Request; class RequestMatcherTest extends TestCase { @@ -27,7 +27,6 @@ public function setUp() /** * @param bool $expected - * @param Request $request * * @dataProvider dataProviderForPathMatch */ diff --git a/tests/Unit/Service/Strategy/HeadersStrategyTest.php b/tests/Unit/Service/Strategy/HeadersStrategyTest.php index 587abe8..3f36415 100644 --- a/tests/Unit/Service/Strategy/HeadersStrategyTest.php +++ b/tests/Unit/Service/Strategy/HeadersStrategyTest.php @@ -18,7 +18,7 @@ public function testGetRateLimitExceededResponseWithHeader() $strategy = new HeadersStrategy('Retry-After'); $response = $strategy->getRateLimitExceededResponse($this->buildResult()); $this->assertSame(429, $response->getStatusCode()); - $this->assertSame(15, $response->headers->get('Retry-After')); + $this->assertSame(15, (int) $response->headers->get('Retry-After')); } public function testGetRateLimitExceededResponseWithoutHeader() @@ -38,7 +38,7 @@ public function testModifyResponse() $response = new Response('my content', 201, ['custom-header' => 'abc']); $strategy->modifyResponse($this->buildIncreaseResult(), $response); $this->assertSame(201, $response->getStatusCode()); - $this->assertSame(3, $response->headers->get('Requests-Available')); + $this->assertSame(3, (int) $response->headers->get('Requests-Available')); } public function testModifyResponseWithoutHeader()