From 3974c97ef75c4c26220cbe17363d91e09e325994 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 25 Mar 2024 11:08:41 +0100 Subject: [PATCH] add return declaration to all remaining methods missing them --- src/ProxyClient/Dispatcher.php | 2 +- src/UserContext/ContextProvider.php | 4 ++-- tests/Unit/CacheInvalidatorTest.php | 22 +++++++++---------- tests/Unit/Test/NginxTestTest.php | 8 +++---- .../PHPUnit/AbstractCacheConstraintTest.php | 8 +++---- .../Test/PHPUnit/IsCacheHitConstraintTest.php | 9 +++----- .../PHPUnit/IsCacheMissConstraintTest.php | 7 ++---- tests/Unit/Test/Proxy/SymfonyProxyTest.php | 4 ++-- tests/Unit/Test/Proxy/VarnishProxyTest.php | 2 +- tests/Unit/Test/VarnishTestTest.php | 12 +++++----- .../AnonymousRequestMatcherTest.php | 10 ++++----- tests/Unit/UserContext/HashGeneratorTest.php | 6 ++--- tests/Unit/UserContext/UserContextTest.php | 6 ++--- 13 files changed, 45 insertions(+), 55 deletions(-) diff --git a/src/ProxyClient/Dispatcher.php b/src/ProxyClient/Dispatcher.php index 47874f6ea..cbb89813c 100644 --- a/src/ProxyClient/Dispatcher.php +++ b/src/ProxyClient/Dispatcher.php @@ -29,7 +29,7 @@ interface Dispatcher * a base uri or the invalidation request * specifies the host */ - public function invalidate(RequestInterface $invalidationRequest, bool $validateHost = true); + public function invalidate(RequestInterface $invalidationRequest, bool $validateHost = true): void; /** * Send all pending invalidation requests and make sure the requests have diff --git a/src/UserContext/ContextProvider.php b/src/UserContext/ContextProvider.php index b2cbf101f..237ae9fff 100644 --- a/src/UserContext/ContextProvider.php +++ b/src/UserContext/ContextProvider.php @@ -19,7 +19,7 @@ interface ContextProvider /** * This function is called before generating the hash of a UserContext. * - * This allow to add a parameter on UserContext or set the whole array of parameters + * This allows to add parameters on UserContext or replace the whole array of parameters */ - public function updateUserContext(UserContext $context); + public function updateUserContext(UserContext $context): void; } diff --git a/tests/Unit/CacheInvalidatorTest.php b/tests/Unit/CacheInvalidatorTest.php index 74270551a..151343722 100644 --- a/tests/Unit/CacheInvalidatorTest.php +++ b/tests/Unit/CacheInvalidatorTest.php @@ -37,7 +37,7 @@ class CacheInvalidatorTest extends TestCase { use MockeryPHPUnitIntegration; - public function testSupportsTrue() + public function testSupportsTrue(): void { /** @var MockInterface&Varnish $proxyClient */ $proxyClient = \Mockery::mock(Varnish::class); @@ -50,7 +50,7 @@ public function testSupportsTrue() $this->assertTrue($cacheInvalidator->supports(CacheInvalidator::TAGS)); } - public function testSupportsFalse() + public function testSupportsFalse(): void { /** @var MockInterface&ProxyClient $proxyClient */ $proxyClient = \Mockery::mock(ProxyClient::class); @@ -63,7 +63,7 @@ public function testSupportsFalse() $this->assertFalse($cacheInvalidator->supports(CacheInvalidator::TAGS)); } - public function testSupportsInvalid() + public function testSupportsInvalid(): void { /** @var MockInterface&ProxyClient $proxyClient */ $proxyClient = \Mockery::mock(ProxyClient::class); @@ -74,7 +74,7 @@ public function testSupportsInvalid() $cacheInvalidator->supports('garbage'); } - public function testInvalidatePath() + public function testInvalidatePath(): void { /** @var MockInterface&PurgeCapable $purge */ $purge = \Mockery::mock(PurgeCapable::class) @@ -92,7 +92,7 @@ public function testInvalidatePath() ; } - public function testRefreshPath() + public function testRefreshPath(): void { $headers = ['X' => 'Y']; /** @var MockInterface&RefreshCapable $refresh */ @@ -108,7 +108,7 @@ public function testRefreshPath() ; } - public function testInvalidate() + public function testInvalidate(): void { $headers = [ 'X-Header' => '^value.*$', @@ -126,7 +126,7 @@ public function testInvalidate() $cacheInvalidator->invalidate($headers); } - public function testInvalidateTags() + public function testInvalidateTags(): void { $tags = [ 'post-8', @@ -144,7 +144,7 @@ public function testInvalidateTags() $cacheInvalidator->invalidateTags($tags); } - public function testInvalidateRegex() + public function testInvalidateRegex(): void { /** @var MockInterface&BanCapable $ban */ $ban = \Mockery::mock(BanCapable::class) @@ -181,7 +181,7 @@ public function testMethodException(string $method, $arg): void $cacheInvalidator->$method($arg); } - public function testProxyClientExceptionsAreLogged() + public function testProxyClientExceptionsAreLogged(): void { /** @var MockInterface&RequestInterface $failedRequest */ $failedRequest = \Mockery::mock(RequestInterface::class) @@ -230,7 +230,7 @@ public function testProxyClientExceptionsAreLogged() ; } - public function testEventDispatcher() + public function testEventDispatcher(): void { /** @var MockInterface&Varnish $proxyClient */ $proxyClient = \Mockery::mock(Varnish::class); @@ -241,7 +241,7 @@ public function testEventDispatcher() $this->assertSame($eventDispatcher, $cacheInvalidator->getEventDispatcher()); } - public function testEventDispatcherImmutable() + public function testEventDispatcherImmutable(): void { /** @var MockInterface&Varnish $proxyClient */ $proxyClient = \Mockery::mock(Varnish::class); diff --git a/tests/Unit/Test/NginxTestTest.php b/tests/Unit/Test/NginxTestTest.php index 719d7b928..6db51af8d 100644 --- a/tests/Unit/Test/NginxTestTest.php +++ b/tests/Unit/Test/NginxTestTest.php @@ -12,7 +12,6 @@ namespace FOS\HttpCache\Tests\Unit\Test; use FOS\HttpCache\Test\NginxTest; -use FOS\HttpCache\Test\Proxy\NginxProxy; use PHPUnit\Framework\TestCase; class NginxTestTest extends TestCase @@ -24,20 +23,19 @@ protected function setUp(): void // do not try to set up proxy } - protected function getBinary() + protected function getBinary(): string { return '/test/binary'; } - protected function getCacheDir() + protected function getCacheDir(): string { return '/tmp/foobar'; } - public function testGetProxy() + public function testGetProxy(): void { $proxy = $this->getProxy(); - $this->assertInstanceOf(NginxProxy::class, $proxy); $this->assertEquals('/test/binary', $proxy->getBinary()); $this->assertEquals('/tmp/foobar', $proxy->getCacheDir()); diff --git a/tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php b/tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php index a400c04fd..b335c95cc 100644 --- a/tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php +++ b/tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php @@ -12,18 +12,18 @@ namespace FOS\HttpCache\Tests\Unit\Test\PHPUnit; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; +use Mockery\MockInterface; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseInterface; abstract class AbstractCacheConstraintTest extends TestCase { use MockeryPHPUnitIntegration; - protected function getResponseMock() + protected function getResponseMock(): ResponseInterface&MockInterface { - $mock = \Mockery::mock( + return \Mockery::mock( '\Psr\Http\Message\ResponseInterface[hasHeader,getHeaderLine,getStatusCode,getHeaders,getBody]' ); - - return $mock; } } diff --git a/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php b/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php index a2087f860..d1e73cd28 100644 --- a/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php +++ b/tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php @@ -17,17 +17,14 @@ class IsCacheHitConstraintTest extends AbstractCacheConstraintTest { - /** - * @var IsCacheHitConstraint - */ - private $constraint; + private IsCacheHitConstraint $constraint; public function setUp(): void { $this->constraint = new IsCacheHitConstraint('cache-header'); } - public function testMatches() + public function testMatches(): void { $response = $this->getResponseMock() ->shouldReceive('hasHeader')->with('cache-header')->andReturn(true) @@ -42,7 +39,7 @@ public function testMatches() $this->constraint->evaluate($response); } - public function testMatchesThrowsExceptionIfHeaderIsMissing() + public function testMatchesThrowsExceptionIfHeaderIsMissing(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Response has no "cache-header" header'); diff --git a/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php b/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php index 55553482f..bb00c09b9 100644 --- a/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php +++ b/tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php @@ -16,17 +16,14 @@ class IsCacheMissConstraintTest extends AbstractCacheConstraintTest { - /** - * @var IsCacheMissConstraint - */ - private $constraint; + private IsCacheMissConstraint $constraint; public function setUp(): void { $this->constraint = new IsCacheMissConstraint('cache-header'); } - public function testMatches() + public function testMatches(): void { $response = $this->getResponseMock() ->shouldReceive('hasHeader')->with('cache-header')->andReturn(true) diff --git a/tests/Unit/Test/Proxy/SymfonyProxyTest.php b/tests/Unit/Test/Proxy/SymfonyProxyTest.php index b425289b9..15d5e444a 100644 --- a/tests/Unit/Test/Proxy/SymfonyProxyTest.php +++ b/tests/Unit/Test/Proxy/SymfonyProxyTest.php @@ -16,7 +16,7 @@ class SymfonyProxyTest extends TestCase { - public function testStart() + public function testStart(): void { $proxy = new SymfonyProxy(); $proxy->start(); @@ -25,7 +25,7 @@ public function testStart() $this->addToAssertionCount(1); } - public function testInvalidDirectoryThrowsException() + public function testInvalidDirectoryThrowsException(): void { define('SYMFONY_CACHE_DIR', '/'); $proxy = new SymfonyProxy(); diff --git a/tests/Unit/Test/Proxy/VarnishProxyTest.php b/tests/Unit/Test/Proxy/VarnishProxyTest.php index 21467a1ac..f15ed513d 100644 --- a/tests/Unit/Test/Proxy/VarnishProxyTest.php +++ b/tests/Unit/Test/Proxy/VarnishProxyTest.php @@ -62,7 +62,7 @@ public function testStart(bool $inlineC): void $this->assertEquals($arguments, $proxy->arguments); } - public function testWaitThrowsException() + public function testWaitThrowsException(): void { $proxy = new VarnishProxyMock('config.vcl'); $proxy->wait = false; diff --git a/tests/Unit/Test/VarnishTestTest.php b/tests/Unit/Test/VarnishTestTest.php index 69c272298..1a4b90dd8 100644 --- a/tests/Unit/Test/VarnishTestTest.php +++ b/tests/Unit/Test/VarnishTestTest.php @@ -11,7 +11,6 @@ namespace FOS\HttpCache\Tests\Unit\Test; -use FOS\HttpCache\Test\Proxy\VarnishProxy; use FOS\HttpCache\Test\VarnishTest; use PHPUnit\Framework\TestCase; @@ -24,30 +23,29 @@ protected function setUp(): void // do not try to set up proxy } - protected function getBinary() + protected function getBinary(): string { return '/test/binary'; } - protected function getCachingProxyPort() + protected function getCachingProxyPort(): int { return 123; } - protected function getVarnishMgmtPort() + protected function getVarnishMgmtPort(): int { return 321; } - protected function getCacheDir() + protected function getCacheDir(): string { return '/tmp/foobar'; } - public function testGetProxy() + public function testGetProxy(): void { $proxy = $this->getProxy(); - $this->assertInstanceOf(VarnishProxy::class, $proxy); $this->assertEquals('/test/binary', $proxy->getBinary()); $this->assertEquals(123, $proxy->getPort()); diff --git a/tests/Unit/UserContext/AnonymousRequestMatcherTest.php b/tests/Unit/UserContext/AnonymousRequestMatcherTest.php index 3fe838f4a..4cec2f112 100644 --- a/tests/Unit/UserContext/AnonymousRequestMatcherTest.php +++ b/tests/Unit/UserContext/AnonymousRequestMatcherTest.php @@ -20,7 +20,7 @@ class AnonymousRequestMatcherTest extends TestCase { use MockeryPHPUnitIntegration; - public function testMatchAnonymousRequest() + public function testMatchAnonymousRequest(): void { $request = new Request(); @@ -32,7 +32,7 @@ public function testMatchAnonymousRequest() $this->assertTrue($requestMatcher->matches($request)); } - public function testNoMatchIfCookie() + public function testNoMatchIfCookie(): void { $request = new Request(); $request->headers->set('Cookie', 'foo=bar'); @@ -46,7 +46,7 @@ public function testNoMatchIfCookie() $this->assertFalse($requestMatcher->matches($request)); } - public function testNoMatchIfSession() + public function testNoMatchIfSession(): void { $request = new Request(); $request->headers->set('Cookie', 'PHPSESSID7e476fc9f29f69d2ad6f11dbcd663b42=25f6d9c5a843e3c948cd26902385a527'); @@ -60,7 +60,7 @@ public function testNoMatchIfSession() $this->assertFalse($requestMatcher->matches($request)); } - public function testMatchIfNoSessionCookie() + public function testMatchIfNoSessionCookie(): void { $request = new Request(); $request->headers->set('Cookie', 'foo=bar'); @@ -74,7 +74,7 @@ public function testMatchIfNoSessionCookie() $this->assertTrue($requestMatcher->matches($request)); } - public function testNoMatchIfAuthenticationHeader() + public function testNoMatchIfAuthenticationHeader(): void { $request = new Request(); $request->headers->set('Authorization', 'foo: bar'); diff --git a/tests/Unit/UserContext/HashGeneratorTest.php b/tests/Unit/UserContext/HashGeneratorTest.php index 3926f642e..55e2e84d1 100644 --- a/tests/Unit/UserContext/HashGeneratorTest.php +++ b/tests/Unit/UserContext/HashGeneratorTest.php @@ -19,7 +19,7 @@ class HashGeneratorTest extends TestCase { - public function testGenerateHash() + public function testGenerateHash(): void { $hashGenerator = new DefaultHashGenerator([new FooProvider()]); @@ -28,7 +28,7 @@ public function testGenerateHash() $this->assertEquals($expectedHash, $hashGenerator->generateHash()); } - public function testConstructorError() + public function testConstructorError(): void { $this->expectException(InvalidArgumentException::class); new DefaultHashGenerator([]); @@ -37,7 +37,7 @@ public function testConstructorError() class FooProvider implements ContextProvider { - public function updateUserContext(UserContext $context) + public function updateUserContext(UserContext $context): void { $context->addParameter('foo', 'bar'); } diff --git a/tests/Unit/UserContext/UserContextTest.php b/tests/Unit/UserContext/UserContextTest.php index 3e3e5ebcf..8af3ad4fa 100644 --- a/tests/Unit/UserContext/UserContextTest.php +++ b/tests/Unit/UserContext/UserContextTest.php @@ -16,7 +16,7 @@ class UserContextTest extends TestCase { - public function testAddParameter() + public function testAddParameter(): void { $userContext = new UserContext(); $userContext->addParameter('authenticated', true); @@ -25,10 +25,10 @@ public function testAddParameter() $parameters = $userContext->getParameters(); - $this->assertEquals(true, $parameters['authenticated']); + $this->assertTrue($parameters['authenticated']); } - public function testSetParameters() + public function testSetParameters(): void { $userContext = new UserContext();