Skip to content

Commit

Permalink
Add return types to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Nov 22, 2019
1 parent 602c1c1 commit 0ebd1f5
Show file tree
Hide file tree
Showing 82 changed files with 484 additions and 617 deletions.
18 changes: 4 additions & 14 deletions Tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function tearDown()
/**
* @return string[]
*/
public function invalidPathProvider()
public function invalidPathProvider(): array
{
return [
[$this->fixturesPath.'/assets/../../foobar.png'],
Expand All @@ -87,10 +87,7 @@ public function invalidPathProvider()
];
}

/**
* @return FilterConfiguration
*/
protected function createFilterConfiguration()
protected function createFilterConfiguration(): FilterConfiguration
{
$config = new FilterConfiguration();
$config->set('thumbnail', [
Expand Down Expand Up @@ -255,14 +252,10 @@ protected function createControllerConfigInstance(int $redirectResponseCode = nu
}

/**
* @param string $object
* @param string[] $methods
* @param bool $constructorInvoke
* @param mixed[] $constructorParams
*
* @return MockObject
*/
protected function createObjectMock($object, array $methods = [], $constructorInvoke = false, array $constructorParams = [])
protected function createObjectMock(string $object, array $methods = [], bool $constructorInvoke = false, array $constructorParams = []): MockObject
{
$builder = $this->getMockBuilder($object);

Expand All @@ -285,11 +278,8 @@ protected function createObjectMock($object, array $methods = [], $constructorIn

/**
* @param object $object
* @param string $name
*
* @return \ReflectionMethod
*/
protected function getVisibilityRestrictedMethod($object, $name)
protected function getVisibilityRestrictedMethod($object, string $name): \ReflectionMethod
{
$r = new \ReflectionObject($object);

Expand Down
4 changes: 2 additions & 2 deletions Tests/Async/CacheResolvedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function setUpBeforeClass()
}
}

public function testCouldBeJsonSerialized()
public function testCouldBeJsonSerialized(): void
{
$message = new CacheResolved('thePath', [
'fooFilter' => 'http://example.com/fooFilter/thePath',
Expand All @@ -40,7 +40,7 @@ public function testCouldBeJsonSerialized()
);
}

public function testCouldBeJsonDeSerialized()
public function testCouldBeJsonDeSerialized(): void
{
$message = CacheResolved::jsonDeserialize('{"path":"thePath","uris":{"fooFilter":"http:\/\/example.com\/fooFilter\/thePath","barFilter":"http:\/\/example.com\/barFilter\/thePath"}}');

Expand Down
20 changes: 10 additions & 10 deletions Tests/Async/ResolveCacheProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testShouldRejectMessagesWithInvalidJsonBody(): void
$this->assertStringStartsWith('The malformed json given.', $result->getReason());
}

public function testShouldSendFailedReplyOnException()
public function testShouldSendFailedReplyOnException(): void
{
$processor = new ResolveCacheProcessor(
$this->createFilterManagerMock(),
Expand All @@ -137,7 +137,7 @@ public function testShouldSendFailedReplyOnException()
);
}

public function testShouldRejectMessagesWithoutPass()
public function testShouldRejectMessagesWithoutPass(): void
{
$processor = new ResolveCacheProcessor(
$this->createFilterManagerMock(),
Expand All @@ -155,7 +155,7 @@ public function testShouldRejectMessagesWithoutPass()
$this->assertSame('The message does not contain "path" but it is required.', $result->getReason());
}

public function testShouldCreateFilteredImage()
public function testShouldCreateFilteredImage(): void
{
$filterName = 'fooFilter';
$imagePath = 'theImagePath';
Expand Down Expand Up @@ -188,7 +188,7 @@ public function testShouldCreateFilteredImage()
$this->assertSame(Result::ACK, (string) $result);
}

public function testShouldCreateOneImagePerFilter()
public function testShouldCreateOneImagePerFilter(): void
{
$filterName1 = 'fooFilter';
$filterName2 = 'barFilter';
Expand Down Expand Up @@ -226,7 +226,7 @@ public function testShouldCreateOneImagePerFilter()
$this->assertSame(Result::ACK, (string) $result);
}

public function testShouldOnlyCreateImageForRequestedFilter()
public function testShouldOnlyCreateImageForRequestedFilter(): void
{
$relevantFilter = 'fooFilter';
$imagePath = 'theImagePath';
Expand Down Expand Up @@ -256,7 +256,7 @@ public function testShouldOnlyCreateImageForRequestedFilter()
$this->assertSame(Result::ACK, (string) $result);
}

public function testShouldCreateOneImagePerRequestedFilter()
public function testShouldCreateOneImagePerRequestedFilter(): void
{
$relevantFilter1 = 'fooFilter';
$relevantFilter2 = 'fooFilter';
Expand Down Expand Up @@ -290,7 +290,7 @@ public function testShouldCreateOneImagePerRequestedFilter()
$this->assertSame(Result::ACK, (string) $result);
}

public function testShouldBurstCacheWhenResolvingForced()
public function testShouldBurstCacheWhenResolvingForced(): void
{
$filterName = 'fooFilter';
$imagePath = 'theImagePath';
Expand Down Expand Up @@ -324,7 +324,7 @@ public function testShouldBurstCacheWhenResolvingForced()
$this->assertSame(Result::ACK, (string) $result);
}

public function testShouldNotBurstCacheWhenResolvingNotForced()
public function testShouldNotBurstCacheWhenResolvingNotForced(): void
{
$filterManagerMock = $this->createFilterManagerMock();
$filterManagerMock
Expand Down Expand Up @@ -354,7 +354,7 @@ public function testShouldNotBurstCacheWhenResolvingNotForced()
$this->assertSame(Result::ACK, (string) $result);
}

public function testShouldSendMessageOnSuccessResolve()
public function testShouldSendMessageOnSuccessResolve(): void
{
$filterManagerMock = $this->createFilterManagerMock();
$filterManagerMock
Expand Down Expand Up @@ -403,7 +403,7 @@ public function testShouldSendMessageOnSuccessResolve()
$this->assertSame(Result::ACK, (string) $result);
}

public function testShouldReturnReplyOnSuccessResolve()
public function testShouldReturnReplyOnSuccessResolve(): void
{
$filterManagerMock = $this->createFilterManagerMock();
$filterManagerMock
Expand Down
18 changes: 9 additions & 9 deletions Tests/Async/ResolveCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ public static function setUpBeforeClass()
}
}

public function testCouldBeJsonSerializedWithoutFiltersAndForce()
public function testCouldBeJsonSerializedWithoutFiltersAndForce(): void
{
$message = new ResolveCache('thePath');

$this->assertSame('{"path":"thePath","filters":null,"force":false}', json_encode($message));
}

public function testCouldBeJsonSerializedWithFilters()
public function testCouldBeJsonSerializedWithFilters(): void
{
$message = new ResolveCache('thePath', ['fooFilter', 'barFilter']);

$this->assertSame('{"path":"thePath","filters":["fooFilter","barFilter"],"force":false}', json_encode($message));
}

public function testCouldBeJsonSerializedWithFiltersAndForce()
public function testCouldBeJsonSerializedWithFiltersAndForce(): void
{
$message = new ResolveCache('thePath', ['fooFilter', 'barFilter'], true);

$this->assertSame('{"path":"thePath","filters":["fooFilter","barFilter"],"force":true}', json_encode($message));
}

public function testCouldBeJsonDeSerializedWithoutFiltersAndForce()
public function testCouldBeJsonDeSerializedWithoutFiltersAndForce(): void
{
$message = ResolveCache::jsonDeserialize('{"path":"thePath","filters":null,"force":false}');

Expand All @@ -57,7 +57,7 @@ public function testCouldBeJsonDeSerializedWithoutFiltersAndForce()
$this->assertFalse($message->isForce());
}

public function testCouldBeJsonDeSerializedWithFilters()
public function testCouldBeJsonDeSerializedWithFilters(): void
{
$message = ResolveCache::jsonDeserialize('{"path":"thePath","filters":["fooFilter","barFilter"],"force":false}');

Expand All @@ -66,7 +66,7 @@ public function testCouldBeJsonDeSerializedWithFilters()
$this->assertFalse($message->isForce());
}

public function testCouldBeJsonDeSerializedWithFiltersAndForce()
public function testCouldBeJsonDeSerializedWithFiltersAndForce(): void
{
$message = ResolveCache::jsonDeserialize('{"path":"thePath","filters":["fooFilter","barFilter"],"force":true}');

Expand All @@ -75,7 +75,7 @@ public function testCouldBeJsonDeSerializedWithFiltersAndForce()
$this->assertTrue($message->isForce());
}

public function testCouldBeJsonDeSerializedWithOnlyPath()
public function testCouldBeJsonDeSerializedWithOnlyPath(): void
{
$message = ResolveCache::jsonDeserialize('{"path":"thePath"}');

Expand All @@ -84,15 +84,15 @@ public function testCouldBeJsonDeSerializedWithOnlyPath()
$this->assertFalse($message->isForce());
}

public function testThrowIfMessageMissingPathOnJsonDeserialize()
public function testThrowIfMessageMissingPathOnJsonDeserialize(): void
{
$this->expectException(\Liip\ImagineBundle\Exception\LogicException::class);
$this->expectExceptionMessage('The message does not contain "path" but it is required.');

ResolveCache::jsonDeserialize('{}');
}

public function testThrowIfMessageContainsNotSupportedFilters()
public function testThrowIfMessageContainsNotSupportedFilters(): void
{
$this->expectException(\Liip\ImagineBundle\Exception\LogicException::class);
$this->expectExceptionMessage('The message filters could be either null or array.');
Expand Down
6 changes: 3 additions & 3 deletions Tests/Binary/Loader/AbstractDoctrineLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function setUp()
->getMockForAbstractClass();
}

public function testFindWithValidObjectFirstHit()
public function testFindWithValidObjectFirstHit(): void
{
$image = new \stdClass();

Expand All @@ -73,7 +73,7 @@ public function testFindWithValidObjectFirstHit()
$this->assertSame('foo', $this->loader->find('/foo/bar'));
}

public function testFindWithValidObjectSecondHit()
public function testFindWithValidObjectSecondHit(): void
{
$image = new \stdClass();

Expand Down Expand Up @@ -102,7 +102,7 @@ public function testFindWithValidObjectSecondHit()
$this->assertSame('foo', $this->loader->find('/foo/bar.png'));
}

public function testFindWithInvalidObject()
public function testFindWithInvalidObject(): void
{
$this->expectException(\Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException::class);

Expand Down
32 changes: 14 additions & 18 deletions Tests/Binary/Loader/FileSystemLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class FileSystemLoaderTest extends TestCase
{
public function testConstruction()
public function testConstruction(): void
{
$loader = $this->getFileSystemLoader();

Expand All @@ -41,7 +41,7 @@ public function testConstruction()
* @param $mimeGuesser
* @param $extensionGuesser
*/
public function testThrowsIfConstructedWithWrongTypeArguments($expectedMessage, $mimeGuesser, $extensionGuesser)
public function testThrowsIfConstructedWithWrongTypeArguments($expectedMessage, $mimeGuesser, $extensionGuesser): void
{
$this->expectException(\Liip\ImagineBundle\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage($expectedMessage);
Expand All @@ -56,7 +56,7 @@ public function testThrowsIfConstructedWithWrongTypeArguments($expectedMessage,
/**
* @return string[][]
*/
public static function provideMultipleWrongArgumentsConstructorCases()
public static function provideMultipleWrongArgumentsConstructorCases(): array
{
return [
[
Expand All @@ -72,15 +72,15 @@ class_exists(MimeTypes::class) ? MimeTypes::getDefault() : MimeTypeGuesser::getI
];
}

public function testImplementsLoaderInterface()
public function testImplementsLoaderInterface(): void
{
$this->assertInstanceOf(LoaderInterface::class, $this->getFileSystemLoader());
}

/**
* @return array[]
*/
public static function provideLoadCases()
public static function provideLoadCases(): array
{
$file = pathinfo(__FILE__, PATHINFO_BASENAME);

Expand Down Expand Up @@ -114,19 +114,16 @@ public static function provideLoadCases()

/**
* @dataProvider provideLoadCases
*
* @param string $root
* @param string $path
*/
public function testLoad($root, $path)
public function testLoad(string $root, string $path): void
{
$this->assertValidLoaderFindReturn($this->getFileSystemLoader([$root])->find($path));
}

/**
* @return string[][]
*/
public static function provideMultipleRootLoadCases()
public static function provideMultipleRootLoadCases(): array
{
$pathsPrepended = [
realpath(__DIR__.'/../'),
Expand All @@ -143,21 +140,20 @@ public static function provideMultipleRootLoadCases()
* @dataProvider provideMultipleRootLoadCases
*
* @param string[] $roots
* @param string $path
*/
public function testMultipleRootLoadCases($roots, $path)
public function testMultipleRootLoadCases(array $roots, string $path): void
{
$this->assertValidLoaderFindReturn($this->getFileSystemLoader($roots)->find($path));
}

public function testAllowsEmptyRootPath()
public function testAllowsEmptyRootPath(): void
{
$loader = $this->getFileSystemLoader([]);

$this->assertInstanceOf(FileSystemLoader::class, $loader);
}

public function testThrowsIfRootPathDoesNotExist()
public function testThrowsIfRootPathDoesNotExist(): void
{
$this->expectException(\Liip\ImagineBundle\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Root image path not resolvable');
Expand All @@ -170,7 +166,7 @@ public function testThrowsIfRootPathDoesNotExist()
/**
* @return array[]
*/
public function provideOutsideRootPathsData()
public function provideOutsideRootPathsData(): array
{
return [
['../Loader/../../Binary/Loader/../../../Resources/config/routing.yaml'],
Expand All @@ -183,7 +179,7 @@ public function provideOutsideRootPathsData()
*
* @param string $path
*/
public function testThrowsIfRealPathOutsideRootPath($path)
public function testThrowsIfRealPathOutsideRootPath($path): void
{
$this->expectException(\Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException::class);
$this->expectExceptionMessage('Source image invalid');
Expand All @@ -193,12 +189,12 @@ public function testThrowsIfRealPathOutsideRootPath($path)
$this->assertInstanceOf(FileSystemLoader::class, $loader);
}

public function testPathWithDoublePeriodBackStep()
public function testPathWithDoublePeriodBackStep(): void
{
$this->assertValidLoaderFindReturn($this->getFileSystemLoader()->find('/../../Binary/Loader/'.pathinfo(__FILE__, PATHINFO_BASENAME)));
}

public function testThrowsIfFileDoesNotExist()
public function testThrowsIfFileDoesNotExist(): void
{
$this->expectException(\Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException::class);
$this->expectExceptionMessage('Source image not resolvable');
Expand Down
Loading

0 comments on commit 0ebd1f5

Please sign in to comment.