From 0bd1f6a0f4025ca24c984ef7704aa1c7f2bfa640 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 6 Jan 2024 10:39:34 +0100 Subject: [PATCH] cleanup phpunit tests now that we don't need ancient legacy support anymore --- .github/workflows/php-cs-fixer.yml | 2 +- .../Compiler/AssetsVersionCompilerPass.php | 10 +- tests/AbstractTest.php | 230 +------------- .../Loader/AbstractDoctrineLoaderTest.php | 4 +- tests/Binary/Loader/ChainLoaderTest.php | 4 +- tests/Binary/Loader/FlysystemLoaderTest.php | 70 ----- tests/Binary/Loader/FlysystemV2LoaderTest.php | 6 +- tests/Binary/Loader/StreamLoaderTest.php | 2 +- .../Console/Style/ImagineStyleTest.php | 2 +- tests/Controller/ImagineControllerTest.php | 17 +- .../Factory/Loader/ChainLoaderFactoryTest.php | 6 +- .../Loader/FileSystemLoaderFactoryTest.php | 18 +- .../Loader/FlysystemLoaderFactoryTest.php | 31 +- .../Loader/StreamLoaderFactoryTest.php | 20 +- .../Resolver/AwsS3ResolverFactoryTest.php | 42 +-- .../Resolver/FlysystemResolverFactoryTest.php | 35 +-- .../Resolver/WebPathResolverFactoryTest.php | 12 +- .../LiipImagineExtensionTest.php | 22 +- tests/Form/Type/ImageTypeTest.php | 12 +- tests/Functional/AbstractWebTestCase.php | 8 - tests/Functional/app/AppKernel.php | 7 +- .../config/{symfony_5-3.yaml => symfony.yaml} | 0 .../Functional/app/config/symfony_legacy.yaml | 3 - tests/Imagine/Cache/CacheManagerTest.php | 293 +++++++++--------- .../Cache/Resolver/AwsS3ResolverTest.php | 7 +- .../Cache/Resolver/FlysystemResolverTest.php | 256 --------------- .../Resolver/FlysystemV2ResolverTest.php | 46 +-- .../Resolver/FormatExtensionResolverTest.php | 2 +- .../Cache/Resolver/ProxyResolverTest.php | 2 +- .../Cache/Resolver/PsrCacheResolverTest.php | 24 +- .../Cache/Resolver/WebPathResolverTest.php | 59 ++-- tests/Imagine/Data/DataManagerTest.php | 87 +++--- tests/Imagine/Filter/FilterManagerTest.php | 206 ++++++------ .../Loader/AutoRotateFilterLoaderTest.php | 3 +- .../Filter/Loader/CropFilterLoaderTest.php | 3 +- .../Loader/DownscaleFilterLoaderTest.php | 2 +- .../Filter/Loader/FixedFilterLoaderTest.php | 3 +- .../Filter/Loader/FlipFilterLoaderTest.php | 7 +- .../Loader/InterlaceFilterLoaderTest.php | 2 +- .../Filter/Loader/PasteFilterLoaderTest.php | 6 +- .../Loader/ResampleFilterLoaderTest.php | 17 +- .../Filter/Loader/ResizeFilterLoaderTest.php | 3 +- .../Filter/Loader/RotateFilterLoaderTest.php | 7 +- .../Filter/Loader/ScaleFilterLoaderTest.php | 23 +- .../Loader/ThumbnailFilterLoaderTest.php | 3 +- .../AbstractPostProcessorTest.php | 11 +- .../AbstractPostProcessorTestCase.php | 8 - .../PostProcessor/CwebpPostProcessorTest.php | 4 +- .../JpegOptimPostProcessorTest.php | 4 +- .../MozJpegPostProcessorTest.php | 4 +- .../OptiPngPostProcessorTest.php | 4 +- .../PngquantPostProcessorTest.php | 4 +- tests/LiipImagineBundleTest.php | 23 +- .../Handler/WarmupCacheHandlerTest.php | 8 - tests/Message/WarmupCacheTest.php | 8 - tests/Service/FilterServiceTest.php | 58 +--- tests/Templating/LazyFilterRuntimeTest.php | 31 ++ tests/bootstrap.php | 10 - 58 files changed, 503 insertions(+), 1298 deletions(-) delete mode 100644 tests/Binary/Loader/FlysystemLoaderTest.php rename tests/Functional/app/config/{symfony_5-3.yaml => symfony.yaml} (100%) delete mode 100644 tests/Functional/app/config/symfony_legacy.yaml delete mode 100644 tests/Imagine/Cache/Resolver/FlysystemResolverTest.php diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml index dd60e4eef..2e3b80895 100644 --- a/.github/workflows/php-cs-fixer.yml +++ b/.github/workflows/php-cs-fixer.yml @@ -18,7 +18,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.3 coverage: none tools: php-cs-fixer diff --git a/src/DependencyInjection/Compiler/AssetsVersionCompilerPass.php b/src/DependencyInjection/Compiler/AssetsVersionCompilerPass.php index fba063ec0..8ded1d029 100644 --- a/src/DependencyInjection/Compiler/AssetsVersionCompilerPass.php +++ b/src/DependencyInjection/Compiler/AssetsVersionCompilerPass.php @@ -54,7 +54,7 @@ public function process(ContainerBuilder $container): void $version = $versionStrategyDefinition->getArgument(0); $format = $versionStrategyDefinition->getArgument(1); $format = $container->resolveEnvPlaceholders($format); - if ($format && !$this->str_ends_with($format, '?%%s')) { + if ($format && !str_ends_with($format, '?%%s')) { $this->log($container, 'Can not handle assets versioning with custom format "'.$format.'". asset twig function can likely not be used with the imagine_filter'); return; @@ -62,12 +62,4 @@ public function process(ContainerBuilder $container): void $runtimeDefinition->setArgument(1, $version); } - - /** - * Can be replaced with the built-in method when dropping support for PHP < 8.0 - */ - private function str_ends_with(string $haystack, string $needle): bool - { - return mb_substr($haystack, -mb_strlen($needle)) === $needle; - } } diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index e97147f2c..86d607bf9 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -11,27 +11,8 @@ namespace Liip\ImagineBundle\Tests; -use Imagine\Image\ImageInterface; -use Imagine\Image\ImagineInterface; -use Imagine\Image\Metadata\MetadataBag; -use Liip\ImagineBundle\Binary\Loader\LoaderInterface; -use Liip\ImagineBundle\Binary\MimeTypeGuesserInterface; -use Liip\ImagineBundle\Config\Controller\ControllerConfig; -use Liip\ImagineBundle\Imagine\Cache\CacheManager; -use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; -use Liip\ImagineBundle\Imagine\Cache\SignerInterface; -use Liip\ImagineBundle\Imagine\Data\DataManager; -use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; -use Liip\ImagineBundle\Imagine\Filter\FilterManager; -use Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface; -use Liip\ImagineBundle\Service\FilterService; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Psr\Log\LoggerInterface; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Mime\MimeTypesInterface; -use Symfony\Component\Routing\RouterInterface; -use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; abstract class AbstractTest extends TestCase { @@ -65,216 +46,7 @@ protected function tearDown(): void } } - /** - * @return string[] - */ - public function invalidPathProvider(): array - { - return [ - [$this->fixturesPath.'/assets/../../foobar.png'], - [$this->fixturesPath.'/assets/some_folder/../foobar.png'], - ['../../outside/foobar.jpg'], - ]; - } - - public function expectExceptionMessageMatchesBC(string $regularExpression): void - { - if (method_exists($this, 'expectExceptionMessageMatches')) { - $this->expectExceptionMessageMatches($regularExpression); - } else { - $this->expectExceptionMessageRegExp($regularExpression); - } - } - - protected function createFilterConfiguration(): FilterConfiguration - { - $config = new FilterConfiguration(); - $config->set('thumbnail', [ - 'size' => [180, 180], - 'mode' => 'outbound', - ]); - - return $config; - } - - /** - * @return MockObject&CacheManager - */ - protected function createCacheManagerMock() - { - return $this - ->getMockBuilder(CacheManager::class) - ->setConstructorArgs([ - $this->createFilterConfiguration(), - $this->createRouterInterfaceMock(), - $this->createSignerInterfaceMock(), - $this->createEventDispatcherInterfaceMock(), - ]) - ->getMock(); - } - - /** - * @return MockObject&FilterConfiguration - */ - protected function createFilterConfigurationMock() - { - return $this->createObjectMock(FilterConfiguration::class); - } - - /** - * @return MockObject&SignerInterface - */ - protected function createSignerInterfaceMock() - { - return $this->createObjectMock(SignerInterface::class); - } - - /** - * @return MockObject&RouterInterface - */ - protected function createRouterInterfaceMock() - { - return $this->createObjectMock(RouterInterface::class); - } - - /** - * @return MockObject&ResolverInterface - */ - protected function createCacheResolverInterfaceMock() - { - return $this->createObjectMock(ResolverInterface::class); - } - - /** - * @return MockObject&EventDispatcherInterface - */ - protected function createEventDispatcherInterfaceMock() - { - return $this->createObjectMock(EventDispatcherInterface::class); - } - - /** - * @return MockObject&ImageInterface - */ - protected function getImageInterfaceMock() - { - return $this->createObjectMock(ImageInterface::class); - } - - /** - * @return MockObject&MetadataBag - */ - protected function getMetadataBagMock() - { - return $this->createObjectMock(MetadataBag::class); - } - - /** - * @return MockObject&ImagineInterface - */ - protected function createImagineInterfaceMock() - { - return $this->createObjectMock(ImagineInterface::class); - } - - /** - * @return MockObject&LoggerInterface - */ - protected function createLoggerInterfaceMock() - { - return $this->createObjectMock(LoggerInterface::class); - } - - /** - * @return MockObject&LoaderInterface - */ - protected function createBinaryLoaderInterfaceMock() - { - return $this->createObjectMock(LoaderInterface::class); - } - - /** - * @return MockObject&MimeTypeGuesserInterface - */ - protected function createMimeTypeGuesserInterfaceMock() - { - return $this->createObjectMock(MimeTypeGuesserInterface::class); - } - - /** - * @return MockObject&MimeTypesInterface - */ - protected function createExtensionGuesserInterfaceMock() - { - return $this->createObjectMock(MimeTypesInterface::class); - } - - /** - * @return MockObject&PostProcessorInterface - */ - protected function createPostProcessorInterfaceMock() - { - return $this->createObjectMock(PostProcessorInterface::class); - } - - /** - * @return MockObject&FilterManager - */ - protected function createFilterManagerMock() - { - return $this->createObjectMock(FilterManager::class, [], false); - } - - /** - * @return MockObject&FilterService - */ - protected function createFilterServiceMock() - { - return $this->createObjectMock(FilterService::class); - } - - /** - * @return MockObject&DataManager - */ - protected function createDataManagerMock() - { - return $this->createObjectMock(DataManager::class, [], false); - } - - protected function createControllerConfigInstance(int $redirectResponseCode = null): ControllerConfig - { - return new ControllerConfig($redirectResponseCode ?? 301); - } - - /** - * @param string[] $methods - * @param mixed[] $constructorParams - */ - protected function createObjectMock(string $object, array $methods = [], bool $constructorInvoke = false, array $constructorParams = []): MockObject - { - $builder = $this->getMockBuilder($object); - - if (\count($methods) > 0) { - $builder->setMethods($methods); - } - - if ($constructorInvoke) { - $builder->enableOriginalConstructor(); - } else { - $builder->disableOriginalConstructor(); - } - - if (\count($constructorParams) > 0) { - $builder->setConstructorArgs($constructorParams); - } - - return $builder->getMock(); - } - - /** - * @param object $object - */ - protected function getVisibilityRestrictedMethod($object, string $name): \ReflectionMethod + protected function getVisibilityRestrictedMethod(object $object, string $name): \ReflectionMethod { $r = new \ReflectionObject($object); diff --git a/tests/Binary/Loader/AbstractDoctrineLoaderTest.php b/tests/Binary/Loader/AbstractDoctrineLoaderTest.php index 60ce28fe4..9c756c6c1 100644 --- a/tests/Binary/Loader/AbstractDoctrineLoaderTest.php +++ b/tests/Binary/Loader/AbstractDoctrineLoaderTest.php @@ -35,9 +35,7 @@ class AbstractDoctrineLoaderTest extends TestCase protected function setUp(): void { - $this->om = $this - ->getMockBuilder(ObjectManager::class) - ->getMock(); + $this->om = $this->createMock(ObjectManager::class); $this->loader = $this ->getMockBuilder(AbstractDoctrineLoader::class) diff --git a/tests/Binary/Loader/ChainLoaderTest.php b/tests/Binary/Loader/ChainLoaderTest.php index 0040698e1..6a727b59f 100644 --- a/tests/Binary/Loader/ChainLoaderTest.php +++ b/tests/Binary/Loader/ChainLoaderTest.php @@ -91,7 +91,7 @@ public function provideInvalidPathsData(): array public function testThrowsIfFileDoesNotExist(string $path): void { $this->expectException(NotLoadableException::class); - $this->expectExceptionMessageMatchesBC('{Source image not resolvable "[^"]+" using "FileSystemLoader=\[foo\]" 1 loaders}'); + $this->expectExceptionMessageMatches('{Source image not resolvable "[^"]+" using "FileSystemLoader=\[foo\]" 1 loaders}'); $this->getChainLoader()->find($path); } @@ -102,7 +102,7 @@ public function testThrowsIfFileDoesNotExist(string $path): void public function testThrowsIfFileDoesNotExistWithMultipleLoaders(string $path): void { $this->expectException(NotLoadableException::class); - $this->expectExceptionMessageMatchesBC('{Source image not resolvable "[^"]+" using "FileSystemLoader=\[foo\], FileSystemLoader=\[bar\]" 2 loaders \(internal exceptions: FileSystemLoader=\[.+\], FileSystemLoader=\[.+\]\)\.}'); + $this->expectExceptionMessageMatches('{Source image not resolvable "[^"]+" using "FileSystemLoader=\[foo\], FileSystemLoader=\[bar\]" 2 loaders \(internal exceptions: FileSystemLoader=\[.+\], FileSystemLoader=\[.+\]\)\.}'); $this->getChainLoader([], [ 'foo' => $this->createFileSystemLoader( diff --git a/tests/Binary/Loader/FlysystemLoaderTest.php b/tests/Binary/Loader/FlysystemLoaderTest.php deleted file mode 100644 index e8e1ef070..000000000 --- a/tests/Binary/Loader/FlysystemLoaderTest.php +++ /dev/null @@ -1,70 +0,0 @@ -markTestSkipped('Requires the league/flysystem:^1.0 package.'); - } - - $this->flyFilesystem = new Filesystem(new Local($this->fixturesPath)); - } - - public function getFlysystemLoader(): FlysystemLoader - { - $extensionGuesser = MimeTypes::getDefault(); - - return new FlysystemLoader($extensionGuesser, $this->flyFilesystem); - } - - public function testShouldImplementLoaderInterface(): void - { - $this->assertInstanceOf(LoaderInterface::class, $this->getFlysystemLoader()); - } - - public function testReturnImageContentOnFind(): void - { - $loader = $this->getFlysystemLoader(); - - $this->assertStringEqualsFile( - $this->fixturesPath.'/assets/cats.jpeg', $loader->find('assets/cats.jpeg')->getContent() - ); - } - - public function testThrowsIfInvalidPathGivenOnFind(): void - { - $this->expectException(\Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException::class); - $this->expectExceptionMessageMatchesBC('{Source image .+ not found}'); - - $loader = $this->getFlysystemLoader(); - - $loader->find('invalid.jpeg'); - } -} diff --git a/tests/Binary/Loader/FlysystemV2LoaderTest.php b/tests/Binary/Loader/FlysystemV2LoaderTest.php index 1da11b0d3..548b91863 100644 --- a/tests/Binary/Loader/FlysystemV2LoaderTest.php +++ b/tests/Binary/Loader/FlysystemV2LoaderTest.php @@ -32,10 +32,6 @@ protected function setUp(): void { parent::setUp(); - if (!interface_exists(FilesystemOperator::class)) { - $this->markTestSkipped('Requires the league/flysystem:^2.0 package.'); - } - $this->flyFilesystem = new Filesystem(new LocalFilesystemAdapter($this->fixturesPath)); } @@ -57,7 +53,7 @@ public function testReturnImageContentOnFind(): void public function testThrowsIfInvalidPathGivenOnFind(): void { $this->expectException(NotLoadableException::class); - $this->expectExceptionMessageMatchesBC('{Source image .+ not found}'); + $this->expectExceptionMessageMatches('{Source image .+ not found}'); $loader = $this->getFlysystemLoader(); diff --git a/tests/Binary/Loader/StreamLoaderTest.php b/tests/Binary/Loader/StreamLoaderTest.php index 50b2f7344..3cb000dc7 100644 --- a/tests/Binary/Loader/StreamLoaderTest.php +++ b/tests/Binary/Loader/StreamLoaderTest.php @@ -22,7 +22,7 @@ class StreamLoaderTest extends AbstractTest public function testThrowsIfInvalidPathGivenOnFind(): void { $this->expectException(\Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException::class); - $this->expectExceptionMessageMatchesBC('{Source image file://.+ not found.}'); + $this->expectExceptionMessageMatches('{Source image file://.+ not found.}'); $loader = new StreamLoader('file://'); $loader->find($this->temporaryPath.'/invalid.jpeg'); diff --git a/tests/Component/Console/Style/ImagineStyleTest.php b/tests/Component/Console/Style/ImagineStyleTest.php index 935848071..f9e2dbd8e 100644 --- a/tests/Component/Console/Style/ImagineStyleTest.php +++ b/tests/Component/Console/Style/ImagineStyleTest.php @@ -225,7 +225,7 @@ public static function provideGroupData(): \Generator public function testInvalidFormatAndReplacements(string $format, array $replacements): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessageMatchesBC('{Invalid string format "[^"]+" or replacements "[^"]+".}'); + $this->expectExceptionMessageMatches('{Invalid string format "[^"]+" or replacements "[^"]+".}'); $style = $this->createImagineStyle($output = $this->createBufferedOutput()); $style->text($format, $replacements); diff --git a/tests/Controller/ImagineControllerTest.php b/tests/Controller/ImagineControllerTest.php index 02275c02a..86abfd84a 100644 --- a/tests/Controller/ImagineControllerTest.php +++ b/tests/Controller/ImagineControllerTest.php @@ -14,6 +14,9 @@ use Liip\ImagineBundle\Config\Controller\ControllerConfig; use Liip\ImagineBundle\Controller\ImagineController; use Liip\ImagineBundle\Exception\InvalidArgumentException; +use Liip\ImagineBundle\Imagine\Cache\SignerInterface; +use Liip\ImagineBundle\Imagine\Data\DataManager; +use Liip\ImagineBundle\Service\FilterService; use Liip\ImagineBundle\Tests\AbstractTest; use Liip\ImagineBundle\Tests\Config\Controller\ControllerConfigTest; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -27,10 +30,10 @@ class ImagineControllerTest extends AbstractTest public function testConstruction(): void { $controller = new ImagineController( - $this->createFilterServiceMock(), - $this->createDataManagerMock(), - $this->createSignerInterfaceMock(), - $this->createControllerConfigInstance() + $this->createMock(FilterService::class), + $this->createMock(DataManager::class), + $this->createMock(SignerInterface::class), + new ControllerConfig(301) ); $this->assertInstanceOf(ImagineController::class, $controller); @@ -84,7 +87,7 @@ public function testInvalidRedirectResponseCode(int $redirectResponseCode): void private function createControllerInstance(string $path, string $filter, string $hash, int $redirectResponseCode, bool $expectation = true): ImagineController { - $filterService = $this->createFilterServiceMock(); + $filterService = $this->createMock(FilterService::class); $filterService ->expects($expectation ? $this->atLeastOnce() : $this->never()) ->method('getUrlOfFilteredImage') @@ -97,7 +100,7 @@ private function createControllerInstance(string $path, string $filter, string $ ->with($path, $filter, [], null) ->willReturn(sprintf('/resolved/image%s', $path)); - $signer = $this->createSignerInterfaceMock(); + $signer = $this->createMock(SignerInterface::class); $signer ->expects($expectation ? $this->once() : $this->never()) ->method('check') @@ -106,7 +109,7 @@ private function createControllerInstance(string $path, string $filter, string $ return new ImagineController( $filterService, - $this->createDataManagerMock(), + $this->createMock(DataManager::class), $signer, new ControllerConfig($redirectResponseCode) ); diff --git a/tests/DependencyInjection/Factory/Loader/ChainLoaderFactoryTest.php b/tests/DependencyInjection/Factory/Loader/ChainLoaderFactoryTest.php index 86fdda485..e12423661 100644 --- a/tests/DependencyInjection/Factory/Loader/ChainLoaderFactoryTest.php +++ b/tests/DependencyInjection/Factory/Loader/ChainLoaderFactoryTest.php @@ -64,12 +64,8 @@ public function testCreateLoaderDefinition(): void public function testProcessOptionsOnAddConfiguration(): void { $treeBuilder = new TreeBuilder('chain'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('chain'); - $loader = new ChainLoaderFactory(); - $loader->addConfiguration($rootNode); + $loader->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'chain' => [ diff --git a/tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php b/tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php index 646ad948c..7efa66280 100644 --- a/tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php +++ b/tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php @@ -299,12 +299,8 @@ public function testProcessCorrectlyOptionsOnAddConfiguration(): void $expectedDataRoot = ['theDataRoot']; $treeBuilder = new TreeBuilder('filesystem'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('filesystem'); - $loader = new FileSystemLoaderFactory(); - $loader->addConfiguration($rootNode); + $loader->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'filesystem' => [ @@ -321,12 +317,8 @@ public function testAddDefaultOptionsIfNotSetOnAddConfiguration(): void $expectedDataRoot = [SymfonyFramework::getContainerResolvableRootWebPath()]; $treeBuilder = new TreeBuilder('filesystem'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('filesystem'); - $loader = new FileSystemLoaderFactory(); - $loader->addConfiguration($rootNode); + $loader->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'filesystem' => [], @@ -341,12 +333,8 @@ public function testAddAsScalarExpectingArrayNormalizationOfConfiguration(): voi $expectedDataRoot = [SymfonyFramework::getContainerResolvableRootWebPath()]; $treeBuilder = new TreeBuilder('filesystem'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('filesystem'); - $loader = new FileSystemLoaderFactory(); - $loader->addConfiguration($rootNode); + $loader->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'filesystem' => [ diff --git a/tests/DependencyInjection/Factory/Loader/FlysystemLoaderFactoryTest.php b/tests/DependencyInjection/Factory/Loader/FlysystemLoaderFactoryTest.php index 2bc70c117..bed013637 100644 --- a/tests/DependencyInjection/Factory/Loader/FlysystemLoaderFactoryTest.php +++ b/tests/DependencyInjection/Factory/Loader/FlysystemLoaderFactoryTest.php @@ -11,12 +11,11 @@ namespace Liip\ImagineBundle\Tests\DependencyInjection\Factory\Loader; -use League\Flysystem\FilesystemInterface; -use League\Flysystem\FilesystemOperator; use Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory; use Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface; use Liip\ImagineBundle\Tests\AbstractTest; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -29,12 +28,6 @@ class FlysystemLoaderFactoryTest extends AbstractTest protected function setUp(): void { parent::setUp(); - - if (!interface_exists(FilesystemInterface::class) - && !interface_exists(FilesystemOperator::class) - ) { - $this->markTestSkipped('Requires the league/flysystem package.'); - } } public function testImplementsLoaderFactoryInterface(): void @@ -72,11 +65,7 @@ public function testCreateLoaderDefinitionOnCreate(): void $loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.the_loader_name'); $this->assertInstanceOf(ChildDefinition::class, $loaderDefinition); - if (interface_exists(FilesystemOperator::class)) { - $loaderName = 'liip_imagine.binary.loader.prototype.flysystem2'; - } else { - $loaderName = 'liip_imagine.binary.loader.prototype.flysystem'; - } + $loaderName = 'liip_imagine.binary.loader.prototype.flysystem2'; $this->assertSame($loaderName, $loaderDefinition->getParent()); $reference = $loaderDefinition->getArgument(1); @@ -85,16 +74,12 @@ public function testCreateLoaderDefinitionOnCreate(): void public function testThrowIfFileSystemServiceNotSetOnAddConfiguration(): void { - $this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class); - $this->expectExceptionMessageMatchesBC('/^The child (node|config) "filesystem_service" (at path|under) "flysystem" must be configured\.$/'); + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessageMatches('/^The child (node|config) "filesystem_service" (at path|under) "flysystem" must be configured\.$/'); $treeBuilder = new TreeBuilder('flysystem'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('flysystem'); - $resolver = new FlysystemLoaderFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $this->processConfigTree($treeBuilder, []); } @@ -104,12 +89,8 @@ public function testProcessCorrectlyOptionsOnAddConfiguration(): void $expectedService = 'theService'; $treeBuilder = new TreeBuilder('flysystem'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('flysystem'); - $loader = new FlysystemLoaderFactory(); - $loader->addConfiguration($rootNode); + $loader->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'flysystem' => [ diff --git a/tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php b/tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php index c5a2be454..6641f44df 100644 --- a/tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php +++ b/tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php @@ -69,15 +69,11 @@ public function testCreateLoaderDefinitionOnCreate(): void public function testThrowIfWrapperNotSetOnAddConfiguration(): void { $this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class); - $this->expectExceptionMessageMatchesBC('/^The child (node|config) "wrapper" (at path|under) "stream" must be configured\.$/'); + $this->expectExceptionMessageMatches('/^The child (node|config) "wrapper" (at path|under) "stream" must be configured\.$/'); $treeBuilder = new TreeBuilder('stream'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('stream'); - $resolver = new StreamLoaderFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $this->processConfigTree($treeBuilder, []); } @@ -88,12 +84,8 @@ public function testProcessCorrectlyOptionsOnAddConfiguration(): void $expectedContext = 'theContext'; $treeBuilder = new TreeBuilder('stream'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('stream'); - $loader = new StreamLoaderFactory(); - $loader->addConfiguration($rootNode); + $loader->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'stream' => [ @@ -112,12 +104,8 @@ public function testProcessCorrectlyOptionsOnAddConfiguration(): void public function testAddDefaultOptionsIfNotSetOnAddConfiguration(): void { $treeBuilder = new TreeBuilder('stream'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('stream'); - $loader = new StreamLoaderFactory(); - $loader->addConfiguration($rootNode); + $loader->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'stream' => [ diff --git a/tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php b/tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php index a83b7e35f..28110f489 100644 --- a/tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php +++ b/tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php @@ -263,15 +263,11 @@ public function testSetCachePrefixIfDefined(): void public function testThrowBucketNotSetOnAddConfiguration(): void { $this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class); - $this->expectExceptionMessageMatchesBC('/^The child (node|config) "bucket" (at path|under) "aws_s3" must be configured\.$/'); + $this->expectExceptionMessageMatches('/^The child (node|config) "bucket" (at path|under) "aws_s3" must be configured\.$/'); $treeBuilder = new TreeBuilder('aws_s3'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('aws_s3'); - $resolver = new AwsS3ResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $this->processConfigTree($treeBuilder, []); } @@ -279,15 +275,11 @@ public function testThrowBucketNotSetOnAddConfiguration(): void public function testThrowClientConfigNotSetOnAddConfiguration(): void { $this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class); - $this->expectExceptionMessageMatchesBC('/^The child (node|config) "client_config" (at path|under) "aws_s3" must be configured\.$/'); + $this->expectExceptionMessageMatches('/^The child (node|config) "client_config" (at path|under) "aws_s3" must be configured\.$/'); $treeBuilder = new TreeBuilder('aws_s3'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('aws_s3'); - $resolver = new AwsS3ResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $this->processConfigTree($treeBuilder, [ 'aws_s3' => [ @@ -299,15 +291,11 @@ public function testThrowClientConfigNotSetOnAddConfiguration(): void public function testThrowClientConfigNotArrayOnAddConfiguration(): void { $this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class); - $this->expectExceptionMessageMatchesBC('{^Invalid type for path "aws_s3.client_config". Expected (\")?array(\")?, but got (\")?string(\")?$}'); + $this->expectExceptionMessageMatches('{^Invalid type for path "aws_s3.client_config". Expected (\")?array(\")?, but got (\")?string(\")?$}'); $treeBuilder = new TreeBuilder('aws_s3'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('aws_s3'); - $resolver = new AwsS3ResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $this->processConfigTree($treeBuilder, [ 'aws_s3' => [ @@ -336,12 +324,8 @@ public function testProcessCorrectlyOptionsOnAddConfiguration(): void $expectedCachePrefix = 'theCachePrefix'; $treeBuilder = new TreeBuilder('aws_s3'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('aws_s3'); - $resolver = new AwsS3ResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'aws_s3' => [ @@ -378,12 +362,8 @@ public function testAddDefaultOptionsIfNotSetOnAddConfiguration(): void $expectedAcl = 'public-read'; $treeBuilder = new TreeBuilder('aws_s3'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('aws_s3'); - $resolver = new AwsS3ResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'aws_s3' => [ @@ -426,12 +406,8 @@ public function testSupportAwsV3ClientConfig(): void $expectedCachePrefix = 'theCachePrefix'; $treeBuilder = new TreeBuilder('aws_s3'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('aws_s3'); - $resolver = new AwsS3ResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'aws_s3' => [ diff --git a/tests/DependencyInjection/Factory/Resolver/FlysystemResolverFactoryTest.php b/tests/DependencyInjection/Factory/Resolver/FlysystemResolverFactoryTest.php index aa11e39e5..554e6fd4f 100644 --- a/tests/DependencyInjection/Factory/Resolver/FlysystemResolverFactoryTest.php +++ b/tests/DependencyInjection/Factory/Resolver/FlysystemResolverFactoryTest.php @@ -11,8 +11,6 @@ namespace Liip\ImagineBundle\Tests\DependencyInjection\Factory\Resolver; -use League\Flysystem\FilesystemInterface; -use League\Flysystem\FilesystemOperator; use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\FlysystemResolverFactory; use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface; use PHPUnit\Framework\TestCase; @@ -26,17 +24,6 @@ */ class FlysystemResolverFactoryTest extends TestCase { - protected function setUp(): void - { - parent::setUp(); - - if (!interface_exists(FilesystemInterface::class) - && !interface_exists(FilesystemOperator::class) - ) { - $this->markTestSkipped('Requires the league/flysystem package.'); - } - } - public function testImplementsResolverFactoryInterface(): void { $rc = new \ReflectionClass(FlysystemResolverFactory::class); @@ -75,11 +62,7 @@ public function testCreateResolverDefinitionOnCreate(): void $resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name'); $this->assertInstanceOf(ChildDefinition::class, $resolverDefinition); - if (interface_exists(FilesystemOperator::class)) { - $resolverName = 'liip_imagine.cache.resolver.prototype.flysystem2'; - } else { - $resolverName = 'liip_imagine.cache.resolver.prototype.flysystem'; - } + $resolverName = 'liip_imagine.cache.resolver.prototype.flysystem2'; $this->assertSame($resolverName, $resolverDefinition->getParent()); $this->assertSame('http://images.example.com', $resolverDefinition->getArgument(2)); @@ -95,12 +78,8 @@ public function testProcessCorrectlyOptionsOnAddConfiguration(): void $expectedVisibility = 'public'; $treeBuilder = new TreeBuilder('flysystem'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('flysystem'); - $resolver = new FlysystemResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'flysystem' => [ @@ -129,12 +108,8 @@ public function testAddDefaultOptionsIfNotSetOnAddConfiguration(): void $this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class); $treeBuilder = new TreeBuilder('flysystem'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('flysystem'); - $resolver = new FlysystemResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $this->processConfigTree($treeBuilder, [ 'flysystem' => [], @@ -143,8 +118,6 @@ public function testAddDefaultOptionsIfNotSetOnAddConfiguration(): void protected function processConfigTree(TreeBuilder $treeBuilder, array $configs): array { - $processor = new Processor(); - - return $processor->process($treeBuilder->buildTree(), $configs); + return (new Processor())->process($treeBuilder->buildTree(), $configs); } } diff --git a/tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php b/tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php index f25391ec3..4f4f6d90a 100644 --- a/tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php +++ b/tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php @@ -73,12 +73,8 @@ public function testProcessCorrectlyOptionsOnAddConfiguration(): void $expectedCachePrefix = 'theCachePrefix'; $treeBuilder = new TreeBuilder('web_path'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('web_path'); - $resolver = new WebPathResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'web_path' => [ @@ -97,12 +93,8 @@ public function testProcessCorrectlyOptionsOnAddConfiguration(): void public function testAddDefaultOptionsIfNotSetOnAddConfiguration(): void { $treeBuilder = new TreeBuilder('web_path'); - $rootNode = method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('web_path'); - $resolver = new WebPathResolverFactory(); - $resolver->addConfiguration($rootNode); + $resolver->addConfiguration($treeBuilder->getRootNode()); $config = $this->processConfigTree($treeBuilder, [ 'web_path' => [], diff --git a/tests/DependencyInjection/LiipImagineExtensionTest.php b/tests/DependencyInjection/LiipImagineExtensionTest.php index 440430020..251354e0e 100644 --- a/tests/DependencyInjection/LiipImagineExtensionTest.php +++ b/tests/DependencyInjection/LiipImagineExtensionTest.php @@ -155,19 +155,11 @@ public function testFactoriesConfiguration($service, $factory): void protected function createConfigurationWithDefaultsFilterSets(): void { - if (!class_exists(Parser::class)) { - $this->markTestSkipped('Requires the symfony/yaml package.'); - } - $this->createConfiguration($this->getConfigurationWithDefaultsFilterSets()); } protected function createConfigurationWithOneEmptyFilterSet(): void { - if (!class_exists(Parser::class)) { - $this->markTestSkipped('Requires the symfony/yaml package.'); - } - $this->createConfiguration($this->getConfigurationWithOneEmptyFilterSet()); } @@ -177,9 +169,8 @@ protected function getConfigurationWithOneEmptyFilterSet() filter_sets: empty_filter_set: ~ EOF; - $parser = new Parser(); - return $parser->parse($yaml); + return (new Parser())->parse($yaml); } protected function getConfigurationWithDefaultsFilterSets() @@ -205,9 +196,8 @@ protected function getConfigurationWithDefaultsFilterSets() thumbnail: { size: [483, 350] } fixed: { width: 120, height: 90 } EOF; - $parser = new Parser(); - return $parser->parse($yaml); + return (new Parser())->parse($yaml); } protected function createEmptyConfiguration(): void @@ -264,9 +254,8 @@ protected function getFullConfig() quality: 100 data_loader: my_loader EOF; - $parser = new Parser(); - return $parser->parse($yaml); + return (new Parser())->parse($yaml); } private function assertAlias(string $value, string $key): void @@ -281,7 +270,7 @@ private function assertParameter(string $value, string $key): void private function assertHasDefinition(string $id): void { - $this->assertTrue($this->containerBuilder->hasDefinition($id) ?: $this->containerBuilder->hasAlias($id)); + $this->assertTrue($this->containerBuilder->hasDefinition($id) || $this->containerBuilder->hasAlias($id)); } private function assertHasNotDefinition(string $id): void @@ -313,7 +302,6 @@ private function assertDefinitionIsDeprecated(string $id, string $message): void $definition = $this->containerBuilder->getDefinition($id); $this->assertTrue($definition->isDeprecated()); - $deprecation = method_exists(Definition::class, 'getDeprecation') ? $definition->getDeprecation($id)['message'] : $definition->getDeprecationMessage($id); - $this->assertSame($message, $deprecation); + $this->assertSame($message, $definition->getDeprecation($id)['message']); } } diff --git a/tests/Form/Type/ImageTypeTest.php b/tests/Form/Type/ImageTypeTest.php index 881a59041..3d5281dad 100644 --- a/tests/Form/Type/ImageTypeTest.php +++ b/tests/Form/Type/ImageTypeTest.php @@ -13,7 +13,6 @@ use Liip\ImagineBundle\Form\Type\ImageType; use Liip\ImagineBundle\Tests\AbstractTest; -use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; @@ -24,15 +23,6 @@ */ class ImageTypeTest extends AbstractTest { - protected function setUp(): void - { - if (!class_exists(AbstractType::class)) { - $this->markTestSkipped('Requires the symfony/form package.'); - } - - parent::setUp(); - } - public function testGetParent(): void { $type = new ImageType(); @@ -69,7 +59,7 @@ public function testBuildView(): void $view = new FormView(); $type = new ImageType(); - $form = $this->createObjectMock(FormInterface::class); + $form = $this->createMock(FormInterface::class); $type->buildView($view, $form, $options); diff --git a/tests/Functional/AbstractWebTestCase.php b/tests/Functional/AbstractWebTestCase.php index 90e761215..a6ac18de1 100644 --- a/tests/Functional/AbstractWebTestCase.php +++ b/tests/Functional/AbstractWebTestCase.php @@ -25,19 +25,11 @@ public static function getKernelClass(): string protected function getService(string $name): ?object { - if (property_exists($this, 'container')) { - return static::$container->get($name); - } - return static::$kernel->getContainer()->get($name); } protected function getParameter(string $name) { - if (property_exists($this, 'container')) { - return static::$container->getParameter($name); - } - return static::$kernel->getContainer()->getParameter($name); } diff --git a/tests/Functional/app/AppKernel.php b/tests/Functional/app/AppKernel.php index 310f32050..4d97beb7f 100644 --- a/tests/Functional/app/AppKernel.php +++ b/tests/Functional/app/AppKernel.php @@ -50,12 +50,7 @@ public function getProjectDir(): string public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(function (ContainerBuilder $container) use ($loader) { - if (version_compare(self::VERSION, '5.3', '>=')) { - $loader->load($this->getProjectDir().'/config/symfony_5-3.yaml'); - } else { - $loader->load($this->getProjectDir().'/config/symfony_legacy.yaml'); - } - + $loader->load($this->getProjectDir().'/config/symfony.yaml'); $loader->load($this->getProjectDir().'/config/config.yml'); $container diff --git a/tests/Functional/app/config/symfony_5-3.yaml b/tests/Functional/app/config/symfony.yaml similarity index 100% rename from tests/Functional/app/config/symfony_5-3.yaml rename to tests/Functional/app/config/symfony.yaml diff --git a/tests/Functional/app/config/symfony_legacy.yaml b/tests/Functional/app/config/symfony_legacy.yaml deleted file mode 100644 index 06e6bb543..000000000 --- a/tests/Functional/app/config/symfony_legacy.yaml +++ /dev/null @@ -1,3 +0,0 @@ -framework: - session: - storage_id: session.storage.mock_file diff --git a/tests/Imagine/Cache/CacheManagerTest.php b/tests/Imagine/Cache/CacheManagerTest.php index 883274da6..42f252fba 100644 --- a/tests/Imagine/Cache/CacheManagerTest.php +++ b/tests/Imagine/Cache/CacheManagerTest.php @@ -15,6 +15,7 @@ use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; use Liip\ImagineBundle\Imagine\Cache\Signer; +use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; use Liip\ImagineBundle\ImagineEvents; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Tests\AbstractTest; @@ -22,8 +23,8 @@ use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\RouterInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; -use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; /** * @covers \Liip\ImagineBundle\Imagine\Cache\CacheManager @@ -33,13 +34,13 @@ class CacheManagerTest extends AbstractTest public function testAddCacheManagerAwareResolver(): void { $cacheManager = new CacheManager( - $this->createFilterConfigurationMock(), - $this->createRouterInterfaceMock(), + $this->createMock(FilterConfiguration::class), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); - $resolver = $this->createCacheManagerAwareResolverMock(); + $resolver = $this->createMock(CacheManagerAwareResolver::class); $resolver ->expects($this->once()) ->method('setCacheManager') @@ -53,7 +54,7 @@ public function testGetBrowserPathWithoutResolver(): void $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Could not find resolver "default" for "thumbnail" filter type'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -66,9 +67,9 @@ public function testGetBrowserPathWithoutResolver(): void $cacheManager = new CacheManager( $config, - $this->createRouterInterfaceMock(), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->getBrowserPath('cats.jpeg', 'thumbnail'); } @@ -76,10 +77,10 @@ public function testGetBrowserPathWithoutResolver(): void public function testGetRuntimePath(): void { $cacheManager = new CacheManager( - $this->createFilterConfigurationMock(), - $this->createRouterInterfaceMock(), + $this->createMock(FilterConfiguration::class), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $rcPath = $cacheManager->getRuntimePath('image.jpg', [ @@ -93,7 +94,7 @@ public function testGetRuntimePath(): void public function testDefaultResolverUsedIfNoneSetOnGetBrowserPath(): void { - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('isStored') @@ -105,7 +106,7 @@ public function testDefaultResolverUsedIfNoneSetOnGetBrowserPath(): void ->with('cats.jpeg', 'thumbnail') ->willReturn('http://a/path/to/an/image.png'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->exactly(2)) ->method('get') @@ -116,7 +117,7 @@ public function testDefaultResolverUsedIfNoneSetOnGetBrowserPath(): void 'cache' => null, ]); - $router = $this->createRouterInterfaceMock(); + $router = $this->createMock(RouterInterface::class); $router ->expects($this->never()) ->method('generate'); @@ -125,7 +126,7 @@ public function testDefaultResolverUsedIfNoneSetOnGetBrowserPath(): void $config, $router, new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver('default', $resolver); @@ -136,7 +137,7 @@ public function testDefaultResolverUsedIfNoneSetOnGetBrowserPath(): void public function testDefaultResolverUsedIfNoneSetOnGetBrowserPathWithWebPGenerate(): void { - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->never()) ->method('isStored'); @@ -144,12 +145,12 @@ public function testDefaultResolverUsedIfNoneSetOnGetBrowserPathWithWebPGenerate ->expects($this->never()) ->method('resolve'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->never()) ->method('get'); - $router = $this->createRouterInterfaceMock(); + $router = $this->createMock(RouterInterface::class); $router ->expects($this->once()) ->method('generate') @@ -159,7 +160,7 @@ public function testDefaultResolverUsedIfNoneSetOnGetBrowserPathWithWebPGenerate $config, $router, new Signer('secret'), - $this->createEventDispatcherInterfaceMock(), + $this->createEventDispatcherMock(), null, true ); @@ -172,7 +173,7 @@ public function testDefaultResolverUsedIfNoneSetOnGetBrowserPathWithWebPGenerate public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBrowserPath(): void { - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('isStored') @@ -182,7 +183,7 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr ->expects($this->never()) ->method('resolve'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -193,7 +194,7 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr 'cache' => null, ]); - $router = $this->createRouterInterfaceMock(); + $router = $this->createMock(RouterInterface::class); $router ->expects($this->once()) ->method('generate') @@ -203,7 +204,7 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr $config, $router, new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver('default', $resolver); @@ -220,7 +221,7 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr ], ]; - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('isStored') @@ -230,7 +231,7 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr ->expects($this->never()) ->method('resolve'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -241,7 +242,7 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr 'cache' => null, ]); - $router = $this->createRouterInterfaceMock(); + $router = $this->createMock(RouterInterface::class); $router ->expects($this->once()) ->method('generate') @@ -251,7 +252,7 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr $config, $router, new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver('default', $resolver); @@ -268,7 +269,7 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr ], ]; - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->never()) ->method('isStored'); @@ -276,12 +277,12 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr ->expects($this->never()) ->method('resolve'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->never()) ->method('get'); - $router = $this->createRouterInterfaceMock(); + $router = $this->createMock(RouterInterface::class); $router ->expects($this->once()) ->method('generate') @@ -291,7 +292,7 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr $config, $router, new Signer('secret'), - $this->createEventDispatcherInterfaceMock(), + $this->createEventDispatcherMock(), null, true ); @@ -302,16 +303,28 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr $this->assertSame('/media/cache/thumbnail/rc/VhOzTGRB/cats.jpeg', $actualBrowserPath); } + /** + * @return string[] + */ + public function invalidPathProvider(): array + { + return [ + [$this->fixturesPath.'/assets/../../foobar.png'], + [$this->fixturesPath.'/assets/some_folder/../foobar.png'], + ['../../outside/foobar.jpg'], + ]; + } + /** * @dataProvider invalidPathProvider */ public function testResolveInvalidPath(string $path): void { $cacheManager = new CacheManager( - $this->createFilterConfigurationMock(), - $this->createRouterInterfaceMock(), + $this->createMock(FilterConfiguration::class), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $this->expectException(NotFoundHttpException::class); @@ -325,10 +338,10 @@ public function testThrowsIfConcreteResolverNotExists(): void $this->expectExceptionMessage('Could not find resolver "default" for "thumbnail" filter type'); $cacheManager = new CacheManager( - $this->createFilterConfigurationMock(), - $this->createRouterInterfaceMock(), + $this->createMock(FilterConfiguration::class), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $this->assertFalse($cacheManager->resolve('cats.jpeg', 'thumbnail')); @@ -338,7 +351,7 @@ public function testFallbackToDefaultResolver(): void { $binary = new Binary('aContent', 'image/png', 'png'); - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('resolve') @@ -353,7 +366,7 @@ public function testFallbackToDefaultResolver(): void ->method('remove') ->with(['/thumbs/cats.jpeg'], ['thumbnail']); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->exactly(3)) ->method('get') @@ -366,9 +379,9 @@ public function testFallbackToDefaultResolver(): void $cacheManager = new CacheManager( $config, - $this->createRouterInterfaceMock(), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver('default', $resolver); @@ -386,7 +399,7 @@ public function testGenerateUrl(): void $path = 'thePath'; $expectedUrl = 'theUrl'; - $routerMock = $this->createRouterInterfaceMock(); + $routerMock = $this->createMock(RouterInterface::class); $routerMock ->expects($this->once()) ->method('generate') @@ -401,10 +414,10 @@ public function testGenerateUrl(): void ->willReturn($expectedUrl); $cacheManager = new CacheManager( - $this->createFilterConfigurationMock(), + $this->createMock(FilterConfiguration::class), $routerMock, new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $this->assertSame( @@ -418,13 +431,13 @@ public function testRemoveCacheForPathAndFilterOnRemove(): void $expectedPath = 'thePath'; $expectedFilter = 'theFilter'; - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('remove') ->with([$expectedPath], [$expectedFilter]); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -436,9 +449,9 @@ public function testRemoveCacheForPathAndFilterOnRemove(): void $cacheManager = new CacheManager( $config, - $this->createRouterInterfaceMock(), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver($expectedFilter, $resolver); $cacheManager->remove($expectedPath, $expectedFilter); @@ -450,19 +463,19 @@ public function testRemoveCacheForPathAndSomeFiltersOnRemove(): void $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $resolverOne = $this->createCacheResolverInterfaceMock(); + $resolverOne = $this->createMock(ResolverInterface::class); $resolverOne ->expects($this->once()) ->method('remove') ->with([$expectedPath], [$expectedFilterOne]); - $resolverTwo = $this->createCacheResolverInterfaceMock(); + $resolverTwo = $this->createMock(ResolverInterface::class); $resolverTwo ->expects($this->once()) ->method('remove') ->with([$expectedPath], [$expectedFilterTwo]); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -474,9 +487,9 @@ public function testRemoveCacheForPathAndSomeFiltersOnRemove(): void $cacheManager = new CacheManager( $config, - $this->createRouterInterfaceMock(), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver($expectedFilterOne, $resolverOne); $cacheManager->addResolver($expectedFilterTwo, $resolverTwo); @@ -489,7 +502,7 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove(): void $expectedPathTwo = 'thePathTwo'; $expectedFilter = 'theFilter'; - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('remove') @@ -498,7 +511,7 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove(): void [$expectedFilter] ); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -510,9 +523,9 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove(): void $cacheManager = new CacheManager( $config, - $this->createRouterInterfaceMock(), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver($expectedFilter, $resolver); $cacheManager->remove([$expectedPathOne, $expectedPathTwo], $expectedFilter); @@ -525,19 +538,19 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove(): void $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $resolverOne = $this->createCacheResolverInterfaceMock(); + $resolverOne = $this->createMock(ResolverInterface::class); $resolverOne ->expects($this->once()) ->method('remove') ->with([$expectedPathOne, $expectedPathTwo], [$expectedFilterOne]); - $resolverTwo = $this->createCacheResolverInterfaceMock(); + $resolverTwo = $this->createMock(ResolverInterface::class); $resolverTwo ->expects($this->once()) ->method('remove') ->with([$expectedPathOne, $expectedPathTwo], [$expectedFilterTwo]); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -549,9 +562,9 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove(): void $cacheManager = new CacheManager( $config, - $this->createRouterInterfaceMock(), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver($expectedFilterOne, $resolverOne); $cacheManager->addResolver($expectedFilterTwo, $resolverTwo); @@ -566,19 +579,19 @@ public function testRemoveCacheForAllFiltersOnRemove(): void $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $resolverOne = $this->createCacheResolverInterfaceMock(); + $resolverOne = $this->createMock(ResolverInterface::class); $resolverOne ->expects($this->once()) ->method('remove') ->with([], [$expectedFilterOne]); - $resolverTwo = $this->createCacheResolverInterfaceMock(); + $resolverTwo = $this->createMock(ResolverInterface::class); $resolverTwo ->expects($this->once()) ->method('remove') ->with([], [$expectedFilterTwo]); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -597,9 +610,9 @@ public function testRemoveCacheForAllFiltersOnRemove(): void $cacheManager = new CacheManager( $config, - $this->createRouterInterfaceMock(), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver($expectedFilterOne, $resolverOne); $cacheManager->addResolver($expectedFilterTwo, $resolverTwo); @@ -612,19 +625,19 @@ public function testRemoveCacheForPathAndAllFiltersOnRemove(): void $expectedFilterTwo = 'theFilterTwo'; $expectedPath = 'thePath'; - $resolverOne = $this->createCacheResolverInterfaceMock(); + $resolverOne = $this->createMock(ResolverInterface::class); $resolverOne ->expects($this->once()) ->method('remove') ->with([$expectedPath], [$expectedFilterOne]); - $resolverTwo = $this->createCacheResolverInterfaceMock(); + $resolverTwo = $this->createMock(ResolverInterface::class); $resolverTwo ->expects($this->once()) ->method('remove') ->with([$expectedPath], [$expectedFilterTwo]); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -643,9 +656,9 @@ public function testRemoveCacheForPathAndAllFiltersOnRemove(): void $cacheManager = new CacheManager( $config, - $this->createRouterInterfaceMock(), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver($expectedFilterOne, $resolverOne); $cacheManager->addResolver($expectedFilterTwo, $resolverTwo); @@ -657,13 +670,13 @@ public function testAggregateFiltersByResolverOnRemove(): void $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('remove') ->with([], [$expectedFilterOne, $expectedFilterTwo]); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -675,9 +688,9 @@ public function testAggregateFiltersByResolverOnRemove(): void $cacheManager = new CacheManager( $config, - $this->createRouterInterfaceMock(), + $this->createMock(RouterInterface::class), new Signer('secret'), - $this->createEventDispatcherInterfaceMock() + $this->createEventDispatcherMock() ); $cacheManager->addResolver($expectedFilterOne, $resolver); $cacheManager->addResolver($expectedFilterTwo, $resolver); @@ -686,64 +699,64 @@ public function testAggregateFiltersByResolverOnRemove(): void public function testShouldDispatchCacheResolveEvents(): void { - $dispatcher = $this->createEventDispatcherInterfaceMock(); + $dispatcher = $this->createEventDispatcherMock(); $dispatcher ->expects($this->exactly(2)) ->method('dispatch') ->withConsecutive( - $this->getDispatcherArgumentsWithBC($dispatcher, [ + [ new CacheResolveEvent('cats.jpg', 'thumbnail'), ImagineEvents::PRE_RESOLVE, - ]), - $this->getDispatcherArgumentsWithBC($dispatcher, [ + ], + [ new CacheResolveEvent('cats.jpg', 'thumbnail'), ImagineEvents::POST_RESOLVE, - ]) + ] ); $cacheManager = new CacheManager( - $this->createFilterConfigurationMock(), - $this->createRouterInterfaceMock(), + $this->createMock(FilterConfiguration::class), + $this->createMock(RouterInterface::class), new Signer('secret'), $dispatcher ); - $cacheManager->addResolver('default', $this->createCacheResolverInterfaceMock()); + $cacheManager->addResolver('default', $this->createMock(ResolverInterface::class)); $cacheManager->resolve('cats.jpg', 'thumbnail'); } public function testShouldAllowToPassChangedDataFromPreResolveEventToResolver(): void { - $dispatcher = $this->createEventDispatcherInterfaceMock(); + $dispatcher = $this->createEventDispatcherMock(); $dispatcher ->method('dispatch') ->withConsecutive( - $this->getDispatcherArgumentsWithBC($dispatcher, [ + [ $this->isInstanceOf(CacheResolveEvent::class), ImagineEvents::PRE_RESOLVE, - ]), - $this->getDispatcherArgumentsWithBC($dispatcher, [ + ], + [ $this->isInstanceOf(CacheResolveEvent::class), ImagineEvents::POST_RESOLVE, - ]) + ] ) - ->willReturnCallback($this->getDispatcherCallbackWithBC($dispatcher, function (CacheResolveEvent $event, string $eventName) { + ->willReturnCallback(function (CacheResolveEvent $event, string $eventName) { if (ImagineEvents::PRE_RESOLVE !== $eventName) { return; } $event->setPath('changed_path'); $event->setFilter('changed_filter'); - })); + }); - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('resolve') ->with('changed_path', 'changed_filter'); $cacheManager = new CacheManager( - $this->createFilterConfigurationMock(), - $this->createRouterInterfaceMock(), + $this->createMock(FilterConfiguration::class), + $this->createMock(RouterInterface::class), new Signer('secret'), $dispatcher ); @@ -754,22 +767,22 @@ public function testShouldAllowToPassChangedDataFromPreResolveEventToResolver(): public function testShouldAllowToGetResolverByFilterChangedInPreResolveEvent(): void { - $dispatcher = $this->createEventDispatcherInterfaceMock(); + $dispatcher = $this->createEventDispatcherMock(); $dispatcher ->method('dispatch') - ->willReturnCallback($this->getDispatcherCallbackWithBC($dispatcher, function (CacheResolveEvent $event, string $eventName) { + ->willReturnCallback(function (CacheResolveEvent $event, string $eventName) { if (ImagineEvents::PRE_RESOLVE !== $eventName) { return; } $event->setFilter('thumbnail'); - })); + }); $cacheManager = $this ->getMockBuilder(CacheManager::class) ->setMethods(['getResolver']) ->setConstructorArgs([ - $this->createFilterConfigurationMock(), - $this->createRouterInterfaceMock(), + $this->createMock(FilterConfiguration::class), + $this->createMock(RouterInterface::class), new Signer('secret'), $dispatcher, ])->getMock(); @@ -778,23 +791,23 @@ public function testShouldAllowToGetResolverByFilterChangedInPreResolveEvent(): ->expects($this->once()) ->method('getResolver') ->with('thumbnail') - ->willReturn($this->createCacheResolverInterfaceMock()); + ->willReturn($this->createMock(ResolverInterface::class)); $cacheManager->resolve('cats.jpg', 'default'); } public function testShouldAllowToPassChangedDataFromPreResolveEventToPostResolveEvent(): void { - $dispatcher = $this->createEventDispatcherInterfaceMock(); + $dispatcher = $this->createEventDispatcherMock(); $dispatcher ->expects($this->exactly(2)) ->method('dispatch') ->withConsecutive( - $this->getDispatcherArgumentsWithBC($dispatcher, [ + [ $this->isInstanceOf(CacheResolveEvent::class), ImagineEvents::PRE_RESOLVE, - ]), - $this->getDispatcherArgumentsWithBC($dispatcher, [ + ], + [ $this->logicalAnd( $this->isInstanceOf(CacheResolveEvent::class), $this->callback(function (CacheResolveEvent $event) { @@ -802,95 +815,67 @@ public function testShouldAllowToPassChangedDataFromPreResolveEventToPostResolve }) ), ImagineEvents::POST_RESOLVE, - ]) + ] ) - ->willReturnCallback($this->getDispatcherCallbackWithBC($dispatcher, function (CacheResolveEvent $event, string $eventName) { + ->willReturnCallback(function (CacheResolveEvent $event, string $eventName) { if (ImagineEvents::PRE_RESOLVE !== $eventName) { return; } $event->setPath('changed_path'); $event->setFilter('changed_filter'); - })); + }); $cacheManager = new CacheManager( - $this->createFilterConfigurationMock(), - $this->createRouterInterfaceMock(), + $this->createMock(FilterConfiguration::class), + $this->createMock(RouterInterface::class), new Signer('secret'), $dispatcher ); - $cacheManager->addResolver('default', $this->createCacheResolverInterfaceMock()); + $cacheManager->addResolver('default', $this->createMock(ResolverInterface::class)); $cacheManager->resolve('cats.jpg', 'thumbnail'); } public function testShouldReturnUrlChangedInPostResolveEvent(): void { - $dispatcher = $this->createEventDispatcherInterfaceMock(); + $dispatcher = $this->createEventDispatcherMock(); $dispatcher ->method('dispatch') ->withConsecutive( - $this->getDispatcherArgumentsWithBC($dispatcher, [ + [ $this->isInstanceOf(CacheResolveEvent::class), ImagineEvents::PRE_RESOLVE, - ]), - $this->getDispatcherArgumentsWithBC($dispatcher, [ + ], + [ $this->isInstanceOf(CacheResolveEvent::class), ImagineEvents::POST_RESOLVE, - ]) + ] ) - ->willReturnCallback($this->getDispatcherCallbackWithBC($dispatcher, function (CacheResolveEvent $event, string $eventName) { + ->willReturnCallback(function (CacheResolveEvent $event, string $eventName) { if (ImagineEvents::POST_RESOLVE !== $eventName) { return; } $event->setUrl('changed_url'); - })); + }); $cacheManager = new CacheManager( - $this->createFilterConfigurationMock(), - $this->createRouterInterfaceMock(), + $this->createMock(FilterConfiguration::class), + $this->createMock(RouterInterface::class), new Signer('secret'), $dispatcher ); - $cacheManager->addResolver('default', $this->createCacheResolverInterfaceMock()); + $cacheManager->addResolver('default', $this->createMock(ResolverInterface::class)); $this->assertSame('changed_url', $cacheManager->resolve('cats.jpg', 'thumbnail')); } - /** - * @return MockObject&ResolverInterface - */ - private function createCacheManagerAwareResolverMock() + private function createEventDispatcherMock(): EventDispatcherInterface&MockObject { - return $this - ->getMockBuilder(CacheManagerAwareResolver::class) - ->getMock(); - } - - /** - * BC Layer for Symfony < 4.3 - */ - private function getDispatcherCallbackWithBC(EventDispatcherInterface $dispatcher, callable $callable): callable - { - return function ($event, $name) use ($dispatcher, $callable) { - if ($dispatcher instanceof ContractsEventDispatcherInterface) { - $callable($event, $name); - } else { - $callable($name, $event); - } - - return $event; - }; - } - - /** - * BC Layer for Symfony < 4.3 - */ - private function getDispatcherArgumentsWithBC(EventDispatcherInterface $dispatcher, array $arguments): array - { - if (!$dispatcher instanceof ContractsEventDispatcherInterface) { - $arguments = [$arguments[1], $arguments[0]]; - } + $mock = $this->createMock(EventDispatcherInterface::class); + $mock + ->method('dispatch') + ->willReturn($this); - return $arguments; + return $mock; } } diff --git a/tests/Imagine/Cache/Resolver/AwsS3ResolverTest.php b/tests/Imagine/Cache/Resolver/AwsS3ResolverTest.php index 8404f4f99..c2f66ed2a 100644 --- a/tests/Imagine/Cache/Resolver/AwsS3ResolverTest.php +++ b/tests/Imagine/Cache/Resolver/AwsS3ResolverTest.php @@ -17,6 +17,7 @@ use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Tests\AbstractTest; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; /** * @covers \Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver @@ -70,7 +71,7 @@ public function testLogNotCreatedObjects(): void ->method('putObject') ->will($this->throwException(new \Exception('Put object on amazon failed'))); - $logger = $this->createLoggerInterfaceMock(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) ->method('error'); @@ -283,7 +284,7 @@ public function testCatchAndLogExceptionsForPathAndFilterOnRemove(): void ->method('deleteObject') ->will($this->throwException(new \Exception())); - $logger = $this->createLoggerInterfaceMock(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) ->method('error'); @@ -335,7 +336,7 @@ public function testCatchAndLogExceptionForFilterOnRemove(): void ->method('deleteMatchingObjects') ->will($this->throwException(new \Exception())); - $logger = $this->createLoggerInterfaceMock(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) ->method('error'); diff --git a/tests/Imagine/Cache/Resolver/FlysystemResolverTest.php b/tests/Imagine/Cache/Resolver/FlysystemResolverTest.php deleted file mode 100644 index ced532740..000000000 --- a/tests/Imagine/Cache/Resolver/FlysystemResolverTest.php +++ /dev/null @@ -1,256 +0,0 @@ -markTestSkipped('The league/flysystem:^1.0 PHP library is not available.'); - } - } - - public function testImplementsResolverInterface(): void - { - $rc = new \ReflectionClass(FlysystemResolver::class); - - $this->assertTrue($rc->implementsInterface(ResolverInterface::class)); - } - - public function testResolveUriForFilter(): void - { - $resolver = new FlysystemResolver($this->createFlySystemMock(), new RequestContext(), 'http://images.example.com'); - - $this->assertSame( - 'http://images.example.com/media/cache/thumb/some-folder/path.jpg', - $resolver->resolve('/some-folder/path.jpg', 'thumb') - ); - } - - public function testRemoveObjectsForFilter(): void - { - $expectedFilter = 'theFilter'; - $fs = $this->createFlySystemMock(); - $fs - ->expects($this->once()) - ->method('deleteDir') - ->with('media/cache/theFilter'); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove([], [$expectedFilter]); - } - - public function testCreateObjectInAdapter(): void - { - $binary = new Binary('aContent', 'image/jpeg', 'jpeg'); - - $fs = $this->createFlySystemMock(); - $fs - ->expects($this->once()) - ->method('put') - ->willReturn(true); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - - $this->assertNull($resolver->store($binary, 'thumb/foobar.jpg', 'thumb')); - } - - public function testIsStoredChecksObjectExistence(): void - { - $fs = $this->createFlySystemMock(); - $fs - ->expects($this->once()) - ->method('has') - ->willReturn(false); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - - $this->assertFalse($resolver->isStored('/some-folder/path.jpg', 'thumb')); - } - - public function testReturnResolvedImageUrlOnResolve(): void - { - $fs = $this->createFlySystemMock(); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - - $this->assertSame( - 'http://images.example.com/media/cache/thumb/some-folder/path.jpg', - $resolver->resolve('/some-folder/path.jpg', 'thumb') - ); - } - - public function testResolveWithPrefixCacheEmpty(): void - { - $resolver = new FlysystemResolver($this->createFlySystemMock(), new RequestContext(), 'http://images.example.com', ''); - - $this->assertSame( - 'http://images.example.com/thumb/some-folder/path.jpg', - $resolver->resolve('/some-folder/path.jpg', 'thumb') - ); - } - - public function testRemoveCacheForPathAndFilterOnRemove(): void - { - $fs = $this->createFlySystemMock(); - $fs - ->expects($this->once()) - ->method('has') - ->with('media/cache/thumb/some-folder/path.jpg') - ->willReturn(true); - $fs - ->expects($this->once()) - ->method('delete') - ->with('media/cache/thumb/some-folder/path.jpg') - ->willReturn(true); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove(['some-folder/path.jpg'], ['thumb']); - } - - public function testRemoveCacheForSomePathsAndFilterOnRemove(): void - { - $fs = $this->createFlySystemMock(); - $fs - ->expects($this->exactly(2)) - ->method('has') - ->withConsecutive( - ['media/cache/thumb/pathOne.jpg'], - ['media/cache/thumb/pathTwo.jpg'] - ) - ->willReturn(true); - $fs - ->method('delete') - ->withConsecutive( - ['media/cache/thumb/pathOne.jpg'], - ['media/cache/thumb/pathTwo.jpg'] - ) - ->willReturn(true); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove( - ['pathOne.jpg', 'pathTwo.jpg'], - ['thumb'] - ); - } - - public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove(): void - { - $fs = $this->createFlySystemMock(); - $fs - ->expects($this->exactly(4)) - ->method('has') - ->withConsecutive( - ['media/cache/filterOne/pathOne.jpg'], - ['media/cache/filterTwo/pathOne.jpg'], - ['media/cache/filterOne/pathTwo.jpg'], - ['media/cache/filterTwo/pathTwo.jpg'] - ) - ->willReturn(true); - $fs - ->method('delete') - ->withConsecutive( - ['media/cache/filterOne/pathOne.jpg'], - ['media/cache/filterTwo/pathOne.jpg'], - ['media/cache/filterOne/pathTwo.jpg'], - ['media/cache/filterTwo/pathTwo.jpg'] - ) - ->willReturn(true); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove( - ['pathOne.jpg', 'pathTwo.jpg'], - ['filterOne', 'filterTwo'] - ); - } - - public function testDoNothingWhenObjectNotExistForPathAndFilterOnRemove(): void - { - $fs = $this->createFlySystemMock(); - $fs - ->expects($this->once()) - ->method('has') - ->with('media/cache/thumb/some-folder/path.jpg') - ->willReturn(false); - $fs - ->expects($this->never()) - ->method('delete'); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove(['some-folder/path.jpg'], ['thumb']); - } - - public function testRemoveCacheForFilterOnRemove(): void - { - $expectedFilter = 'theFilter'; - - $fs = $this->createFlySystemMock(); - $fs - ->expects($this->once()) - ->method('deleteDir') - ->with('media/cache/theFilter'); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove([], [$expectedFilter]); - } - - public function testRemoveCacheForSomeFiltersOnRemove(): void - { - $expectedFilterOne = 'theFilterOne'; - $expectedFilterTwo = 'theFilterTwo'; - - $fs = $this->createFlySystemMock(); - $fs - ->expects($this->exactly(2)) - ->method('deleteDir') - ->withConsecutive( - ['media/cache/theFilterOne'], - ['media/cache/theFilterTwo'] - ); - - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove([], [$expectedFilterOne, $expectedFilterTwo]); - } - - /** - * @return MockObject&Filesystem - */ - protected function createFlySystemMock() - { - return $this - ->getMockBuilder(Filesystem::class) - ->disableOriginalConstructor() - ->setMethods([ - 'delete', - 'deleteDir', - 'has', - 'put', - 'remove', - ]) - ->getMock(); - } -} diff --git a/tests/Imagine/Cache/Resolver/FlysystemV2ResolverTest.php b/tests/Imagine/Cache/Resolver/FlysystemV2ResolverTest.php index 588068e68..5f7bdd024 100644 --- a/tests/Imagine/Cache/Resolver/FlysystemV2ResolverTest.php +++ b/tests/Imagine/Cache/Resolver/FlysystemV2ResolverTest.php @@ -12,12 +12,10 @@ namespace Liip\ImagineBundle\Tests\Imagine\Cache\Resolver; use League\Flysystem\Filesystem; -use League\Flysystem\FilesystemOperator; use Liip\ImagineBundle\Imagine\Cache\Resolver\FlysystemV2Resolver; use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Tests\AbstractTest; -use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Routing\RequestContext; /** @@ -25,15 +23,6 @@ */ class FlysystemV2ResolverTest extends AbstractTest { - protected function setUp(): void - { - parent::setUp(); - - if (!interface_exists(FilesystemOperator::class)) { - $this->markTestSkipped('The league/flysystem:^2.0 PHP library is not available.'); - } - } - public function testImplementsResolverInterface(): void { $rc = new \ReflectionClass(FlysystemV2Resolver::class); @@ -44,7 +33,7 @@ public function testImplementsResolverInterface(): void public function testResolveUriForFilter(): void { $resolver = new FlysystemV2Resolver( - $this->createFlySystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), 'http://images.example.com' ); @@ -58,7 +47,7 @@ public function testResolveUriForFilter(): void public function testRemoveObjectsForFilter(): void { $expectedFilter = 'theFilter'; - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $fs ->expects($this->once()) ->method('deleteDirectory') @@ -72,7 +61,7 @@ public function testCreateObjectInAdapter(): void { $binary = new Binary('aContent', 'image/jpeg', 'jpeg'); - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $fs ->expects($this->once()) ->method('write'); @@ -84,7 +73,7 @@ public function testCreateObjectInAdapter(): void public function testIsStoredChecksObjectExistence(): void { - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $fs ->expects($this->once()) ->method('fileExists') @@ -97,7 +86,7 @@ public function testIsStoredChecksObjectExistence(): void public function testReturnResolvedImageUrlOnResolve(): void { - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $resolver = new FlysystemV2Resolver($fs, new RequestContext(), 'http://images.example.com'); @@ -110,7 +99,7 @@ public function testReturnResolvedImageUrlOnResolve(): void public function testResolveWithPrefixCacheEmpty(): void { $resolver = new FlysystemV2Resolver( - $this->createFlySystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), 'http://images.example.com', '' @@ -124,7 +113,7 @@ public function testResolveWithPrefixCacheEmpty(): void public function testRemoveCacheForPathAndFilterOnRemove(): void { - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $fs ->expects($this->once()) ->method('fileExists') @@ -141,7 +130,7 @@ public function testRemoveCacheForPathAndFilterOnRemove(): void public function testRemoveCacheForSomePathsAndFilterOnRemove(): void { - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $fs ->expects($this->exactly(2)) ->method('fileExists') @@ -166,7 +155,7 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove(): void public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove(): void { - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $fs ->expects($this->exactly(4)) ->method('fileExists') @@ -195,7 +184,7 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove(): void public function testDoNothingWhenObjectNotExistForPathAndFilterOnRemove(): void { - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $fs ->expects($this->once()) ->method('fileExists') @@ -213,7 +202,7 @@ public function testRemoveCacheForFilterOnRemove(): void { $expectedFilter = 'theFilter'; - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $fs ->expects($this->once()) ->method('deleteDirectory') @@ -228,7 +217,7 @@ public function testRemoveCacheForSomeFiltersOnRemove(): void $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $fs = $this->createFlySystemMock(); + $fs = $this->createMock(Filesystem::class); $fs ->expects($this->exactly(2)) ->method('deleteDirectory') @@ -240,15 +229,4 @@ public function testRemoveCacheForSomeFiltersOnRemove(): void $resolver = new FlysystemV2Resolver($fs, new RequestContext(), 'http://images.example.com'); $resolver->remove([], [$expectedFilterOne, $expectedFilterTwo]); } - - /** - * @return MockObject&Filesystem - */ - protected function createFlySystemMock() - { - return $this - ->getMockBuilder(Filesystem::class) - ->disableOriginalConstructor() - ->getMock(); - } } diff --git a/tests/Imagine/Cache/Resolver/FormatExtensionResolverTest.php b/tests/Imagine/Cache/Resolver/FormatExtensionResolverTest.php index df77bc27d..13fd56694 100644 --- a/tests/Imagine/Cache/Resolver/FormatExtensionResolverTest.php +++ b/tests/Imagine/Cache/Resolver/FormatExtensionResolverTest.php @@ -35,7 +35,7 @@ class FormatExtensionResolverTest extends AbstractTest protected function setUp(): void { - $this->primaryResolver = $this->createObjectMock(ResolverInterface::class); + $this->primaryResolver = $this->createMock(ResolverInterface::class); $filterConfiguration = new FilterConfiguration([ 'thumbnail' => [ 'format' => 'webp', diff --git a/tests/Imagine/Cache/Resolver/ProxyResolverTest.php b/tests/Imagine/Cache/Resolver/ProxyResolverTest.php index 1698f5880..49b15f7df 100644 --- a/tests/Imagine/Cache/Resolver/ProxyResolverTest.php +++ b/tests/Imagine/Cache/Resolver/ProxyResolverTest.php @@ -34,7 +34,7 @@ class ProxyResolverTest extends AbstractTest protected function setUp(): void { - $this->primaryResolver = $this->createObjectMock(ResolverInterface::class); + $this->primaryResolver = $this->createMock(ResolverInterface::class); $this->resolver = new ProxyResolver($this->primaryResolver, ['http://images.example.com']); } diff --git a/tests/Imagine/Cache/Resolver/PsrCacheResolverTest.php b/tests/Imagine/Cache/Resolver/PsrCacheResolverTest.php index 8f2a7ec8a..e2d14d154 100644 --- a/tests/Imagine/Cache/Resolver/PsrCacheResolverTest.php +++ b/tests/Imagine/Cache/Resolver/PsrCacheResolverTest.php @@ -12,6 +12,7 @@ namespace Liip\ImagineBundle\Tests\Imagine\Cache\Resolver; use Liip\ImagineBundle\Imagine\Cache\Resolver\PsrCacheResolver; +use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Tests\AbstractTest; use Symfony\Component\Cache\Adapter\ArrayAdapter; @@ -25,18 +26,9 @@ class PsrCacheResolverTest extends AbstractTest protected $path = 'MadCat2.jpeg'; protected $webPath = '/media/cache/thumbnail/MadCat2.jpeg'; - protected function setUp(): void - { - if (!class_exists(ArrayAdapter::class)) { - $this->markTestSkipped('Requires the symfony/cache package.'); - } - - parent::setUp(); - } - public function testResolveIsSavedToCache(): void { - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('resolve') @@ -54,7 +46,7 @@ public function testResolveIsSavedToCache(): void public function testNotCallInternalResolverIfCachedOnIsStored(): void { - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('resolve') @@ -75,7 +67,7 @@ public function testNotCallInternalResolverIfCachedOnIsStored(): void public function testCallInternalResolverIfNotCachedOnIsStored(): void { - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->exactly(2)) ->method('isStored') @@ -91,7 +83,7 @@ public function testStoreIsForwardedToResolver(): void { $binary = new Binary('aContent', 'image/jpeg', 'jpg'); - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->exactly(2)) ->method('store') @@ -106,7 +98,7 @@ public function testStoreIsForwardedToResolver(): void public function testSavesToCacheIfInternalResolverReturnUrlOnResolve(): void { - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('resolve') @@ -124,7 +116,7 @@ public function testSavesToCacheIfInternalResolverReturnUrlOnResolve(): void public function testRemoveSinglePathCacheOnRemove(): void { - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->once()) ->method('resolve') @@ -154,7 +146,7 @@ public function testRemoveSinglePathCacheOnRemove(): void public function testRemoveAllFilterCacheOnRemove(): void { - $resolver = $this->createCacheResolverInterfaceMock(); + $resolver = $this->createMock(ResolverInterface::class); $resolver ->expects($this->exactly(4)) ->method('resolve') diff --git a/tests/Imagine/Cache/Resolver/WebPathResolverTest.php b/tests/Imagine/Cache/Resolver/WebPathResolverTest.php index 1e3689965..998dfe1f1 100644 --- a/tests/Imagine/Cache/Resolver/WebPathResolverTest.php +++ b/tests/Imagine/Cache/Resolver/WebPathResolverTest.php @@ -14,7 +14,6 @@ use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; use Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver; use Liip\ImagineBundle\Model\Binary; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Routing\RequestContext; @@ -62,7 +61,7 @@ public function testImplementsResolverInterface(): void public function testCouldBeConstructedWithRequiredArguments(): void { - $filesystemMock = $this->createFilesystemMock(); + $filesystemMock = $this->createMock(Filesystem::class); $requestContext = new RequestContext(); $webRoot = 'theWebRoot'; @@ -76,7 +75,7 @@ public function testCouldBeConstructedWithRequiredArguments(): void public function testCouldBeConstructedWithOptionalArguments(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), 'aWebRoot', 'theCachePrefix' @@ -88,7 +87,7 @@ public function testCouldBeConstructedWithOptionalArguments(): void public function testTrimRightSlashFromWebPathOnConstruct(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), 'aWebRoot/', 'theCachePrefix' @@ -100,7 +99,7 @@ public function testTrimRightSlashFromWebPathOnConstruct(): void public function testRemoveDoubleSlashFromWebRootOnConstruct(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), 'aWeb//Root', '/aCachePrefix' @@ -112,7 +111,7 @@ public function testRemoveDoubleSlashFromWebRootOnConstruct(): void public function testTrimRightSlashFromCachePrefixOnConstruct(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), 'aWebRoot', '/aCachePrefix' @@ -124,7 +123,7 @@ public function testTrimRightSlashFromCachePrefixOnConstruct(): void public function testRemoveDoubleSlashFromCachePrefixOnConstruct(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), 'aWebRoot', 'aCache//Prefix' @@ -136,7 +135,7 @@ public function testRemoveDoubleSlashFromCachePrefixOnConstruct(): void public function testReturnTrueIfFileExistsOnIsStored(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), $this->basePath, 'aCachePrefix' @@ -148,7 +147,7 @@ public function testReturnTrueIfFileExistsOnIsStored(): void public function testReturnFalseIfFileNotExistsOnIsStored(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), $this->basePath, 'aCachePrefix' @@ -160,7 +159,7 @@ public function testReturnFalseIfFileNotExistsOnIsStored(): void public function testReturnFalseIfIsNotFile(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), $this->basePath, 'aCachePrefix' @@ -176,7 +175,7 @@ public function testComposeSchemaHostAndFileUrlOnResolve(): void $requestContext->setHost('thehost'); $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), $requestContext, '/aWebRoot', 'aCachePrefix' @@ -196,7 +195,7 @@ public function testComposeSchemaHostAndBasePathWithPhpFileAndFileUrlOnResolve() $requestContext->setBaseUrl('/theBasePath/app.php'); $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), $requestContext, '/aWebRoot', 'aCachePrefix' @@ -216,7 +215,7 @@ public function testResolveWithPrefixCacheEmpty(): void $requestContext->setBaseUrl('/theBasePath/app.php'); $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), $requestContext, '/aWebRoot', '' @@ -236,7 +235,7 @@ public function testComposeSchemaHostAndBasePathWithDirsOnlyAndFileUrlOnResolve( $requestContext->setBaseUrl('/theBasePath/theSubBasePath'); $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), $requestContext, '/aWebRoot', 'aCachePrefix' @@ -256,7 +255,7 @@ public function testComposeSchemaHostAndBasePathWithBackSplashOnResolve(): void $requestContext->setBaseUrl('\\'); $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), $requestContext, '/aWebRoot', 'aCachePrefix' @@ -276,7 +275,7 @@ public function testComposeSchemaHttpAndCustomPortAndFileUrlOnResolve(): void $requestContext->setHttpPort(88); $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), $requestContext, '/aWebRoot', 'aCachePrefix' @@ -296,7 +295,7 @@ public function testComposeSchemaHttpsAndCustomPortAndFileUrlOnResolve(): void $requestContext->setHttpsPort(444); $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), $requestContext, '/aWebRoot', 'aCachePrefix' @@ -312,7 +311,7 @@ public function testDumpBinaryContentOnStore(): void { $binary = new Binary('theContent', 'aMimeType', 'aFormat'); - $filesystemMock = $this->createFilesystemMock(); + $filesystemMock = $this->createMock(Filesystem::class); $filesystemMock ->expects($this->once()) ->method('dumpFile') @@ -330,7 +329,7 @@ public function testDumpBinaryContentOnStore(): void public function testDoNothingIfFiltersAndPathsEmptyOnRemove(): void { - $filesystemMock = $this->createFilesystemMock(); + $filesystemMock = $this->createMock(Filesystem::class); $filesystemMock ->expects($this->never()) ->method('remove'); @@ -347,7 +346,7 @@ public function testDoNothingIfFiltersAndPathsEmptyOnRemove(): void public function testRemoveCacheForPathAndFilterOnRemove(): void { - $filesystemMock = $this->createFilesystemMock(); + $filesystemMock = $this->createMock(Filesystem::class); $filesystemMock ->expects($this->once()) ->method('remove') @@ -365,7 +364,7 @@ public function testRemoveCacheForPathAndFilterOnRemove(): void public function testRemoveCacheForSomePathsAndFilterOnRemove(): void { - $filesystemMock = $this->createFilesystemMock(); + $filesystemMock = $this->createMock(Filesystem::class); $filesystemMock ->expects($this->exactly(2)) ->method('remove') @@ -386,7 +385,7 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove(): void public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove(): void { - $filesystemMock = $this->createFilesystemMock(); + $filesystemMock = $this->createMock(Filesystem::class); $filesystemMock ->expects($this->exactly(4)) ->method('remove') @@ -412,7 +411,7 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove(): void public function testRemoveCacheForFilterOnRemove(): void { - $filesystemMock = $this->createFilesystemMock(); + $filesystemMock = $this->createMock(Filesystem::class); $filesystemMock ->expects($this->once()) ->method('remove') @@ -432,7 +431,7 @@ public function testRemoveCacheForFilterOnRemove(): void public function testRemoveCacheForSomeFiltersOnRemove(): void { - $filesystemMock = $this->createFilesystemMock(); + $filesystemMock = $this->createMock(Filesystem::class); $filesystemMock ->expects($this->once()) ->method('remove') @@ -454,7 +453,7 @@ public function testRemoveCacheForSomeFiltersOnRemove(): void public function testShouldRemoveDoubleSlashInUrl(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), '/aWebRoot', 'aCachePrefix' @@ -472,7 +471,7 @@ public function testShouldRemoveDoubleSlashInUrl(): void public function testShouldSanitizeSeparatorBetweenSchemeAndAuthorityInUrl(): void { $resolver = new WebPathResolver( - $this->createFilesystemMock(), + $this->createMock(Filesystem::class), new RequestContext(), '/aWebRoot', 'aCachePrefix' @@ -500,12 +499,4 @@ public static function assertAttributeSame($expected, string $actualAttributeNam self::assertSame($expected, $actual, $message); } - - /** - * @return MockObject&Filesystem - */ - protected function createFilesystemMock() - { - return $this->getMockBuilder(Filesystem::class)->getMock(); - } } diff --git a/tests/Imagine/Data/DataManagerTest.php b/tests/Imagine/Data/DataManagerTest.php index 57e3e2b28..7a666acf5 100644 --- a/tests/Imagine/Data/DataManagerTest.php +++ b/tests/Imagine/Data/DataManagerTest.php @@ -11,7 +11,10 @@ namespace Liip\ImagineBundle\Tests\Imagine\Data; +use Liip\ImagineBundle\Binary\Loader\LoaderInterface; +use Liip\ImagineBundle\Binary\MimeTypeGuesserInterface; use Liip\ImagineBundle\Imagine\Data\DataManager; +use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Tests\AbstractTest; use Symfony\Component\Mime\MimeTypesInterface; @@ -23,14 +26,14 @@ class DataManagerTest extends AbstractTest { public function testUseDefaultLoaderUsedIfNoneSet(): void { - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('find') ->with('cats.jpeg') ->willReturn('content'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -41,13 +44,13 @@ public function testUseDefaultLoaderUsedIfNoneSet(): void 'data_loader' => null, ]); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->willReturn('image/png'); - $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config, 'default'); + $dataManager = new DataManager($mimeTypeGuesser, $this->createMock(MimeTypesInterface::class), $config, 'default'); $dataManager->addLoader('default', $loader); $dataManager->find('thumbnail', 'cats.jpeg'); @@ -55,14 +58,14 @@ public function testUseDefaultLoaderUsedIfNoneSet(): void public function testUseLoaderRegisteredForFilterOnFind(): void { - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('find') ->with('cats.jpeg') ->willReturn('content'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -73,13 +76,13 @@ public function testUseLoaderRegisteredForFilterOnFind(): void 'data_loader' => 'the_loader', ]); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->willReturn('image/png'); - $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createMock(MimeTypesInterface::class), $config); $dataManager->addLoader('the_loader', $loader); $dataManager->find('thumbnail', 'cats.jpeg'); @@ -87,14 +90,14 @@ public function testUseLoaderRegisteredForFilterOnFind(): void public function testThrowsIfMimeTypeWasNotGuessedOnFind(): void { - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('find') ->with('cats.jpeg') ->willReturn('content'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -105,13 +108,13 @@ public function testThrowsIfMimeTypeWasNotGuessedOnFind(): void 'data_loader' => 'the_loader', ]); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->willReturn(null); - $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createMock(MimeTypesInterface::class), $config); $dataManager->addLoader('the_loader', $loader); $this->expectException(\LogicException::class); @@ -125,14 +128,14 @@ public function testThrowsIfMimeTypeNotImageOneOnFind(): void $this->expectException(\LogicException::class); $this->expectExceptionMessage('The mime type of file cats.jpeg must be image/xxx or application/pdf, got text/plain'); - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('find') ->with('cats.jpeg') ->willReturn('content'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -143,13 +146,13 @@ public function testThrowsIfMimeTypeNotImageOneOnFind(): void 'data_loader' => 'the_loader', ]); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->willReturn('text/plain'); - $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createMock(MimeTypesInterface::class), $config); $dataManager->addLoader('the_loader', $loader); $dataManager->find('thumbnail', 'cats.jpeg'); } @@ -159,14 +162,14 @@ public function testThrowsIfLoaderReturnBinaryWithEmtptyMimeTypeOnFind(): void $this->expectException(\LogicException::class); $this->expectExceptionMessage('The mime type of image cats.jpeg was not guessed'); - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('find') ->with('cats.jpeg') ->willReturn(new Binary('content', null)); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -177,12 +180,12 @@ public function testThrowsIfLoaderReturnBinaryWithEmtptyMimeTypeOnFind(): void 'data_loader' => 'the_loader', ]); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->never()) ->method('guess'); - $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createMock(MimeTypesInterface::class), $config); $dataManager->addLoader('the_loader', $loader); $dataManager->find('thumbnail', 'cats.jpeg'); } @@ -194,14 +197,14 @@ public function testThrowsIfLoaderReturnBinaryWithMimeTypeNotImageOneOnFind(): v $binary = new Binary('content', 'text/plain'); - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('find') ->with('cats.jpeg') ->willReturn($binary); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -212,12 +215,12 @@ public function testThrowsIfLoaderReturnBinaryWithMimeTypeNotImageOneOnFind(): v 'data_loader' => 'the_loader', ]); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->never()) ->method('guess'); - $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createMock(MimeTypesInterface::class), $config); $dataManager->addLoader('the_loader', $loader); $dataManager->find('thumbnail', 'cats.jpeg'); } @@ -227,7 +230,7 @@ public function testThrowIfLoaderNotRegisteredForGivenFilterOnFind(): void $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Could not find data loader "" for "thumbnail" filter type'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -238,7 +241,7 @@ public function testThrowIfLoaderNotRegisteredForGivenFilterOnFind(): void 'data_loader' => null, ]); - $dataManager = new DataManager($this->createMimeTypeGuesserInterfaceMock(), $this->createExtensionGuesserInterfaceMock(), $config); + $dataManager = new DataManager($this->createMock(MimeTypeGuesserInterface::class), $this->createMock(MimeTypesInterface::class), $config); $dataManager->find('thumbnail', 'cats.jpeg'); } @@ -247,20 +250,20 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedMimeTypeOnFind( $expectedContent = 'theImageBinaryContent'; $expectedMimeType = 'image/png'; - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('find') ->willReturn($expectedContent); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->with($expectedContent) ->willReturn($expectedMimeType); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -271,7 +274,7 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedMimeTypeOnFind( 'data_loader' => null, ]); - $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config, 'default'); + $dataManager = new DataManager($mimeTypeGuesser, $this->createMock(MimeTypesInterface::class), $config, 'default'); $dataManager->addLoader('default', $loader); $binary = $dataManager->find('thumbnail', 'cats.jpeg'); @@ -287,20 +290,20 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedFormatOnFind(): $mimeType = 'image/png'; $expectedFormat = 'png'; - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('find') ->willReturn($content); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->with($content) ->willReturn($mimeType); - $extensionGuesser = $this->createExtensionGuesserInterfaceMock(); + $extensionGuesser = $this->createMock(MimeTypesInterface::class); if ($extensionGuesser instanceof MimeTypesInterface) { $extensionGuesser @@ -316,7 +319,7 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedFormatOnFind(): ->willReturn($expectedFormat); } - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -338,9 +341,9 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedFormatOnFind(): public function testUseDefaultGlobalImageUsedIfImageNotFound(): void { - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -349,13 +352,13 @@ public function testUseDefaultGlobalImageUsedIfImageNotFound(): void 'default_image' => null, ]); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->never()) ->method('guess'); $defaultGlobalImage = 'cats.jpeg'; - $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config, 'default', 'cats.jpeg'); + $dataManager = new DataManager($mimeTypeGuesser, $this->createMock(MimeTypesInterface::class), $config, 'default', 'cats.jpeg'); $dataManager->addLoader('default', $loader); $defaultImage = $dataManager->getDefaultImageUrl('thumbnail'); @@ -364,11 +367,11 @@ public function testUseDefaultGlobalImageUsedIfImageNotFound(): void public function testUseDefaultFilterImageUsedIfImageNotFound(): void { - $loader = $this->createBinaryLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $defaultFilterImage = 'cats.jpeg'; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->once()) ->method('get') @@ -377,12 +380,12 @@ public function testUseDefaultFilterImageUsedIfImageNotFound(): void 'default_image' => $defaultFilterImage, ]); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->never()) ->method('guess'); - $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config, 'default', null); + $dataManager = new DataManager($mimeTypeGuesser, $this->createMock(MimeTypesInterface::class), $config, 'default', null); $dataManager->addLoader('default', $loader); $defaultImage = $dataManager->getDefaultImageUrl('thumbnail'); diff --git a/tests/Imagine/Filter/FilterManagerTest.php b/tests/Imagine/Filter/FilterManagerTest.php index b6f2d1d40..9877cedfb 100644 --- a/tests/Imagine/Filter/FilterManagerTest.php +++ b/tests/Imagine/Filter/FilterManagerTest.php @@ -11,12 +11,16 @@ namespace Liip\ImagineBundle\Tests\Filter; +use Imagine\Image\ImageInterface; +use Imagine\Image\ImagineInterface; use Liip\ImagineBundle\Binary\BinaryInterface; +use Liip\ImagineBundle\Binary\MimeTypeGuesserInterface; +use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; use Liip\ImagineBundle\Imagine\Filter\FilterManager; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Tests\AbstractTest; -use PHPUnit\Framework\MockObject\MockObject; /** * @covers \Liip\ImagineBundle\Imagine\Filter\FilterManager @@ -28,7 +32,7 @@ public function testThrowsIfNoLoadersAddedForFilterOnApplyFilter(): void $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Could not find filter(s): "thumbnail"'); - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -47,8 +51,8 @@ public function testThrowsIfNoLoadersAddedForFilterOnApplyFilter(): void $filterManager = new FilterManager( $config, - $this->createImagineInterfaceMock(), - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(ImagineInterface::class), + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->applyFilter($binary, 'thumbnail'); @@ -66,7 +70,7 @@ public function testReturnFilteredBinaryWithExpectedContentOnApplyFilter(): void 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -78,20 +82,20 @@ public function testReturnFilteredBinaryWithExpectedContentOnApplyFilter(): void 'post_processors' => [], ]); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn($expectedFilteredContent); - $imagine = $this->createImagineInterfaceMock(); + $imagine = $this->createMock(ImagineInterface::class); $imagine ->expects($this->once()) ->method('load') ->with($originalContent) ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -101,7 +105,7 @@ public function testReturnFilteredBinaryWithExpectedContentOnApplyFilter(): void $filterManager = new FilterManager( $config, $imagine, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -123,7 +127,7 @@ public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApplyFilter( 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -135,19 +139,19 @@ public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApplyFilter( 'post_processors' => [], ]); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn('aFilteredContent'); - $imagine = $this->createImagineInterfaceMock(); + $imagine = $this->createMock(ImagineInterface::class); $imagine ->expects($this->once()) ->method('load') ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -157,7 +161,7 @@ public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApplyFilter( $filterManager = new FilterManager( $config, $imagine, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -180,7 +184,7 @@ public function testReturnFilteredBinaryWithCustomFormatIfSetOnApplyFilter(): vo 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -193,19 +197,19 @@ public function testReturnFilteredBinaryWithCustomFormatIfSetOnApplyFilter(): vo 'post_processors' => [], ]); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn('aFilteredContent'); - $imagine = $this->createImagineInterfaceMock(); + $imagine = $this->createMock(ImagineInterface::class); $imagine ->expects($this->once()) ->method('load') ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -215,7 +219,7 @@ public function testReturnFilteredBinaryWithCustomFormatIfSetOnApplyFilter(): vo $filterManager = new FilterManager( $config, $imagine, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -237,7 +241,7 @@ public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApplyFilte 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -249,24 +253,24 @@ public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApplyFilte 'post_processors' => [], ]); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn('aFilteredContent'); - $imagine = $this->createImagineInterfaceMock(); + $imagine = $this->createMock(ImagineInterface::class); $imagine ->expects($this->once()) ->method('load') ->willReturn($image); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->never()) ->method('guess'); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -300,7 +304,7 @@ public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApplyFi 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -313,26 +317,26 @@ public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApplyFi 'post_processors' => [], ]); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn($expectedContent); - $imagine = $this->createImagineInterfaceMock(); + $imagine = $this->createMock(ImagineInterface::class); $imagine ->expects($this->once()) ->method('load') ->willReturn($image); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->with($expectedContent) ->willReturn($expectedMimeType); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -364,7 +368,7 @@ public function testAltersQualityOnApplyFilter(): void 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -377,20 +381,20 @@ public function testAltersQualityOnApplyFilter(): void 'post_processors' => [], ]); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->with('png', ['quality' => $expectedQuality]) ->willReturn('aFilteredContent'); - $imagine = $this->createImagineInterfaceMock(); + $imagine = $this->createMock(ImagineInterface::class); $imagine ->expects($this->once()) ->method('load') ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -400,7 +404,7 @@ public function testAltersQualityOnApplyFilter(): void $filterManager = new FilterManager( $config, $imagine, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -419,7 +423,7 @@ public function testAlters100QualityIfNotSetOnApplyFilter(): void 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -431,20 +435,20 @@ public function testAlters100QualityIfNotSetOnApplyFilter(): void 'post_processors' => [], ]); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->with('png', ['quality' => $expectedQuality]) ->willReturn('aFilteredContent'); - $imagine = $this->createImagineInterfaceMock(); + $imagine = $this->createMock(ImagineInterface::class); $imagine ->expects($this->once()) ->method('load') ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -454,7 +458,7 @@ public function testAlters100QualityIfNotSetOnApplyFilter(): void $filterManager = new FilterManager( $config, $imagine, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -484,7 +488,7 @@ public function testMergeRuntimeConfigWithOneFromFilterConfigurationOnApplyFilte 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -496,19 +500,19 @@ public function testMergeRuntimeConfigWithOneFromFilterConfigurationOnApplyFilte 'post_processors' => [], ]); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn('aFilteredContent'); - $imagine = $this->createImagineInterfaceMock(); + $imagine = $this->createMock(ImagineInterface::class); $imagine ->expects($this->once()) ->method('load') ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -518,7 +522,7 @@ public function testMergeRuntimeConfigWithOneFromFilterConfigurationOnApplyFilte $filterManager = new FilterManager( $config, $imagine, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -536,9 +540,9 @@ public function testThrowsIfNoLoadersAddedForFilterOnApply(): void $binary = new Binary('aContent', 'image/png', 'png'); $filterManager = new FilterManager( - $this->createFilterConfigurationMock(), - $this->createImagineInterfaceMock(), - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(FilterConfiguration::class), + $this->createMock(ImagineInterface::class), + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->apply($binary, [ @@ -563,20 +567,20 @@ public function testReturnFilteredBinaryWithExpectedContentOnApply(): void 'mode' => 'outbound', ]; - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn($expectedFilteredContent); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->expects($this->once()) ->method('load') ->with($originalContent) ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -584,9 +588,9 @@ public function testReturnFilteredBinaryWithExpectedContentOnApply(): void ->willReturnArgument(0); $filterManager = new FilterManager( - $this->createFilterConfigurationMock(), + $this->createMock(FilterConfiguration::class), $imagineMock, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -613,19 +617,19 @@ public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApply(): voi 'mode' => 'outbound', ]; - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn('aFilteredContent'); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->expects($this->once()) ->method('load') ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -633,9 +637,9 @@ public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApply(): voi ->willReturnArgument(0); $filterManager = new FilterManager( - $this->createFilterConfigurationMock(), + $this->createMock(FilterConfiguration::class), $imagineMock, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -663,19 +667,19 @@ public function testReturnFilteredBinaryWithCustomFormatIfSetOnApply(): void 'mode' => 'outbound', ]; - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn('aFilteredContent'); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->expects($this->once()) ->method('load') ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -683,9 +687,9 @@ public function testReturnFilteredBinaryWithCustomFormatIfSetOnApply(): void ->willReturnArgument(0); $filterManager = new FilterManager( - $this->createFilterConfigurationMock(), + $this->createMock(FilterConfiguration::class), $imagineMock, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -713,24 +717,24 @@ public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApply(): v 'mode' => 'outbound', ]; - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn('aFilteredContent'); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->expects($this->once()) ->method('load') ->willReturn($image); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->never()) ->method('guess'); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -738,7 +742,7 @@ public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApply(): v ->willReturnArgument(0); $filterManager = new FilterManager( - $this->createFilterConfigurationMock(), + $this->createMock(FilterConfiguration::class), $imagineMock, $mimeTypeGuesser ); @@ -769,26 +773,26 @@ public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApply() 'mode' => 'outbound', ]; - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn($expectedContent); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->expects($this->once()) ->method('load') ->willReturn($image); - $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); + $mimeTypeGuesser = $this->createMock(MimeTypeGuesserInterface::class); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->with($expectedContent) ->willReturn($expectedMimeType); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -796,7 +800,7 @@ public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApply() ->willReturnArgument(0); $filterManager = new FilterManager( - $this->createFilterConfigurationMock(), + $this->createMock(FilterConfiguration::class), $imagineMock, $mimeTypeGuesser ); @@ -826,20 +830,20 @@ public function testAltersQualityOnApply(): void 'mode' => 'outbound', ]; - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->with('png', ['quality' => $expectedQuality]) ->willReturn('aFilteredContent'); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->expects($this->once()) ->method('load') ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -847,9 +851,9 @@ public function testAltersQualityOnApply(): void ->willReturnArgument(0); $filterManager = new FilterManager( - $this->createFilterConfigurationMock(), + $this->createMock(FilterConfiguration::class), $imagineMock, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -876,20 +880,20 @@ public function testAlters100QualityIfNotSetOnApply(): void 'mode' => 'outbound', ]; - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->with('png', ['quality' => $expectedQuality]) ->willReturn('aFilteredContent'); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->expects($this->once()) ->method('load') ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -897,9 +901,9 @@ public function testAlters100QualityIfNotSetOnApply(): void ->willReturnArgument(0); $filterManager = new FilterManager( - $this->createFilterConfigurationMock(), + $this->createMock(FilterConfiguration::class), $imagineMock, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -924,7 +928,7 @@ public function testApplyPostProcessor(): void 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -943,20 +947,20 @@ public function testApplyPostProcessor(): void 'mode' => 'outbound', ]; - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn($originalContent); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->expects($this->once()) ->method('load') ->with($originalContent) ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -965,7 +969,7 @@ public function testApplyPostProcessor(): void $processedBinary = new Binary($expectedPostProcessedContent, 'image/png', 'png'); - $postProcessor = $this->createPostProcessorInterfaceMock(); + $postProcessor = $this->createMock(PostProcessorInterface::class); $postProcessor ->expects($this->once()) ->method('process') @@ -975,7 +979,7 @@ public function testApplyPostProcessor(): void $filterManager = new FilterManager( $config, $imagineMock, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); $filterManager->addPostProcessor('foo', $postProcessor); @@ -998,7 +1002,7 @@ public function testThrowsIfNoPostProcessorAddedForFilterOnApplyFilter(): void 'mode' => 'outbound', ]; - $config = $this->createFilterConfigurationMock(); + $config = $this->createMock(FilterConfiguration::class); $config ->expects($this->atLeastOnce()) ->method('get') @@ -1017,20 +1021,20 @@ public function testThrowsIfNoPostProcessorAddedForFilterOnApplyFilter(): void 'mode' => 'outbound', ]; - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('get') ->willReturn($originalContent); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->expects($this->once()) ->method('load') ->with($originalContent) ->willReturn($image); - $loader = $this->createFilterLoaderInterfaceMock(); + $loader = $this->createMock(LoaderInterface::class); $loader ->expects($this->once()) ->method('load') @@ -1040,7 +1044,7 @@ public function testThrowsIfNoPostProcessorAddedForFilterOnApplyFilter(): void $filterManager = new FilterManager( $config, $imagineMock, - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(MimeTypeGuesserInterface::class) ); $filterManager->addLoader('thumbnail', $loader); @@ -1049,21 +1053,13 @@ public function testThrowsIfNoPostProcessorAddedForFilterOnApplyFilter(): void public function testApplyPostProcessorsWhenNotDefined(): void { - $binary = $this->getMockBuilder(BinaryInterface::class)->getMock(); + $binary = $this->createMock(BinaryInterface::class); $filterManager = new FilterManager( - $this->createFilterConfigurationMock(), - $this->createImagineInterfaceMock(), - $this->createMimeTypeGuesserInterfaceMock() + $this->createMock(FilterConfiguration::class), + $this->createMock(ImagineInterface::class), + $this->createMock(MimeTypeGuesserInterface::class) ); $this->assertSame($binary, $filterManager->applyPostProcessors($binary, [])); } - - /** - * @return MockObject&LoaderInterface - */ - protected function createFilterLoaderInterfaceMock() - { - return $this->createObjectMock(LoaderInterface::class); - } } diff --git a/tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php b/tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php index f1187cb0d..be720c3bc 100644 --- a/tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Tests\Filter; +use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\AutoRotateFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; @@ -23,7 +24,7 @@ public function testUseAutorotateFromImagine(): void { $loader = new AutoRotateFilterLoader(); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->expects($this->once()) ->method('metadata'); diff --git a/tests/Imagine/Filter/Loader/CropFilterLoaderTest.php b/tests/Imagine/Filter/Loader/CropFilterLoaderTest.php index 716181e76..fb706b394 100644 --- a/tests/Imagine/Filter/Loader/CropFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/CropFilterLoaderTest.php @@ -12,6 +12,7 @@ namespace Liip\ImagineBundle\Tests\Filter; use Imagine\Image\Box; +use Imagine\Image\ImageInterface; use Imagine\Image\Point; use Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; @@ -41,7 +42,7 @@ public function testLoad(array $coordinates, array $area): void $loader = new CropFilterLoader(); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->expects($this->once()) ->method('crop') ->with(new Point($x, $y), new Box($width, $height)) diff --git a/tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php b/tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php index 05e7d591d..9fb934be7 100644 --- a/tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php @@ -56,7 +56,7 @@ public function provideSizes() $initialSize = new Box(50, 200); $resultSize = new Box(50, 200); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->method('getSize') ->willReturn($initialSize); diff --git a/tests/Imagine/Filter/Loader/FixedFilterLoaderTest.php b/tests/Imagine/Filter/Loader/FixedFilterLoaderTest.php index 86ff5b3bf..f1043d19b 100644 --- a/tests/Imagine/Filter/Loader/FixedFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/FixedFilterLoaderTest.php @@ -12,6 +12,7 @@ namespace Liip\ImagineBundle\Tests\Filter; use Imagine\Image\Box; +use Imagine\Image\ImageInterface; use Imagine\Image\Point; use Liip\ImagineBundle\Imagine\Filter\Loader\FixedFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; @@ -55,7 +56,7 @@ public function testLoad(int $width, int $height, Box $expected): void floor(($resize->getHeight() - $expected->getHeight()) / 2) ); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->method('getSize')->willReturn($mockImageSize); $image->expects($this->once()) ->method('resize') diff --git a/tests/Imagine/Filter/Loader/FlipFilterLoaderTest.php b/tests/Imagine/Filter/Loader/FlipFilterLoaderTest.php index 93b7c6e7d..3beb1d455 100644 --- a/tests/Imagine/Filter/Loader/FlipFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/FlipFilterLoaderTest.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Tests\Filter; +use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\FlipFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; @@ -32,7 +33,7 @@ public static function provideLoadWithAxisXOptionData(): array */ public function testLoadWithAxisXOption(string $axis): void { - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->expects($this->once()) ->method('flipHorizontally') ->willReturn($image); @@ -53,7 +54,7 @@ public static function provideLoadWithAxisYOptionData(): array */ public function testLoadWithAxisYOption(string $axis): void { - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->expects($this->once()) ->method('flipVertically') ->willReturn($image); @@ -67,7 +68,7 @@ public function testThrowsOnInvalidOptions(): void $this->expectExceptionMessage('The "axis" option must be set to "x", "horizontal", "y", or "vertical".'); $loader = new FlipFilterLoader(); - $loader->load($this->getImageInterfaceMock(), [ + $loader->load($this->createMock(ImageInterface::class), [ 'axis' => 'invalid', ]); } diff --git a/tests/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php b/tests/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php index c734c1131..b6a2ce14a 100644 --- a/tests/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php @@ -24,7 +24,7 @@ public function testLoad(): void { $loader = new InterlaceFilterLoader(); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image ->expects($this->once()) ->method('interlace') diff --git a/tests/Imagine/Filter/Loader/PasteFilterLoaderTest.php b/tests/Imagine/Filter/Loader/PasteFilterLoaderTest.php index 88dde74a7..94ef977a4 100644 --- a/tests/Imagine/Filter/Loader/PasteFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/PasteFilterLoaderTest.php @@ -12,6 +12,8 @@ namespace Liip\ImagineBundle\Tests\Filter; use Imagine\Image\Box; +use Imagine\Image\ImageInterface; +use Imagine\Image\ImagineInterface; use Imagine\Image\Point; use Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; @@ -44,7 +46,7 @@ public function testLoad(int $x, int $y, Point $expected): void self::DUMMY_IMAGE_WIDTH, self::DUMMY_IMAGE_HEIGHT ); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->method('getSize')->willReturn($mockImageSize); $image->method('copy')->willReturn($image); $image->expects($this->once()) @@ -52,7 +54,7 @@ public function testLoad(int $x, int $y, Point $expected): void ->with($image, $expected) ->willReturn($image); - $imagineMock = $this->createImagineInterfaceMock(); + $imagineMock = $this->createMock(ImagineInterface::class); $imagineMock ->method('open') ->willReturn($image); diff --git a/tests/Imagine/Filter/Loader/ResampleFilterLoaderTest.php b/tests/Imagine/Filter/Loader/ResampleFilterLoaderTest.php index ed42bb0a2..7dfffe1b0 100644 --- a/tests/Imagine/Filter/Loader/ResampleFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/ResampleFilterLoaderTest.php @@ -12,6 +12,7 @@ namespace Liip\ImagineBundle\Tests\Filter; use Imagine\Gmagick\Imagine as GmagickImagine; +use Imagine\Image\ImageInterface; use Imagine\Image\ImagineInterface; use Imagine\Imagick\Imagine as ImagickImagine; use Liip\ImagineBundle\Imagine\Filter\Loader\ResampleFilterLoader; @@ -87,12 +88,12 @@ public static function provideOptionsData(): array */ public function testOptions(array $options): void { - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->expects($this->once()) ->method('save') ->willReturn($image); - $imagine = $this->createImagineInterfaceMock(); + $imagine = $this->createMock(ImagineInterface::class); $imagine->expects($this->once()) ->method('open') ->willReturn($image); @@ -131,7 +132,7 @@ public function testThrowsOnInvalidOptions(array $options): void $this->expectExceptionMessage('Invalid option(s) passed to Liip\\ImagineBundle\\Imagine\\Filter\\Loader\\ResampleFilterLoader::load().'); $loader = $this->createResampleFilterLoaderInstance(); - $loader->load($this->getImageInterfaceMock(), $options); + $loader->load($this->createMock(ImageInterface::class), $options); } public function testThrowsOnInvalidFilterOption(): void @@ -140,7 +141,7 @@ public function testThrowsOnInvalidFilterOption(): void $this->expectExceptionMessage('Invalid value for "filter" option: must be a valid constant resolvable using one of formats "\\Imagine\\Image\\ImageInterface::FILTER_%s", "\\Imagine\\Image\\ImageInterface::%s", or "%s".'); $loader = $this->createResampleFilterLoaderInstance(); - $loader->load($this->getImageInterfaceMock(), [ + $loader->load($this->createMock(ImageInterface::class), [ 'x' => 120, 'y' => 120, 'unit' => 'ppi', @@ -151,10 +152,10 @@ public function testThrowsOnInvalidFilterOption(): void public function testThrowsOnInvalidTemporaryPathOption(): void { $this->expectException(\RuntimeException::class); - $this->expectExceptionMessageMatchesBC('{Unable to create temporary file in ".+" base path.}'); + $this->expectExceptionMessageMatches('{Unable to create temporary file in ".+" base path.}'); $loader = $this->createResampleFilterLoaderInstance(); - $loader->load($this->getImageInterfaceMock(), [ + $loader->load($this->createMock(ImageInterface::class), [ 'x' => 120, 'y' => 120, 'unit' => 'ppi', @@ -166,7 +167,7 @@ public function testThrowsOnSaveOrOpenError(): void { $this->expectException(\Liip\ImagineBundle\Exception\Imagine\Filter\LoadFilterException::class); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->expects($this->once()) ->method('save') ->willThrowException(new \Exception('Error saving file!')); @@ -176,7 +177,7 @@ public function testThrowsOnSaveOrOpenError(): void private function createResampleFilterLoaderInstance(ImagineInterface $imagine = null): ResampleFilterLoader { - return new ResampleFilterLoader($imagine ?: $this->createImagineInterfaceMock()); + return new ResampleFilterLoader($imagine ?: $this->createMock(ImagineInterface::class)); } private static function getSupportedDriver(): string diff --git a/tests/Imagine/Filter/Loader/ResizeFilterLoaderTest.php b/tests/Imagine/Filter/Loader/ResizeFilterLoaderTest.php index 4a1496a4d..6eb15cb4e 100644 --- a/tests/Imagine/Filter/Loader/ResizeFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/ResizeFilterLoaderTest.php @@ -12,6 +12,7 @@ namespace Liip\ImagineBundle\Tests\Filter; use Imagine\Image\Box; +use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; @@ -31,7 +32,7 @@ public function testLoad(int $width, int $height): void { $loader = new ResizeFilterLoader(); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->expects($this->once()) ->method('resize') ->with(new Box($width, $height)) diff --git a/tests/Imagine/Filter/Loader/RotateFilterLoaderTest.php b/tests/Imagine/Filter/Loader/RotateFilterLoaderTest.php index 6917cadf2..e912bdbf9 100644 --- a/tests/Imagine/Filter/Loader/RotateFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/RotateFilterLoaderTest.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Tests\Filter; +use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\RotateFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; @@ -25,7 +26,7 @@ public function testLoadRotate0Degrees(): void { $loader = new RotateFilterLoader(); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $result = $loader->load($image, ['angle' => 0]); $this->assertSame($image, $result); @@ -35,8 +36,8 @@ public function testLoadRotate90Degrees(): void { $loader = new RotateFilterLoader(); - $image = $this->getImageInterfaceMock(); - $rotatedImage = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); + $rotatedImage = $this->createMock(ImageInterface::class); $image ->expects($this->once()) diff --git a/tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php b/tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php index 653cda29a..22d606ee0 100644 --- a/tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php @@ -12,9 +12,11 @@ namespace Liip\ImagineBundle\Tests\Filter; use Imagine\Image\Box; +use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader; use Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; +use PHPUnit\Framework\MockObject\MockObject; /** * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader @@ -49,7 +51,7 @@ class ScaleFilterLoaderTest extends AbstractTest public function testItShouldPreserveRatio(): void { $loader = new ScaleFilterLoader(); - $image = $this->getImageInterfaceMock(); + $image = $this->createImageInterfaceMock(); $image->expects($this->once()) ->method('resize') ->with(new Box( @@ -69,13 +71,12 @@ public function testItShouldPreserveRatio(): void * @dataProvider dimensionsDataProvider * * @param int[] $dimensions - * @param Box $expected */ - public function testItShouldUseDimensions($dimensions, $expected): void + public function testItShouldUseDimensions(array $dimensions, Box $expected): void { $loader = new ScaleFilterLoader(); - $image = $this->getImageInterfaceMock(); + $image = $this->createImageInterfaceMock(); $image->expects($this->once()) ->method('resize') ->with($expected) @@ -96,7 +97,7 @@ public function itShouldThrowInvalidArgumentException(): void $this->expectException(\InvalidArgumentException::class); $scale = new ScaleFilterLoader('foo', 'bar'); - $scale->load($this->getImageInterfaceMock(), []); + $scale->load($this->createImageInterfaceMock(), []); } public function dimensionsDataProvider(): array @@ -117,7 +118,7 @@ public function dimensionsDataProvider(): array public function testShouldScale($dimensions, $expected): void { $loader = new UpscaleFilterLoader(); - $image = $this->getUpscaleMockImage(); + $image = $this->createUpscaleMockImage(); $image->expects($this->once()) ->method('resize') ->with($expected) @@ -147,7 +148,7 @@ public function minScaleDataProvider(): array public function testShouldNotScale($dimensions, $expected): void { $loader = new UpscaleFilterLoader(); - $image = $this->getUpscaleMockImage(); + $image = $this->createUpscaleMockImage(); $image->expects($this->never()) ->method('resize') ->with($expected) @@ -168,9 +169,9 @@ public function minNotScaleDataProvider(): array ]; } - protected function getUpscaleMockImage() + private function createUpscaleMockImage(): ImageInterface&MockObject { - $mockImage = parent::getImageInterfaceMock(); + $mockImage = $this->createMock(ImageInterface::class); $mockImage->method('getSize')->willReturn(new Box( self::UPSCALE_DUMMY_IMAGE_WIDTH, self::UPSCALE_DUMMY_IMAGE_HEIGHT @@ -179,9 +180,9 @@ protected function getUpscaleMockImage() return $mockImage; } - protected function getImageInterfaceMock() + private function createImageInterfaceMock(): ImageInterface&MockObject { - $mockImage = parent::getImageInterfaceMock(); + $mockImage = $this->createMock(ImageInterface::class); $mockImage->method('getSize')->willReturn(new Box( self::DUMMY_IMAGE_WIDTH, self::DUMMY_IMAGE_HEIGHT diff --git a/tests/Imagine/Filter/Loader/ThumbnailFilterLoaderTest.php b/tests/Imagine/Filter/Loader/ThumbnailFilterLoaderTest.php index b86ba5233..cccd0f4f5 100644 --- a/tests/Imagine/Filter/Loader/ThumbnailFilterLoaderTest.php +++ b/tests/Imagine/Filter/Loader/ThumbnailFilterLoaderTest.php @@ -12,6 +12,7 @@ namespace Liip\ImagineBundle\Tests\Filter; use Imagine\Image\Box; +use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; @@ -45,7 +46,7 @@ public function testLoad(?int $width, ?int $height, Box $expected): void self::DUMMY_IMAGE_WIDTH, self::DUMMY_IMAGE_HEIGHT ); - $image = $this->getImageInterfaceMock(); + $image = $this->createMock(ImageInterface::class); $image->method('getSize')->willReturn($mockImageSize); $image->method('copy')->willReturn($image); $image->expects($this->once()) diff --git a/tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTest.php b/tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTest.php index 545c0a6c2..35bf6102c 100644 --- a/tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTest.php +++ b/tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTest.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Tests\Imagine\Filter\PostProcessor; +use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Imagine\Filter\PostProcessor\AbstractPostProcessor; use Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface; use Liip\ImagineBundle\Model\Binary; @@ -25,8 +26,7 @@ class AbstractPostProcessorTest extends AbstractPostProcessorTestCase { public function testIsBinaryOfType(): void { - $binary = $this->getBinaryInterfaceMock(); - + $binary = $this->createMock(BinaryInterface::class); $binary ->expects($this->atLeastOnce()) ->method('getMimeType') @@ -133,15 +133,10 @@ public static function provideIsValidReturnData(): array */ public function testIsValidReturn(array $validReturns, array $errorString, bool $expected): void { - $process = $this - ->getMockBuilder(Process::class) - ->disableOriginalConstructor() - ->getMock(); - + $process = $this->createMock(Process::class); $process ->method('getExitCode') ->willReturn(0); - $process ->method('getOutput') ->willReturn('foo bar baz'); diff --git a/tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTestCase.php b/tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTestCase.php index 414f600ab..16193eedb 100644 --- a/tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTestCase.php +++ b/tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTestCase.php @@ -11,7 +11,6 @@ namespace Liip\ImagineBundle\Tests\Imagine\Filter\PostProcessor; -use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Tests\AbstractTest; abstract class AbstractPostProcessorTestCase extends AbstractTest @@ -38,13 +37,6 @@ public static function getPostProcessAsStdInErrorExecutable(): string abstract protected function getPostProcessorInstance(array $parameters = []); - protected function getBinaryInterfaceMock(): BinaryInterface - { - return $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); - } - protected function assertTemporaryFile(string $content, string $file, string $context, array $options = []): void { $this->assertFileExists($file); diff --git a/tests/Imagine/Filter/PostProcessor/CwebpPostProcessorTest.php b/tests/Imagine/Filter/PostProcessor/CwebpPostProcessorTest.php index 9beddd8ec..0f0645772 100644 --- a/tests/Imagine/Filter/PostProcessor/CwebpPostProcessorTest.php +++ b/tests/Imagine/Filter/PostProcessor/CwebpPostProcessorTest.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Tests\Imagine\Filter\PostProcessor; +use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Imagine\Filter\PostProcessor\CwebpPostProcessor; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Model\FileBinary; @@ -149,8 +150,7 @@ public function testProcessError(string $content, array $options, string $expect public function testProcessWithNonSupportedMimeType(): void { - $binary = $this->getBinaryInterfaceMock(); - + $binary = $this->createMock(BinaryInterface::class); $binary ->expects($this->atLeastOnce()) ->method('getMimeType') diff --git a/tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php b/tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php index f1dabdd60..a6a279e3b 100644 --- a/tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php +++ b/tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Tests\Imagine\Filter\PostProcessor; +use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Exception\Imagine\Filter\PostProcessor\InvalidOptionException; use Liip\ImagineBundle\Imagine\Filter\PostProcessor\JpegOptimPostProcessor; use Liip\ImagineBundle\Model\Binary; @@ -64,8 +65,7 @@ public function testProcessArguments(array $parameters, array $options, array $e public function testProcessWithNonSupportedMimeType(): void { - $binary = $this->getBinaryInterfaceMock(); - + $binary = $this->createMock(BinaryInterface::class); $binary ->expects($this->atLeastOnce()) ->method('getMimeType') diff --git a/tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php b/tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php index d3703b0de..dee153707 100644 --- a/tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php +++ b/tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Tests\Imagine\Filter\PostProcessor; +use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Imagine\Filter\PostProcessor\MozJpegPostProcessor; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Model\FileBinary; @@ -97,8 +98,7 @@ public function testProcessError(string $content, array $options, string $expect public function testProcessWithNonSupportedMimeType(): void { - $binary = $this->getBinaryInterfaceMock(); - + $binary = $this->createMock(BinaryInterface::class); $binary ->expects($this->atLeastOnce()) ->method('getMimeType') diff --git a/tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php b/tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php index 81150457c..5b25bba83 100644 --- a/tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php +++ b/tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Tests\Imagine\Filter\PostProcessor; +use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Exception\Imagine\Filter\PostProcessor\InvalidOptionException; use Liip\ImagineBundle\Imagine\Filter\PostProcessor\OptiPngPostProcessor; use Liip\ImagineBundle\Model\Binary; @@ -132,8 +133,7 @@ public function testProcessError(string $content, array $options, string $expect public function testProcessWithNonSupportedMimeType(): void { - $binary = $this->getBinaryInterfaceMock(); - + $binary = $this->createMock(BinaryInterface::class); $binary ->expects($this->atLeastOnce()) ->method('getMimeType') diff --git a/tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php b/tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php index 1262f6e76..58fe98d2d 100644 --- a/tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php +++ b/tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Tests\Imagine\Filter\PostProcessor; +use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Exception\Imagine\Filter\PostProcessor\InvalidOptionException; use Liip\ImagineBundle\Imagine\Filter\PostProcessor\PngquantPostProcessor; use Liip\ImagineBundle\Model\Binary; @@ -147,8 +148,7 @@ public function testProcessError(string $content, array $options, string $expect public function testProcessWithNonSupportedMimeType(): void { - $binary = $this->getBinaryInterfaceMock(); - + $binary = $this->createMock(BinaryInterface::class); $binary ->expects($this->atLeastOnce()) ->method('getMimeType') diff --git a/tests/LiipImagineBundleTest.php b/tests/LiipImagineBundleTest.php index 1676e47bb..70c0ba90d 100644 --- a/tests/LiipImagineBundleTest.php +++ b/tests/LiipImagineBundleTest.php @@ -47,7 +47,7 @@ public function testSubClassOfBundle(): void public function testAddPasses(): void { $passes = []; - $containerMock = $this->createContainerBuilderMock(); + $containerMock = $this->createMock(ContainerBuilder::class); $containerMock ->expects($this->atLeastOnce()) ->method('getExtension') @@ -91,7 +91,7 @@ public function testAddResolvers(): void return true; })); - $containerMock = $this->createContainerBuilderMock(); + $containerMock = $this->createMock(ContainerBuilder::class); $containerMock ->expects($this->atLeastOnce()) ->method('getExtension') @@ -119,7 +119,7 @@ public function testAddLoaders(): void return true; })); - $containerMock = $this->createContainerBuilderMock(); + $containerMock = $this->createMock(ContainerBuilder::class); $containerMock ->expects($this->atLeastOnce()) ->method('getExtension') @@ -136,23 +136,20 @@ public function testAddLoaders(): void ], $loaders); } - /** - * @return MockObject&ContainerBuilder - */ - protected function createContainerBuilderMock() - { - return $this->createObjectMock(ContainerBuilder::class, [], false); - } - /** * @return MockObject&LiipImagineExtension */ protected function createLiipImagineExtensionMock() { - return $this->createObjectMock(LiipImagineExtension::class, [ + $builder = $this->getMockBuilder(LiipImagineExtension::class); + $builder->setMethods([ 'getNamespace', 'addResolverFactory', 'addLoaderFactory', - ], false); + ]); + + $builder->disableOriginalConstructor(); + + return $builder->getMock(); } } diff --git a/tests/Message/Handler/WarmupCacheHandlerTest.php b/tests/Message/Handler/WarmupCacheHandlerTest.php index 29779a2b7..c45756cf9 100644 --- a/tests/Message/Handler/WarmupCacheHandlerTest.php +++ b/tests/Message/Handler/WarmupCacheHandlerTest.php @@ -19,20 +19,12 @@ use Liip\ImagineBundle\Message\WarmupCache; use Liip\ImagineBundle\Service\FilterService; use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; -use Symfony\Component\Messenger\MessageBusInterface; /** * @covers \Liip\ImagineBundle\Message\Handler\WarmupCacheHandler */ class WarmupCacheHandlerTest extends AbstractWebTestCase { - protected function setUp(): void - { - if (!interface_exists(MessageBusInterface::class)) { - $this->markTestSkipped('Requires the symfony/messenger package.'); - } - } - public function testCouldBeConstructedWithExpectedArguments(): void { static::createClient(); diff --git a/tests/Message/WarmupCacheTest.php b/tests/Message/WarmupCacheTest.php index 93c9e3151..a4de129f0 100644 --- a/tests/Message/WarmupCacheTest.php +++ b/tests/Message/WarmupCacheTest.php @@ -15,20 +15,12 @@ use Liip\ImagineBundle\Message\WarmupCache; use PHPUnit\Framework\TestCase; -use Symfony\Component\Messenger\MessageBusInterface; /** * @covers \Liip\ImagineBundle\Message\WarmupCache */ class WarmupCacheTest extends TestCase { - protected function setUp(): void - { - if (!interface_exists(MessageBusInterface::class)) { - $this->markTestSkipped('Requires the symfony/messenger package.'); - } - } - public function testMessageWithoutFiltersAndForce(): void { $message = new WarmupCache('thePath'); diff --git a/tests/Service/FilterServiceTest.php b/tests/Service/FilterServiceTest.php index d334dd780..72795955d 100644 --- a/tests/Service/FilterServiceTest.php +++ b/tests/Service/FilterServiceTest.php @@ -65,21 +65,10 @@ protected function setUp(): void { parent::setUp(); - $this->dataManager = $this - ->getMockBuilder(DataManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->filterManager = $this - ->getMockBuilder(FilterManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->cacheManager = $this - ->getMockBuilder(CacheManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->logger = $this - ->getMockBuilder(LoggerInterface::class) - ->getMock(); + $this->dataManager = $this->createMock(DataManager::class); + $this->filterManager = $this->createMock(FilterManager::class); + $this->cacheManager = $this->createMock(CacheManager::class); + $this->logger = $this->createMock(LoggerInterface::class); } public function provideWebpGeneration(): \Traversable @@ -162,9 +151,7 @@ public function testWarmsUpCache(bool $webpGenerate): void public function testWarmsUpCacheForced(bool $webpGenerate): void { $resolver = null; - $binary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); + $binary = $this->createMock(BinaryInterface::class); $service = $this->createFilterService($webpGenerate); @@ -184,9 +171,7 @@ public function testWarmsUpCacheForced(bool $webpGenerate): void public function testWarmsUpCacheNotStored(bool $webpGenerate): void { $resolver = null; - $binary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); + $binary = $this->createMock(BinaryInterface::class); $service = $this->createFilterService($webpGenerate); @@ -204,12 +189,7 @@ public function testWarmsUpCacheNotStored(bool $webpGenerate): void public function testWarmsUpCacheNotStoredForced(bool $webpGenerate): void { $resolver = null; - $binary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); - $filteredBinary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); + $binary = $this->createMock(BinaryInterface::class); $service = $this->createFilterService($webpGenerate); @@ -231,9 +211,7 @@ public function testWarmsUpCacheNonExistingFilter(bool $webpGenerate): void $this->expectException(NonExistingFilterException::class); $resolver = null; - $binary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); + $binary = $this->createMock(BinaryInterface::class); $exception = new NonExistingFilterException('Filter not found'); $service = $this->createFilterService($webpGenerate); @@ -300,9 +278,7 @@ public function testGetUrlOfFilteredImageNotStored(bool $webpGenerate): void { $resolver = null; $url = 'https://example.com/cache'.self::SOURCE_IMAGE; - $binary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); + $binary = $this->createMock(BinaryInterface::class); $service = $this->createFilterService($webpGenerate); @@ -328,9 +304,7 @@ public function testGetUrlOfFilteredImageNotExistingFilter(bool $webpGenerate): $this->expectException(NonExistingFilterException::class); $resolver = null; - $binary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); + $binary = $this->createMock(BinaryInterface::class); $exception = new NonExistingFilterException('Filter not found'); $service = $this->createFilterService($webpGenerate); @@ -418,9 +392,7 @@ public function testGetUrlOfFilteredImageWithRuntimeFiltersNotStored(bool $webpG $runtimeOptions = [ 'filters' => self::RUNTIME_FILTERS, ]; - $binary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); + $binary = $this->createMock(BinaryInterface::class); $service = $this->createFilterService($webpGenerate); @@ -459,9 +431,7 @@ public function testGetUrlOfFilteredImageWithRuntimeFiltersNotExistingFilter(boo $runtimeOptions = [ 'filters' => self::RUNTIME_FILTERS, ]; - $binary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); + $binary = $this->createMock(BinaryInterface::class); $exception = new NonExistingFilterException('Filter not found'); $service = $this->createFilterService($webpGenerate); @@ -541,9 +511,7 @@ private function expectCacheManagerIsStored(string $image, bool $webpGenerate, b private function expectCacheManagerStore(string $image, bool $webpGenerate, $resolver): void { - $filteredBinary = $this - ->getMockBuilder(BinaryInterface::class) - ->getMock(); + $filteredBinary = $this->createMock(BinaryInterface::class); if ($webpGenerate) { $this->cacheManager diff --git a/tests/Templating/LazyFilterRuntimeTest.php b/tests/Templating/LazyFilterRuntimeTest.php index 138ebeb5b..4f3a7747a 100644 --- a/tests/Templating/LazyFilterRuntimeTest.php +++ b/tests/Templating/LazyFilterRuntimeTest.php @@ -12,9 +12,13 @@ namespace Liip\ImagineBundle\Tests\Templating; use Liip\ImagineBundle\Imagine\Cache\CacheManager; +use Liip\ImagineBundle\Imagine\Cache\SignerInterface; +use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; use Liip\ImagineBundle\Templating\LazyFilterRuntime; use Liip\ImagineBundle\Tests\AbstractTest; use PHPUnit\Framework\MockObject\MockObject; +use Symfony\Component\Routing\RouterInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * @covers \Liip\ImagineBundle\Templating\LazyFilterRuntime @@ -139,4 +143,31 @@ public function testInvokeFilterCacheMethodWithRuntimeConfig(): void $this->assertSame($expectedCachePath, $actualPath); } + + /** + * @return MockObject&CacheManager + */ + private function createCacheManagerMock() + { + return $this + ->getMockBuilder(CacheManager::class) + ->setConstructorArgs([ + $this->createFilterConfiguration(), + $this->createMock(RouterInterface::class), + $this->createMock(SignerInterface::class), + $this->createMock(EventDispatcherInterface::class), + ]) + ->getMock(); + } + + private function createFilterConfiguration(): FilterConfiguration + { + $config = new FilterConfiguration(); + $config->set('thumbnail', [ + 'size' => [180, 180], + 'mode' => 'outbound', + ]); + + return $config; + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 20bd5f6c7..14961b3ee 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -21,13 +21,3 @@ exit(1); } } - -namespace Symfony\Component\ExpressionLanguage { - if (interface_exists(ExpressionFunctionProviderInterface::class)) { - return; - } - - interface ExpressionFunctionProviderInterface - { - } -}