Skip to content

Commit

Permalink
Merge pull request #563 from FriendsOfSymfony/strict-typing-unit-tests
Browse files Browse the repository at this point in the history
add return declaration to all remaining methods missing them
  • Loading branch information
dbu authored Mar 25, 2024
2 parents 63a2641 + 3974c97 commit c8e58e9
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/ProxyClient/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/UserContext/ContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
22 changes: 11 additions & 11 deletions tests/Unit/CacheInvalidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -92,7 +92,7 @@ public function testInvalidatePath()
;
}

public function testRefreshPath()
public function testRefreshPath(): void
{
$headers = ['X' => 'Y'];
/** @var MockInterface&RefreshCapable $refresh */
Expand All @@ -108,7 +108,7 @@ public function testRefreshPath()
;
}

public function testInvalidate()
public function testInvalidate(): void
{
$headers = [
'X-Header' => '^value.*$',
Expand All @@ -126,7 +126,7 @@ public function testInvalidate()
$cacheInvalidator->invalidate($headers);
}

public function testInvalidateTags()
public function testInvalidateTags(): void
{
$tags = [
'post-8',
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -230,7 +230,7 @@ public function testProxyClientExceptionsAreLogged()
;
}

public function testEventDispatcher()
public function testEventDispatcher(): void
{
/** @var MockInterface&Varnish $proxyClient */
$proxyClient = \Mockery::mock(Varnish::class);
Expand All @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions tests/Unit/Test/NginxTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
9 changes: 3 additions & 6 deletions tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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');
Expand Down
7 changes: 2 additions & 5 deletions tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Test/Proxy/SymfonyProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class SymfonyProxyTest extends TestCase
{
public function testStart()
public function testStart(): void
{
$proxy = new SymfonyProxy();
$proxy->start();
Expand All @@ -25,7 +25,7 @@ public function testStart()
$this->addToAssertionCount(1);
}

public function testInvalidDirectoryThrowsException()
public function testInvalidDirectoryThrowsException(): void
{
define('SYMFONY_CACHE_DIR', '/');
$proxy = new SymfonyProxy();
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Test/Proxy/VarnishProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions tests/Unit/Test/VarnishTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/UserContext/AnonymousRequestMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AnonymousRequestMatcherTest extends TestCase
{
use MockeryPHPUnitIntegration;

public function testMatchAnonymousRequest()
public function testMatchAnonymousRequest(): void
{
$request = new Request();

Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/UserContext/HashGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class HashGeneratorTest extends TestCase
{
public function testGenerateHash()
public function testGenerateHash(): void
{
$hashGenerator = new DefaultHashGenerator([new FooProvider()]);

Expand All @@ -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([]);
Expand All @@ -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');
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/UserContext/UserContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class UserContextTest extends TestCase
{
public function testAddParameter()
public function testAddParameter(): void
{
$userContext = new UserContext();
$userContext->addParameter('authenticated', true);
Expand All @@ -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();

Expand Down

0 comments on commit c8e58e9

Please sign in to comment.