From 95f959cf39e7f2cb9c2d09dfb7ba2a4470dea8c7 Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Sat, 11 Feb 2017 23:25:10 -0500 Subject: [PATCH] support phpunit 5.x without deprecations and general test cleanup --- Binary/Locator/FileSystemLocator.php | 2 +- .../Compiler/LocatorsCompilerPass.php | 2 +- .../Loader/FileSystemLoaderFactory.php | 1 - .../Factory/Resolver/AwsS3ResolverFactory.php | 6 +- Tests/AbstractTest.php | 196 ++++++-- .../Loader/AbstractDoctrineLoaderTest.php | 87 +++- Tests/Binary/Loader/FileSystemLoaderTest.php | 10 +- Tests/Binary/Loader/FlysystemLoaderTest.php | 51 +-- Tests/Binary/Loader/GridFSLoaderTest.php | 52 ++- Tests/Binary/Loader/StreamLoaderTest.php | 40 +- Tests/Binary/SimpleMimeTypeGuesserTest.php | 48 +- Tests/Controller/ImagineControllerTest.php | 54 +-- .../MetadataReaderCompilerPassTest.php | 4 +- .../DependencyInjection/ConfigurationTest.php | 16 +- .../Loader/FileSystemLoaderFactoryTest.php | 4 +- .../Loader/FlysystemLoaderFactoryTest.php | 11 +- .../Loader/StreamLoaderFactoryTest.php | 6 +- .../Resolver/AwsS3ResolverFactoryTest.php | 45 +- .../Resolver/FlysystemResolverFactoryTest.php | 12 +- .../Resolver/WebPathResolverFactoryTest.php | 8 +- .../LiipImagineExtensionTest.php | 42 +- Tests/Events/CacheResolveEventTest.php | 2 +- .../Resolver/NotResolvableExceptionTest.php | 4 +- .../Resolver/NotStorableExceptionTest.php | 4 +- Tests/Form/Type/ImageTypeTest.php | 10 +- Tests/Functional/AbstractSetupWebTestCase.php | 49 ++ ...ebTestCase.php => AbstractWebTestCase.php} | 5 +- .../{ => Binary}/ExtensionGuesserTest.php | 12 +- .../Binary/Loader/FileSystemLoaderTest.php | 4 +- .../Binary/Locator/FileSystemLocatorTest.php | 4 +- .../{ => Binary}/MimeTypeGuesserTest.php | 12 +- .../Binary/SimpleMimeTypeGuesserTest.php | 11 +- .../Command/AbstractCommandTestCase.php | 44 ++ Tests/Functional/Command/RemoveCacheTest.php | 56 +-- Tests/Functional/Command/ResolveCacheTest.php | 56 +-- .../Controller/ImagineControllerTest.php | 52 +-- .../Resolver/NoCacheWebPathResolverTest.php | 13 +- .../{ => Imagine/Cache}/SignerTest.php | 12 +- .../Imagine/Data/DataManagerTest.php | 13 +- .../Imagine/Filter/FilterManagerTest.php | 13 +- .../Loader/DownscaleFilterLoaderTest.php | 13 +- .../Loader/GrayscaleFilterLoaderTest.php | 12 +- .../Loader/InterlaceFilterLoaderTest.php | 13 +- .../Filter/Loader/RotateFilterLoaderTest.php | 12 +- Tests/Functional/app/config/config.yml | 52 ++- Tests/Functional/app/config/routing.yml | 4 + Tests/Imagine/Cache/CacheManagerTest.php | 318 ++++++------- .../Cache/Resolver/AmazonS3ResolverTest.php | 157 +++---- .../Cache/Resolver/AwsS3ResolverTest.php | 166 +++---- .../Cache/Resolver/CacheResolverTest.php | 59 +-- .../Cache/Resolver/FlysystemResolverTest.php | 128 +++--- .../Resolver/NoCacheWebPathResolverTest.php | 15 +- .../Cache/Resolver/ProxyResolverTest.php | 31 +- .../Cache/Resolver/WebPathResolverTest.php | 53 +-- Tests/Imagine/Cache/SignerTest.php | 7 +- Tests/Imagine/Data/DataManagerTest.php | 209 ++++----- .../Filter/FilterConfigurationTest.php | 8 +- Tests/Imagine/Filter/FilterManagerTest.php | 423 ++++++++---------- .../Loader/AutoRotateFilterLoaderTest.php | 11 +- .../Filter/Loader/CropFilterLoaderTest.php | 8 +- .../Loader/DownscaleFilterLoaderTest.php | 12 +- ...ntCastByRoundDownscaleFilterLoaderTest.php | 2 +- ...oIntCastByRoundUpscaleFilterLoaderTest.php | 2 +- .../Loader/GrayscaleFilterLoaderTest.php | 4 +- .../Loader/InterlaceFilterLoaderTest.php | 6 +- .../Filter/Loader/PasteFilterLoaderTest.php | 10 +- .../Loader/RelativeResizeLoaderTest.php | 0 .../Filter/Loader/ResizeFilterLoaderTest.php | 8 +- .../Filter/Loader/RotateFilterLoaderTest.php | 10 +- .../Filter/Loader/ScaleFilterLoaderTest.php | 22 +- .../Loader/ThumbnailFilterLoaderTest.php | 8 +- Tests/LiipImagineBundleTest.php | 42 +- Tests/Model/BinaryTest.php | 6 +- Tests/Templating/Helper/ImagineHelperTest.php | 21 +- Tests/Templating/ImagineExtensionTest.php | 20 +- composer.json | 12 +- 76 files changed, 1405 insertions(+), 1552 deletions(-) create mode 100644 Tests/Functional/AbstractSetupWebTestCase.php rename Tests/Functional/{WebTestCase.php => AbstractWebTestCase.php} (88%) rename Tests/Functional/{ => Binary}/ExtensionGuesserTest.php (50%) rename Tests/Functional/{ => Binary}/MimeTypeGuesserTest.php (51%) create mode 100644 Tests/Functional/Command/AbstractCommandTestCase.php rename Tests/Functional/{ => Imagine/Cache}/SignerTest.php (51%) delete mode 100644 Tests/Imagine/Filter/Loader/RelativeResizeLoaderTest.php diff --git a/Binary/Locator/FileSystemLocator.php b/Binary/Locator/FileSystemLocator.php index 384f5aacb..ad1a802a9 100644 --- a/Binary/Locator/FileSystemLocator.php +++ b/Binary/Locator/FileSystemLocator.php @@ -21,7 +21,7 @@ class FileSystemLocator implements LocatorInterface /** * @var string[] */ - private $roots; + private $roots = array(); /** * @param array[] $options diff --git a/DependencyInjection/Compiler/LocatorsCompilerPass.php b/DependencyInjection/Compiler/LocatorsCompilerPass.php index 29b95ca56..a8bcd7bb4 100644 --- a/DependencyInjection/Compiler/LocatorsCompilerPass.php +++ b/DependencyInjection/Compiler/LocatorsCompilerPass.php @@ -22,7 +22,7 @@ public function process(ContainerBuilder $container) { foreach ($container->findTaggedServiceIds('liip_imagine.binary.locator') as $id => $tags) { if (isset($tags[0]['shared'])) { - $this->setDefinitionSharing($container->getDefinition($id), $tags[0]['shared']); + $this->setDefinitionSharing($container->getDefinition($id), (bool) $tags[0]['shared']); } } } diff --git a/DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php b/DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php index e9e3c88cf..1a3554277 100644 --- a/DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php +++ b/DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php @@ -86,7 +86,6 @@ public function addConfiguration(ArrayNodeDefinition $builder) ->end(); } - /* * @param string[] $staticPaths * @param array $config diff --git a/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php b/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php index 36926fbcc..bc0e7a3f1 100644 --- a/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php +++ b/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php @@ -25,12 +25,12 @@ class AwsS3ResolverFactory implements ResolverFactoryInterface public function create(ContainerBuilder $container, $resolverName, array $config) { $awsS3ClientId = 'liip_imagine.cache.resolver.'.$resolverName.'.client'; - $awsS3ClientDefinition = new Definition('Aws\S3\S3Client'); + $awsS3ClientDefinition = new Definition('\Aws\S3\S3Client'); if (method_exists($awsS3ClientDefinition, 'setFactory')) { - $awsS3ClientDefinition->setFactory(array('Aws\S3\S3Client', 'factory')); + $awsS3ClientDefinition->setFactory(array('\Aws\S3\S3Client', 'factory')); } else { // to be removed when dependency on Symfony DependencyInjection is bumped to 2.6 - $awsS3ClientDefinition->setFactoryClass('Aws\S3\S3Client'); + $awsS3ClientDefinition->setFactoryClass('\Aws\S3\S3Client'); $awsS3ClientDefinition->setFactoryMethod('factory'); } $awsS3ClientDefinition->addArgument($config['client_config']); diff --git a/Tests/AbstractTest.php b/Tests/AbstractTest.php index 5f877df8b..1e3c71aa0 100644 --- a/Tests/AbstractTest.php +++ b/Tests/AbstractTest.php @@ -11,9 +11,22 @@ 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\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 Psr\Log\LoggerInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface; use Symfony\Component\Routing\RouterInterface; abstract class AbstractTest extends \PHPUnit_Framework_TestCase @@ -23,33 +36,44 @@ abstract class AbstractTest extends \PHPUnit_Framework_TestCase */ protected $filesystem; - protected $fixturesDir; - protected $tempDir; + /** + * @var string + */ + protected $fixturesPath; + + /** + * @var string + */ + protected $temporaryPath; protected function setUp() { - $this->fixturesDir = __DIR__.'/Fixtures'; - - $this->tempDir = str_replace('/', DIRECTORY_SEPARATOR, sys_get_temp_dir().'/liip_imagine_test'); - + $this->fixturesPath = realpath(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'); + $this->temporaryPath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'liip_imagine_test'; $this->filesystem = new Filesystem(); - if ($this->filesystem->exists($this->tempDir)) { - $this->filesystem->remove($this->tempDir); + if ($this->filesystem->exists($this->temporaryPath)) { + $this->filesystem->remove($this->temporaryPath); } - $this->filesystem->mkdir($this->tempDir); + $this->filesystem->mkdir($this->temporaryPath); } + /** + * @return string[] + */ public function invalidPathProvider() { return array( - array($this->fixturesDir.'/assets/../../foobar.png'), - array($this->fixturesDir.'/assets/some_folder/../foobar.png'), + array($this->fixturesPath.'/assets/../../foobar.png'), + array($this->fixturesPath.'/assets/some_folder/../foobar.png'), array('../../outside/foobar.jpg'), ); } + /** + * @return FilterConfiguration + */ protected function createFilterConfiguration() { $config = new FilterConfiguration(); @@ -61,9 +85,20 @@ protected function createFilterConfiguration() return $config; } - protected function getMockCacheManager() + /** + * @return \PHPUnit_Framework_MockObject_MockObject|CacheManager + */ + protected function createCacheManagerMock() { - return $this->getMockBuilder('Liip\ImagineBundle\Imagine\Cache\CacheManager')->getMock(); + return $this + ->getMockBuilder('\Liip\ImagineBundle\Imagine\Cache\CacheManager') + ->setConstructorArgs(array( + $this->createFilterConfiguration(), + $this->createRouterInterfaceMock(), + $this->createSignerInterfaceMock(), + $this->createEventDispatcherInterfaceMock(), + )) + ->getMock(); } /** @@ -71,43 +106,148 @@ protected function getMockCacheManager() */ protected function createFilterConfigurationMock() { - return $this->getMockBuilder('Liip\ImagineBundle\Imagine\Filter\FilterConfiguration')->getMock(); + return $this->createObjectMock('\Liip\ImagineBundle\Imagine\Filter\FilterConfiguration'); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|SignerInterface + */ + protected function createSignerInterfaceMock() + { + return $this->createObjectMock('\Liip\ImagineBundle\Imagine\Cache\SignerInterface'); } /** * @return \PHPUnit_Framework_MockObject_MockObject|RouterInterface */ - protected function createRouterMock() + protected function createRouterInterfaceMock() { - return $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->getMock(); + return $this->createObjectMock('\Symfony\Component\Routing\RouterInterface'); } /** * @return \PHPUnit_Framework_MockObject_MockObject|ResolverInterface */ - protected function createResolverMock() + protected function createCacheResolverInterfaceMock() { - return $this->getMockBuilder('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')->getMock(); + return $this->createObjectMock('\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface'); } - protected function createEventDispatcherMock() + /** + * @return \PHPUnit_Framework_MockObject_MockObject|EventDispatcherInterface + */ + protected function createEventDispatcherInterfaceMock() + { + return $this->createObjectMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface'); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|ImageInterface + */ + protected function getImageInterfaceMock() + { + return $this->createObjectMock('\Imagine\Image\ImageInterface'); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|MetadataBag + */ + protected function getMetadataBagMock() { - return $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); + return $this->createObjectMock('\Imagine\Image\Metadata\MetadataBag'); } - protected function getMockImage() + /** + * @return \PHPUnit_Framework_MockObject_MockObject|ImagineInterface + */ + protected function createImagineInterfaceMock() { - return $this->getMockBuilder('Imagine\Image\ImageInterface')->getMock(); + return $this->createObjectMock('\Imagine\Image\ImagineInterface'); } - protected function getMockMetaData() + /** + * @return \PHPUnit_Framework_MockObject_MockObject|LoggerInterface + */ + protected function createLoggerInterfaceMock() { - return $this->getMockBuilder('Imagine\Image\Metadata\MetadataBag')->getMock(); + return $this->createObjectMock('\Psr\Log\LoggerInterface'); } - protected function createImagineMock() + /** + * @return \PHPUnit_Framework_MockObject_MockObject|LoaderInterface + */ + protected function createBinaryLoaderInterfaceMock() { - return $this->getMockBuilder('Imagine\Image\ImagineInterface')->getMock(); + return $this->createObjectMock('\Liip\ImagineBundle\Binary\Loader\LoaderInterface'); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|MimeTypeGuesserInterface + */ + protected function createMimeTypeGuesserInterfaceMock() + { + return $this->createObjectMock('\Liip\ImagineBundle\Binary\MimeTypeGuesserInterface'); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|ExtensionGuesserInterface + */ + protected function createExtensionGuesserInterfaceMock() + { + return $this->createObjectMock('\Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface'); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|PostProcessorInterface + */ + protected function createPostProcessorInterfaceMock() + { + return $this->createObjectMock('\Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface'); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|FilterManager + */ + protected function createFilterManagerMock() + { + return $this->createObjectMock('\Liip\ImagineBundle\Imagine\Filter\FilterManager', array(), false); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|DataManager + */ + protected function createDataManagerMock() + { + return $this->createObjectMock('\Liip\ImagineBundle\Imagine\Data\DataManager', array(), false); + } + + /** + * @param string $object + * @param string[] $methods + * @param bool $constructorInvoke + * @param mixed[] $constructorParams + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function createObjectMock($object, array $methods = array(), $constructorInvoke = false, array $constructorParams = array()) + { + $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(); } /** @@ -132,8 +272,8 @@ protected function tearDown() return; } - if ($this->filesystem->exists($this->tempDir)) { - $this->filesystem->remove($this->tempDir); + if ($this->filesystem->exists($this->temporaryPath)) { + $this->filesystem->remove($this->temporaryPath); } } } diff --git a/Tests/Binary/Loader/AbstractDoctrineLoaderTest.php b/Tests/Binary/Loader/AbstractDoctrineLoaderTest.php index 2670c871d..c8a85f7b6 100644 --- a/Tests/Binary/Loader/AbstractDoctrineLoaderTest.php +++ b/Tests/Binary/Loader/AbstractDoctrineLoaderTest.php @@ -15,35 +15,53 @@ use Liip\ImagineBundle\Binary\Loader\AbstractDoctrineLoader; /** - * @covers Liip\ImagineBundle\Binary\Loader\AbstractDoctrineLoader + * @covers \Liip\ImagineBundle\Binary\Loader\AbstractDoctrineLoader */ class AbstractDoctrineLoaderTest extends \PHPUnit_Framework_TestCase { /** - * @var ObjectRepository + * @var \PHPUnit_Framework_MockObject_MockObject|ObjectRepository */ private $om; /** - * @var AbstractDoctrineLoader + * @var \PHPUnit_Framework_MockObject_MockObject|AbstractDoctrineLoader */ private $loader; public function setUp() { - $this->om = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); - - $this->loader = $this->getMockBuilder('Liip\ImagineBundle\Binary\Loader\AbstractDoctrineLoader')->setConstructorArgs(array($this->om))->getMockForAbstractClass(); + $this->om = $this + ->getMockBuilder('\Doctrine\Common\Persistence\ObjectManager') + ->getMock(); + + $this->loader = $this + ->getMockBuilder('\Liip\ImagineBundle\Binary\Loader\AbstractDoctrineLoader') + ->setConstructorArgs(array($this->om)) + ->getMockForAbstractClass(); } public function testFindWithValidObjectFirstHit() { $image = new \stdClass(); - $this->loader->expects($this->atLeastOnce())->method('mapPathToId')->with('/foo/bar')->will($this->returnValue(1337)); - $this->loader->expects($this->atLeastOnce())->method('getStreamFromImage')->with($image)->will($this->returnValue(fopen('data://text/plain,foo', 'r'))); + $this->loader + ->expects($this->atLeastOnce()) + ->method('mapPathToId') + ->with('/foo/bar') + ->will($this->returnValue(1337)); + + $this->loader + ->expects($this->atLeastOnce()) + ->method('getStreamFromImage') + ->with($image) + ->will($this->returnValue(fopen('data://text/plain,foo', 'r'))); - $this->om->expects($this->atLeastOnce())->method('find')->with(null, 1337)->will($this->returnValue($image)); + $this->om + ->expects($this->atLeastOnce()) + ->method('find') + ->with(null, 1337) + ->will($this->returnValue($image)); $this->assertEquals('foo', $this->loader->find('/foo/bar')); } @@ -52,17 +70,27 @@ public function testFindWithValidObjectSecondHit() { $image = new \stdClass(); - $this->loader->expects($this->atLeastOnce())->method('mapPathToId')->will($this->returnValueMap(array( - array('/foo/bar.png', 1337), - array('/foo/bar', 4711), - ))); - - $this->loader->expects($this->atLeastOnce())->method('getStreamFromImage')->with($image)->will($this->returnValue(fopen('data://text/plain,foo', 'r'))); - - $this->om->expects($this->atLeastOnce())->method('find')->will($this->returnValueMap(array( - array(null, 1337, null), - array(null, 4711, $image), - ))); + $this->loader + ->expects($this->atLeastOnce()) + ->method('mapPathToId') + ->will($this->returnValueMap(array( + array('/foo/bar.png', 1337), + array('/foo/bar', 4711), + ))); + + $this->loader + ->expects($this->atLeastOnce()) + ->method('getStreamFromImage') + ->with($image) + ->will($this->returnValue(fopen('data://text/plain,foo', 'r'))); + + $this->om + ->expects($this->atLeastOnce()) + ->method('find') + ->will($this->returnValueMap(array( + array(null, 1337, null), + array(null, 4711, $image), + ))); $this->assertEquals('foo', $this->loader->find('/foo/bar.png')); } @@ -72,10 +100,21 @@ public function testFindWithValidObjectSecondHit() */ public function testFindWithInvalidObject() { - $this->loader->expects($this->atLeastOnce())->method('mapPathToId')->with('/foo/bar')->will($this->returnValue(1337)); - $this->loader->expects($this->never())->method('getStreamFromImage'); - - $this->om->expects($this->atLeastOnce())->method('find')->with(null, 1337)->will($this->returnValue(null)); + $this->loader + ->expects($this->atLeastOnce()) + ->method('mapPathToId') + ->with('/foo/bar') + ->will($this->returnValue(1337)); + + $this->loader + ->expects($this->never()) + ->method('getStreamFromImage'); + + $this->om + ->expects($this->atLeastOnce()) + ->method('find') + ->with(null, 1337) + ->will($this->returnValue(null)); $this->loader->find('/foo/bar'); } diff --git a/Tests/Binary/Loader/FileSystemLoaderTest.php b/Tests/Binary/Loader/FileSystemLoaderTest.php index 5871f5144..6d5663372 100644 --- a/Tests/Binary/Loader/FileSystemLoaderTest.php +++ b/Tests/Binary/Loader/FileSystemLoaderTest.php @@ -23,16 +23,14 @@ */ class FileSystemLoaderTest extends \PHPUnit_Framework_TestCase { - public function testImplementsLoaderInterface() + public function testConstruction() { - $r = new \ReflectionClass('Liip\ImagineBundle\Binary\Loader\FileSystemLoader'); - - $this->assertTrue($r->implementsInterface('Liip\ImagineBundle\Binary\Loader\LoaderInterface')); + $this->getFileSystemLoader(); } - public function testConstruction() + public function testImplementsLoaderInterface() { - $this->getFileSystemLoader(); + $this->assertInstanceOf('\Liip\ImagineBundle\Binary\Loader\LoaderInterface', $this->getFileSystemLoader()); } /** diff --git a/Tests/Binary/Loader/FlysystemLoaderTest.php b/Tests/Binary/Loader/FlysystemLoaderTest.php index f8f0d0ad3..fddc18315 100644 --- a/Tests/Binary/Loader/FlysystemLoaderTest.php +++ b/Tests/Binary/Loader/FlysystemLoaderTest.php @@ -12,12 +12,14 @@ namespace Liip\ImagineBundle\Tests\Binary\Loader; use Liip\ImagineBundle\Binary\Loader\FlysystemLoader; +use Liip\ImagineBundle\Binary\Loader\LoaderInterface; use Liip\ImagineBundle\Tests\AbstractTest; use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser; /** * @requires PHP 5.4 - * @covers Liip\ImagineBundle\Binary\Loader\FlysystemLoader + * + * @covers \Liip\ImagineBundle\Binary\Loader\FlysystemLoader */ class FlysystemLoaderTest extends AbstractTest { @@ -28,55 +30,44 @@ public function setUp() parent::setUp(); if (!class_exists('\League\Flysystem\Filesystem')) { - $this->markTestSkipped( - 'The league/flysystem PHP library is not available.' - ); + $this->markTestSkipped('Requires the league/flysystem package.'); } - $adapter = new \League\Flysystem\Adapter\Local($this->fixturesDir); - $this->flyFilesystem = new \League\Flysystem\Filesystem($adapter); + $this->flyFilesystem = new \League\Flysystem\Filesystem(new \League\Flysystem\Adapter\Local($this->fixturesPath)); } - public function testShouldImplementLoaderInterface() + public function testConstruction() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Binary\Loader\FlysystemLoader'); - - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Binary\Loader\LoaderInterface')); + return new FlysystemLoader(ExtensionGuesser::getInstance(), $this->flyFilesystem); } - public function testCouldBeConstructedWithExpectedArguments() + /** + * @depends testConstruction + */ + public function testShouldImplementLoaderInterface(LoaderInterface $loader) { - return new FlysystemLoader( - ExtensionGuesser::getInstance(), - $this->flyFilesystem - ); + $this->assertInstanceOf('\Liip\ImagineBundle\Binary\Loader\LoaderInterface', $loader); } /** - * @depends testCouldBeConstructedWithExpectedArguments + * @depends testConstruction */ - public function testReturnImageContentOnFind($loader) + public function testReturnImageContentOnFind(LoaderInterface $loader) { - $expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg'); - $this->assertSame( - $expectedContent, + file_get_contents($this->fixturesPath.'/assets/cats.jpeg'), $loader->find('assets/cats.jpeg')->getContent() ); } /** - * @depends testCouldBeConstructedWithExpectedArguments + * @depends testConstruction + * + * @expectedException \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException + * @expectedExceptionMessageRegExp {Source image .+ not found} */ - public function testThrowsIfInvalidPathGivenOnFind($loader) + public function testThrowsIfInvalidPathGivenOnFind(LoaderInterface $loader) { - $path = 'invalid.jpeg'; - - $this->setExpectedException( - 'Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException', - sprintf('Source image "%s" not found.', $path) - ); - - $loader->find($path); + $loader->find('invalid.jpeg'); } } diff --git a/Tests/Binary/Loader/GridFSLoaderTest.php b/Tests/Binary/Loader/GridFSLoaderTest.php index 547482b37..db17cacbe 100644 --- a/Tests/Binary/Loader/GridFSLoaderTest.php +++ b/Tests/Binary/Loader/GridFSLoaderTest.php @@ -12,38 +12,49 @@ namespace Liip\ImagineBundle\Tests\Binary\Loader; use Doctrine\MongoDB\GridFSFile; +use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\DocumentRepository; use Liip\ImagineBundle\Binary\Loader\GridFSLoader; +use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Binary\Loader\GridFSLoader + * @covers \Liip\ImagineBundle\Binary\Loader\GridFSLoader */ -class GridFSLoaderTest extends \PHPUnit_Framework_TestCase +class GridFSLoaderTest extends AbstractTest { /** - * @var DocumentRepository + * @var \PHPUnit_Framework_MockObject_MockObject|DocumentRepository */ private $repo; /** - * @var GridFSLoader + * @var \PHPUnit_Framework_MockObject_MockObject|GridFSLoader */ private $loader; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|DocumentManager + */ + private $dm; + public function setUp() { if (!extension_loaded('mongodb')) { - $this->markTestSkipped('ext/mongodb is not installed'); + $this->markTestSkipped('Requires the mongodb extension.'); } - if (!class_exists('Doctrine\MongoDB\GridFSFile')) { - $this->markTestSkipped('doctrine mongo odm is not installed'); - } - $this->repo = $this->getMockBuilder('Doctrine\ODM\MongoDB\DocumentRepository')->disableOriginalConstructor()->getMock(); - $dm = $this->getMockBuilder('Doctrine\ODM\MongoDB\DocumentManager')->disableOriginalConstructor()->getMock(); - $dm->expects($this->any())->method('getRepository')->with('\Foo\Bar')->will($this->returnValue($this->repo)); + if (!class_exists('\Doctrine\MongoDB\GridFSFile')) { + $this->markTestSkipped('Requires the Doctrine mongo ODM.'); + } - $this->loader = new GridFSLoader($dm, '\Foo\Bar'); + $this->repo = $this->createObjectMock('\Doctrine\ODM\MongoDB\DocumentRepository'); + $this->dm = $this->createObjectMock('\Doctrine\ODM\MongoDB\DocumentManager'); + $this->dm + ->expects($this->any()) + ->method('getRepository') + ->with('\Foo\Bar') + ->will($this->returnValue($this->repo)); + $this->loader = new GridFSLoader($this->dm, '\Foo\Bar'); } public function testFindWithValidDocument() @@ -51,15 +62,18 @@ public function testFindWithValidDocument() $image = new GridFSFile(); $image->setBytes('01010101'); - $imageDocument = $this->getMock('ImageDocument', array('getFile')); + $imageDocument = $this->createObjectMock('ImageDocument', array('getFile')); $imageDocument ->expects($this->any()) ->method('getFile') ->with() - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $this->repo->expects($this->atLeastOnce())->method('find')->with($this->isInstanceOf('\MongoId'))->will($this->returnValue($imageDocument)); + $this->repo + ->expects($this->atLeastOnce()) + ->method('find') + ->with($this->isInstanceOf('\MongoId')) + ->will($this->returnValue($imageDocument)); $this->assertEquals('01010101', $this->loader->find('0123456789abcdef01234567')); } @@ -69,7 +83,11 @@ public function testFindWithValidDocument() */ public function testFindWithInValidDocument() { - $this->repo->expects($this->atLeastOnce())->method('find')->with($this->isInstanceOf('\MongoId'))->will($this->returnValue(null)); + $this->repo + ->expects($this->atLeastOnce()) + ->method('find') + ->with($this->isInstanceOf('\MongoId')) + ->will($this->returnValue(null)); $this->loader->find('0123456789abcdef01234567'); } diff --git a/Tests/Binary/Loader/StreamLoaderTest.php b/Tests/Binary/Loader/StreamLoaderTest.php index 1c3dabd3d..b4e0f54d3 100644 --- a/Tests/Binary/Loader/StreamLoaderTest.php +++ b/Tests/Binary/Loader/StreamLoaderTest.php @@ -15,54 +15,46 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Binary\Loader\StreamLoader + * @covers \Liip\ImagineBundle\Binary\Loader\StreamLoader */ class StreamLoaderTest extends AbstractTest { + /** + * @expectedException \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException + * @expectedExceptionMessageRegExp {Source image file://.+ not found.} + */ public function testThrowsIfInvalidPathGivenOnFind() { $loader = new StreamLoader('file://'); - - $path = $this->tempDir.'/invalid.jpeg'; - - $this->setExpectedException( - 'Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException', - 'Source image file://'.$path.' not found.' - ); - - $loader->find($path); + $loader->find($this->temporaryPath.'/invalid.jpeg'); } public function testReturnImageContentOnFind() { - $expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg'); - $loader = new StreamLoader('file://'); $this->assertSame( - $expectedContent, - $loader->find($this->fixturesDir.'/assets/cats.jpeg') + file_get_contents($this->fixturesPath.'/assets/cats.jpeg'), + $loader->find($this->fixturesPath.'/assets/cats.jpeg') ); } public function testReturnImageContentWhenStreamContextProvidedOnFind() { - $expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg'); - - $context = stream_context_create(); - - $loader = new StreamLoader('file://', $context); + $loader = new StreamLoader('file://', stream_context_create()); $this->assertSame( - $expectedContent, - $loader->find($this->fixturesDir.'/assets/cats.jpeg') + file_get_contents($this->fixturesPath.'/assets/cats.jpeg'), + $loader->find($this->fixturesPath.'/assets/cats.jpeg') ); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The given context is no valid resource + */ public function testThrowsIfInvalidResourceGivenInConstructor() { - $this->setExpectedException('InvalidArgumentException', 'The given context is no valid resource.'); - - new StreamLoader('not valid resource', true); + new StreamLoader('an-invalid-resource-name', true); } } diff --git a/Tests/Binary/SimpleMimeTypeGuesserTest.php b/Tests/Binary/SimpleMimeTypeGuesserTest.php index a6952e526..0cad03ebf 100644 --- a/Tests/Binary/SimpleMimeTypeGuesserTest.php +++ b/Tests/Binary/SimpleMimeTypeGuesserTest.php @@ -15,40 +15,50 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; /** - * @covers Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser + * @covers \Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser */ class SimpleMimeTypeGuesserTest extends \PHPUnit_Framework_TestCase { - public function provideImages() + /** + * @return SimpleMimeTypeGuesser + */ + private function getSimpleMimeTypeGuesser() { - return array( - 'gif' => array(__DIR__.'/../Fixtures/assets/cats.gif', 'image/gif'), - 'png' => array(__DIR__.'/../Fixtures/assets/cats.png', 'image/png'), - 'jpg' => array(__DIR__.'/../Fixtures/assets/cats.jpeg', 'image/jpeg'), - 'pdf' => array(__DIR__.'/../Fixtures/assets/cats.pdf', 'application/pdf'), - 'txt' => array(__DIR__.'/../Fixtures/assets/cats.txt', 'text/plain'), - ); + return new SimpleMimeTypeGuesser(MimeTypeGuesser::getInstance()); } - public function testImplementsMimeTypeGuesserInterface() + public function testCouldBeConstructedWithSymfonyMimeTypeGuesserAsFirstArgument() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser'); - - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Binary\MimeTypeGuesserInterface')); + $this->getSimpleMimeTypeGuesser(); } - public function testCouldBeConstructedWithSymfonyMimeTypeGuesserAsFirstArgument() + public function testImplementsMimeTypeGuesserInterface() { - new SimpleMimeTypeGuesser(MimeTypeGuesser::getInstance()); + $this->assertInstanceOf('\Liip\ImagineBundle\Binary\MimeTypeGuesserInterface', $this->getSimpleMimeTypeGuesser()); } /** - * @dataProvider provideImages + * @return array[] */ - public function testGuessMimeType($imageFile, $expectedMimeType) + public static function provideImageData() { - $guesser = new SimpleMimeTypeGuesser(MimeTypeGuesser::getInstance()); + return array( + 'gif' => array(__DIR__.'/../Fixtures/assets/cats.gif', 'image/gif'), + 'png' => array(__DIR__.'/../Fixtures/assets/cats.png', 'image/png'), + 'jpg' => array(__DIR__.'/../Fixtures/assets/cats.jpeg', 'image/jpeg'), + 'pdf' => array(__DIR__.'/../Fixtures/assets/cats.pdf', 'application/pdf'), + 'txt' => array(__DIR__.'/../Fixtures/assets/cats.txt', 'text/plain'), + ); + } - $this->assertEquals($expectedMimeType, $guesser->guess(file_get_contents($imageFile))); + /** + * @dataProvider provideImageData + * + * @param string $fileName + * @param string $mimeType + */ + public function testGuessMimeType($fileName, $mimeType) + { + $this->assertEquals($mimeType, $this->getSimpleMimeTypeGuesser()->guess(file_get_contents($fileName))); } } diff --git a/Tests/Controller/ImagineControllerTest.php b/Tests/Controller/ImagineControllerTest.php index d3d1d87d5..d93da8486 100644 --- a/Tests/Controller/ImagineControllerTest.php +++ b/Tests/Controller/ImagineControllerTest.php @@ -12,63 +12,21 @@ namespace Liip\ImagineBundle\Tests\Controller; use Liip\ImagineBundle\Controller\ImagineController; -use Liip\ImagineBundle\Imagine\Cache\CacheManager; -use Liip\ImagineBundle\Imagine\Data\DataManager; -use Liip\ImagineBundle\Imagine\Filter\FilterManager; +use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Controller\ImagineController + * @covers \Liip\ImagineBundle\Controller\ImagineController */ -class ImagineControllerTest extends \PHPUnit_Framework_TestCase +class ImagineControllerTest extends AbstractTest { - public function testCouldBeConstructedWithExpectedServices() + public function testConstruction() { new ImagineController( $this->createDataManagerMock(), $this->createFilterManagerMock(), $this->createCacheManagerMock(), - $this->createSignerMock(), - $this->createLoggerMock() + $this->createSignerInterfaceMock(), + $this->createLoggerInterfaceMock() ); } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|DataManager - */ - protected function createDataManagerMock() - { - return $this->getMock('Liip\ImagineBundle\Imagine\Data\DataManager', array(), array(), '', false); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|FilterManager - */ - protected function createFilterManagerMock() - { - return $this->getMock('Liip\ImagineBundle\Imagine\Filter\FilterManager', array(), array(), '', false); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|CacheManager - */ - protected function createCacheManagerMock() - { - return $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array(), array(), '', false); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\Liip\ImagineBundle\Imagine\Cache\SignerInterface - */ - protected function createSignerMock() - { - return $this->getMock('Liip\ImagineBundle\Imagine\Cache\Signer', array(), array(), '', false); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface - */ - protected function createLoggerMock() - { - return $this->getMock('Psr\Log\LoggerInterface'); - } } diff --git a/Tests/DependencyInjection/Compiler/MetadataReaderCompilerPassTest.php b/Tests/DependencyInjection/Compiler/MetadataReaderCompilerPassTest.php index c42251292..44a4c6028 100644 --- a/Tests/DependencyInjection/Compiler/MetadataReaderCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/MetadataReaderCompilerPassTest.php @@ -38,7 +38,7 @@ private static function getVisibilityRestrictedStaticProperty(\ReflectionClass $ */ private static function getReaderParamAndDefaultAndExifValues() { - $r = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Compiler\MetadataReaderCompilerPass'); + $r = new \ReflectionClass('\Liip\ImagineBundle\DependencyInjection\Compiler\MetadataReaderCompilerPass'); return array( static::getVisibilityRestrictedStaticProperty($r, 'metadataReaderParameter'), @@ -54,7 +54,7 @@ private static function getReaderParamAndDefaultAndExifValues() */ private function getMetadataReaderCompilerPass($return) { - $mock = $this->getMockBuilder('Liip\ImagineBundle\DependencyInjection\Compiler\MetadataReaderCompilerPass') + $mock = $this->getMockBuilder('\Liip\ImagineBundle\DependencyInjection\Compiler\MetadataReaderCompilerPass') ->setMethods(array('isExifExtensionLoaded')) ->getMock(); diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index a3a7c0c0b..497a7d1e0 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -22,15 +22,15 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * @covers Liip\ImagineBundle\DependencyInjection\Configuration + * @covers \Liip\ImagineBundle\DependencyInjection\Configuration */ class ConfigurationTest extends \Phpunit_Framework_TestCase { public function testImplementsConfigurationInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Configuration'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\DependencyInjection\Configuration'); - $this->assertTrue($rc->implementsInterface('Symfony\Component\Config\Definition\ConfigurationInterface')); + $this->assertTrue($rc->implementsInterface('\Symfony\Component\Config\Definition\ConfigurationInterface')); } public function testCouldBeConstructedWithResolversAndLoadersFactoriesAsArguments() @@ -146,9 +146,12 @@ public function testSetFilesystemLoaderAsDefaultLoaderIfNull() $this->assertArrayHasKey('filesystem', $config['loaders']['default']); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage Loaders has to be array + */ public function testThrowIfLoadersNotArray() { - $this->setExpectedException('LogicException', 'Loaders has to be array'); $this->processConfiguration( new Configuration( array( @@ -336,9 +339,12 @@ public function testSetWebPathAsDefaultResolverIfNull() $this->assertArrayHasKey('web_path', $config['resolvers']['default']); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage Resolvers has to be array + */ public function testThrowsIfResolversNotArray() { - $this->setExpectedException('LogicException', 'Resolvers has to be array'); $config = $this->processConfiguration( new Configuration( array( diff --git a/Tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php b/Tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php index 9173ef4a7..95295edf7 100644 --- a/Tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php @@ -24,9 +24,9 @@ class FileSystemLoaderFactoryTest extends FactoryTestCase { public function testImplementsLoaderFactoryInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface')); } public function testCouldBeConstructedWithoutAnyArguments() diff --git a/Tests/DependencyInjection/Factory/Loader/FlysystemLoaderFactoryTest.php b/Tests/DependencyInjection/Factory/Loader/FlysystemLoaderFactoryTest.php index c109f5140..3e9f66f1e 100644 --- a/Tests/DependencyInjection/Factory/Loader/FlysystemLoaderFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Loader/FlysystemLoaderFactoryTest.php @@ -18,7 +18,8 @@ /** * @requires PHP 5.4 - * @covers Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory + * + * @covers \Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory */ class FlysystemLoaderFactoryTest extends \Phpunit_Framework_TestCase { @@ -27,17 +28,15 @@ public function setUp() parent::setUp(); if (!class_exists('\League\Flysystem\Filesystem')) { - $this->markTestSkipped( - 'The league/flysystem PHP library is not available.' - ); + $this->markTestSkipped('Requires the league/flysystem package.'); } } public function testImplementsLoaderFactoryInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface')); } public function testCouldBeConstructedWithoutAnyArguments() diff --git a/Tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php b/Tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php index 995eb9e58..7309bb931 100644 --- a/Tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php @@ -17,15 +17,15 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * @covers Liip\ImagineBundle\DependencyInjection\Factory\Loader\StreamLoaderFactory + * @covers \Liip\ImagineBundle\DependencyInjection\Factory\Loader\StreamLoaderFactory */ class StreamLoaderFactoryTest extends \Phpunit_Framework_TestCase { public function testImplementsLoaderFactoryInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Loader\StreamLoaderFactory'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\DependencyInjection\Factory\Loader\StreamLoaderFactory'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface')); } public function testCouldBeConstructedWithoutAnyArguments() diff --git a/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php b/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php index cb1ea52bc..672676b47 100644 --- a/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php @@ -24,9 +24,9 @@ class AwsS3ResolverFactoryTest extends \Phpunit_Framework_TestCase { public function testImplementsResolverFactoryInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface')); } public function testCouldBeConstructedWithoutAnyArguments() @@ -61,10 +61,10 @@ public function testCreateResolverDefinitionOnCreate() $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name')); $resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $resolverDefinition->getParent()); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); $this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.client', $resolverDefinition->getArgument(0)); $this->assertEquals('theBucket', $resolverDefinition->getArgument(1)); @@ -116,7 +116,7 @@ public function testCreateS3ClientDefinitionOnCreate() $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name.client')); $clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name.client'); - $this->assertEquals('Aws\S3\S3Client', $clientDefinition->getClass()); + $this->assertEquals('\Aws\S3\S3Client', $clientDefinition->getClass()); $this->assertEquals(array('theClientConfigKey' => 'theClientConfigVal'), $clientDefinition->getArgument(0)); } @@ -142,10 +142,13 @@ public function testCreateS3ClientDefinitionWithFactoryOnCreate() )); $clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name.client'); - $this->assertEquals(array('Aws\S3\S3Client', 'factory'), $clientDefinition->getFactory()); + $this->assertEquals(array('\Aws\S3\S3Client', 'factory'), $clientDefinition->getFactory()); } - public function testLegacyCreateS3ClientDefinitionWithFactoryOnCreate() + /** + * @group legacy + */ + public function testCreateS3ClientDefinitionWithFactoryOnCreateLegacy() { if (SymfonyFramework::isKernelGreaterThanOrEqualTo(2, 6)) { $this->markTestSkipped('No need to test on symfony >= 2.6'); @@ -167,7 +170,7 @@ public function testLegacyCreateS3ClientDefinitionWithFactoryOnCreate() )); $clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name.client'); - $this->assertEquals('Aws\S3\S3Client', $clientDefinition->getFactoryClass()); + $this->assertEquals('\Aws\S3\S3Client', $clientDefinition->getFactoryClass()); $this->assertEquals('factory', $clientDefinition->getFactoryMethod()); } @@ -225,20 +228,20 @@ public function testWrapResolverWithCacheOnCreateWithoutProxy() $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name.cached')); $cachedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name.cached'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $cachedResolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $cachedResolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $cachedResolverDefinition->getParent()); $this->assertFalse($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name.proxied')); $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name')); $resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.cache', $resolverDefinition->getParent()); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); $this->assertEquals('the_cache_service_id', $resolverDefinition->getArgument(0)); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(1)); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(1)); $this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.cached', $resolverDefinition->getArgument(1)); } @@ -261,28 +264,28 @@ public function testWrapResolverWithProxyAndCacheOnCreate() $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name.proxied')); $proxiedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name.proxied'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $proxiedResolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $proxiedResolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $proxiedResolverDefinition->getParent()); $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name.cached')); $cachedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name.cached'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $cachedResolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $cachedResolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.proxy', $cachedResolverDefinition->getParent()); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $cachedResolverDefinition->getArgument(0)); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\Reference', $cachedResolverDefinition->getArgument(0)); $this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.proxied', $cachedResolverDefinition->getArgument(0)); $this->assertEquals(array('foo'), $cachedResolverDefinition->getArgument(1)); $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name')); $resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.cache', $resolverDefinition->getParent()); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); $this->assertEquals('the_cache_service_id', $resolverDefinition->getArgument(0)); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(1)); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(1)); $this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.cached', $resolverDefinition->getArgument(1)); } @@ -305,15 +308,15 @@ public function testWrapResolverWithProxyMatchReplaceStrategyOnCreate() $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name.proxied')); $proxiedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name.proxied'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $proxiedResolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $proxiedResolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $proxiedResolverDefinition->getParent()); $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name.cached')); $cachedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name.cached'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $cachedResolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $cachedResolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.proxy', $cachedResolverDefinition->getParent()); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $cachedResolverDefinition->getArgument(0)); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\Reference', $cachedResolverDefinition->getArgument(0)); $this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.proxied', $cachedResolverDefinition->getArgument(0)); $this->assertEquals(array('foo' => 'bar'), $cachedResolverDefinition->getArgument(1)); diff --git a/Tests/DependencyInjection/Factory/Resolver/FlysystemResolverFactoryTest.php b/Tests/DependencyInjection/Factory/Resolver/FlysystemResolverFactoryTest.php index 868088c1f..fe03ad45a 100644 --- a/Tests/DependencyInjection/Factory/Resolver/FlysystemResolverFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Resolver/FlysystemResolverFactoryTest.php @@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * @covers Liip\ImagineBundle\DependencyInjection\Factory\Resolver\FlysystemResolverFactory + * @covers \Liip\ImagineBundle\DependencyInjection\Factory\Resolver\FlysystemResolverFactory */ class FlysystemResolverFactoryTest extends \Phpunit_Framework_TestCase { @@ -26,17 +26,15 @@ public function setUp() parent::setUp(); if (!class_exists('\League\Flysystem\Filesystem')) { - $this->markTestSkipped( - 'The league/flysystem PHP library is not available.' - ); + $this->markTestSkipped('Requires the league/flysystem package.'); } } public function testImplementsResolverFactoryInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\FlysystemResolverFactory'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\DependencyInjection\Factory\Resolver\FlysystemResolverFactory'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface')); } public function testCouldBeConstructedWithoutAnyArguments() @@ -67,7 +65,7 @@ public function testCreateResolverDefinitionOnCreate() $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name')); $resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.flysystem', $resolverDefinition->getParent()); $this->assertEquals('http://images.example.com', $resolverDefinition->getArgument(2)); diff --git a/Tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php b/Tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php index bf4e24f2a..8530ad7a6 100644 --- a/Tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php @@ -17,15 +17,15 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * @covers Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory + * @covers \Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory */ class WebPathResolverFactoryTest extends \Phpunit_Framework_TestCase { public function testImplementsResolverFactoryInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface')); } public function testCouldBeConstructedWithoutAnyArguments() @@ -54,7 +54,7 @@ public function testCreateResolverDefinitionOnCreate() $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name')); $resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); $this->assertEquals('liip_imagine.cache.resolver.prototype.web_path', $resolverDefinition->getParent()); $this->assertEquals('theWebRoot', $resolverDefinition->getArgument(2)); diff --git a/Tests/DependencyInjection/LiipImagineExtensionTest.php b/Tests/DependencyInjection/LiipImagineExtensionTest.php index 07b1350f8..5b8492ffc 100644 --- a/Tests/DependencyInjection/LiipImagineExtensionTest.php +++ b/Tests/DependencyInjection/LiipImagineExtensionTest.php @@ -39,8 +39,7 @@ class LiipImagineExtensionTest extends AbstractTest public function testUserLoadThrowsExceptionUnlessDriverIsValid() { $loader = new LiipImagineExtension(); - $config = array('driver' => 'foo'); - $loader->load(array($config), new ContainerBuilder()); + $loader->load(array(array('driver' => 'foo')), new ContainerBuilder()); } public function testLoadWithDefaults() @@ -73,8 +72,22 @@ public function testCustomRouteRequirements() $this->assertEquals('value1', $variable1, sprintf('%s parameter is correct', $variable1)); } + public static function provideFactoryData() + { + return array( + array( + 'liip_imagine.mime_type_guesser', + array('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', 'getInstance'), + ), + array( + 'liip_imagine.extension_guesser', + array('Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser', 'getInstance'), + ), + ); + } + /** - * @dataProvider factoriesProvider + * @dataProvider provideFactoryData */ public function testFactoriesConfiguration($service, $factory) { @@ -89,10 +102,11 @@ public function testFactoriesConfiguration($service, $factory) } /** - * @legacy - * @dataProvider factoriesProvider + * @group legacy + * + * @dataProvider provideFactoryData */ - public function testLegacyFactoriesConfiguration($service, $factory) + public function testFactoriesConfigurationLegacy($service, $factory) { if (SymfonyFramework::isKernelGreaterThanOrEqualTo(2, 6)) { $this->markTestSkipped('No need to test on symfony >= 2.6'); @@ -105,20 +119,6 @@ public function testLegacyFactoriesConfiguration($service, $factory) $this->assertEquals($factory[1], $definition->getFactoryMethod()); } - public function factoriesProvider() - { - return array( - array( - 'liip_imagine.mime_type_guesser', - array('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', 'getInstance'), - ), - array( - 'liip_imagine.extension_guesser', - array('Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser', 'getInstance'), - ), - ); - } - protected function createEmptyConfiguration() { $this->containerBuilder = new ContainerBuilder(); @@ -126,6 +126,7 @@ protected function createEmptyConfiguration() $loader->addLoaderFactory(new FileSystemLoaderFactory()); $loader->addResolverFactory(new WebPathResolverFactory()); $loader->load(array(array()), $this->containerBuilder); + $this->assertTrue($this->containerBuilder instanceof ContainerBuilder); } @@ -136,6 +137,7 @@ protected function createFullConfiguration() $loader->addLoaderFactory(new FileSystemLoaderFactory()); $loader->addResolverFactory(new WebPathResolverFactory()); $loader->load(array($this->getFullConfig()), $this->containerBuilder); + $this->assertTrue($this->containerBuilder instanceof ContainerBuilder); } diff --git a/Tests/Events/CacheResolveEventTest.php b/Tests/Events/CacheResolveEventTest.php index 9a70dc329..4a77d2966 100644 --- a/Tests/Events/CacheResolveEventTest.php +++ b/Tests/Events/CacheResolveEventTest.php @@ -14,7 +14,7 @@ use Liip\ImagineBundle\Events\CacheResolveEvent; /** - * @covers Liip\ImagineBundle\Events\CacheResolveEvent + * @covers \Liip\ImagineBundle\Events\CacheResolveEvent */ class CacheResolveEventTest extends \PHPUnit_Framework_TestCase { diff --git a/Tests/Exception/Imagine/Cache/Resolver/NotResolvableExceptionTest.php b/Tests/Exception/Imagine/Cache/Resolver/NotResolvableExceptionTest.php index 9104cc68b..7a5f7b4e4 100644 --- a/Tests/Exception/Imagine/Cache/Resolver/NotResolvableExceptionTest.php +++ b/Tests/Exception/Imagine/Cache/Resolver/NotResolvableExceptionTest.php @@ -14,7 +14,7 @@ use Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException; /** - * @covers Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException + * @covers \Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException */ class NotResolvableExceptionTest extends \PHPUnit_Framework_TestCase { @@ -29,6 +29,6 @@ public function testImplementsExceptionInterface() { $e = new NotResolvableException(); - $this->assertInstanceOf('Liip\ImagineBundle\Exception\ExceptionInterface', $e); + $this->assertInstanceOf('\Liip\ImagineBundle\Exception\ExceptionInterface', $e); } } diff --git a/Tests/Exception/Imagine/Cache/Resolver/NotStorableExceptionTest.php b/Tests/Exception/Imagine/Cache/Resolver/NotStorableExceptionTest.php index acd14e47c..5f2ade33e 100644 --- a/Tests/Exception/Imagine/Cache/Resolver/NotStorableExceptionTest.php +++ b/Tests/Exception/Imagine/Cache/Resolver/NotStorableExceptionTest.php @@ -14,7 +14,7 @@ use Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException; /** - * @covers Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException + * @covers \Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException */ class NotStorableExceptionTest extends \PHPUnit_Framework_TestCase { @@ -29,6 +29,6 @@ public function testImplementsExceptionInterface() { $e = new NotStorableException(); - $this->assertInstanceOf('Liip\ImagineBundle\Exception\ExceptionInterface', $e); + $this->assertInstanceOf('\Liip\ImagineBundle\Exception\ExceptionInterface', $e); } } diff --git a/Tests/Form/Type/ImageTypeTest.php b/Tests/Form/Type/ImageTypeTest.php index 37c543cee..ceb16145a 100644 --- a/Tests/Form/Type/ImageTypeTest.php +++ b/Tests/Form/Type/ImageTypeTest.php @@ -13,13 +13,14 @@ use Liip\ImagineBundle\Form\Type\ImageType; use Liip\ImagineBundle\Utility\Framework\SymfonyFramework; +use Liip\ImagineBundle\Tests\AbstractTest; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; /** * @covers \Liip\ImagineBundle\Form\Type\ImageType */ -class ImageTypeTest extends \PHPUnit_Framework_TestCase +class ImageTypeTest extends AbstractTest { public function testGetName() { @@ -55,7 +56,10 @@ public function testConfigureOptions() $this->assertTrue($resolver->isDefined('link_attr')); } - public function testLegacySetDefaultOptions() + /** + * @group legacy + */ + public function testSetDefaultOptionsLegacy() { if (SymfonyFramework::isKernelGreaterThanOrEqualTo(2, 6)) { $this->markTestSkipped('No need to test on symfony >= 2.6'); @@ -88,7 +92,7 @@ public function testBuildView() $view = new FormView(); $type = new ImageType(); - $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); + $form = $this->createObjectMock('\Symfony\Component\Form\Test\FormInterface'); $type->buildView($view, $form, $options); diff --git a/Tests/Functional/AbstractSetupWebTestCase.php b/Tests/Functional/AbstractSetupWebTestCase.php new file mode 100644 index 000000000..9c4e6a2da --- /dev/null +++ b/Tests/Functional/AbstractSetupWebTestCase.php @@ -0,0 +1,49 @@ +client = $this->createClient(); + $this->webRoot = self::$kernel->getContainer()->getParameter('kernel.root_dir').'/web'; + $this->cacheRoot = $this->webRoot.'/media/cache'; + $this->filesystem = new Filesystem(); + $this->filesystem->remove($this->cacheRoot); + } +} diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/AbstractWebTestCase.php similarity index 88% rename from Tests/Functional/WebTestCase.php rename to Tests/Functional/AbstractWebTestCase.php index 9eb0d6c46..b96b93deb 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/AbstractWebTestCase.php @@ -11,10 +11,9 @@ namespace Liip\ImagineBundle\Tests\Functional; -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; -use Symfony\Component\HttpKernel\Kernel; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -abstract class WebTestCase extends BaseWebTestCase +abstract class AbstractWebTestCase extends WebTestCase { /** * @return string diff --git a/Tests/Functional/ExtensionGuesserTest.php b/Tests/Functional/Binary/ExtensionGuesserTest.php similarity index 50% rename from Tests/Functional/ExtensionGuesserTest.php rename to Tests/Functional/Binary/ExtensionGuesserTest.php index 4827ca1f8..ccab9cf66 100644 --- a/Tests/Functional/ExtensionGuesserTest.php +++ b/Tests/Functional/Binary/ExtensionGuesserTest.php @@ -9,15 +9,19 @@ * file that was distributed with this source code. */ -namespace Liip\ImagineBundle\Tests\Functional; +namespace Liip\ImagineBundle\Tests\Functional\Binary; -class ExtensionGuesserTest extends WebTestCase +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; + +class ExtensionGuesserTest extends AbstractWebTestCase { public function testCouldBeGetFromContainerAsService() { $this->createClient(); - $guesser = self::$kernel->getContainer()->get('liip_imagine.extension_guesser'); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser', $guesser); + $this->assertInstanceOf( + '\Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser', + self::$kernel->getContainer()->get('liip_imagine.extension_guesser') + ); } } diff --git a/Tests/Functional/Binary/Loader/FileSystemLoaderTest.php b/Tests/Functional/Binary/Loader/FileSystemLoaderTest.php index 5b16f1a3e..cec47b9bc 100644 --- a/Tests/Functional/Binary/Loader/FileSystemLoaderTest.php +++ b/Tests/Functional/Binary/Loader/FileSystemLoaderTest.php @@ -12,12 +12,12 @@ namespace Liip\ImagineBundle\Tests\Functional\Binary\Loader; use Liip\ImagineBundle\Binary\Loader\FileSystemLoader; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; /** * @covers \Liip\ImagineBundle\Binary\Loader\FileSystemLoader */ -class FileSystemLoaderTest extends WebTestCase +class FileSystemLoaderTest extends AbstractWebTestCase { /** * @param string $name diff --git a/Tests/Functional/Binary/Locator/FileSystemLocatorTest.php b/Tests/Functional/Binary/Locator/FileSystemLocatorTest.php index 5b2e8baf4..8ba038209 100644 --- a/Tests/Functional/Binary/Locator/FileSystemLocatorTest.php +++ b/Tests/Functional/Binary/Locator/FileSystemLocatorTest.php @@ -13,12 +13,12 @@ use Liip\ImagineBundle\Binary\Locator\FileSystemLocator; use Liip\ImagineBundle\Binary\Locator\LocatorInterface; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; /** * @covers \Liip\ImagineBundle\Binary\Locator\FileSystemLocator */ -class FileSystemLocatorTest extends WebTestCase +class FileSystemLocatorTest extends AbstractWebTestCase { /** * @param string $name diff --git a/Tests/Functional/MimeTypeGuesserTest.php b/Tests/Functional/Binary/MimeTypeGuesserTest.php similarity index 51% rename from Tests/Functional/MimeTypeGuesserTest.php rename to Tests/Functional/Binary/MimeTypeGuesserTest.php index 3ba0218f1..d0420bf2e 100644 --- a/Tests/Functional/MimeTypeGuesserTest.php +++ b/Tests/Functional/Binary/MimeTypeGuesserTest.php @@ -9,15 +9,19 @@ * file that was distributed with this source code. */ -namespace Liip\ImagineBundle\Tests\Functional; +namespace Liip\ImagineBundle\Tests\Functional\Binary; -class MimeTypeGuesserTest extends WebTestCase +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; + +class MimeTypeGuesserTest extends AbstractWebTestCase { public function testCouldBeGetFromContainerAsService() { $this->createClient(); - $guesser = self::$kernel->getContainer()->get('liip_imagine.mime_type_guesser'); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', $guesser); + $this->assertInstanceOf( + '\Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', + self::$kernel->getContainer()->get('liip_imagine.mime_type_guesser') + ); } } diff --git a/Tests/Functional/Binary/SimpleMimeTypeGuesserTest.php b/Tests/Functional/Binary/SimpleMimeTypeGuesserTest.php index 386d94d71..f272d9c2f 100644 --- a/Tests/Functional/Binary/SimpleMimeTypeGuesserTest.php +++ b/Tests/Functional/Binary/SimpleMimeTypeGuesserTest.php @@ -11,16 +11,17 @@ namespace Liip\ImagineBundle\Tests\Functional\Binary; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; -class SimpleMimeTypeGuesserTest extends WebTestCase +class SimpleMimeTypeGuesserTest extends AbstractWebTestCase { public function testCouldBeGetFromContainerAsService() { $this->createClient(); - $service = self::$kernel->getContainer()->get('liip_imagine.binary.mime_type_guesser'); - - $this->assertInstanceOf('Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser', $service); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser', + self::$kernel->getContainer()->get('liip_imagine.binary.mime_type_guesser') + ); } } diff --git a/Tests/Functional/Command/AbstractCommandTestCase.php b/Tests/Functional/Command/AbstractCommandTestCase.php new file mode 100644 index 000000000..c620f9df5 --- /dev/null +++ b/Tests/Functional/Command/AbstractCommandTestCase.php @@ -0,0 +1,44 @@ +setApplication(new Application($this->createClient()->getKernel())); + if ($command instanceof ContainerAwareCommand) { + $command->setContainer($this->createClient()->getContainer()); + } + + $arguments = array_replace(array('command' => $command->getName()), $arguments); + $options = array_replace(array('--env' => 'test'), $options); + + $commandTester = new CommandTester($command); + $commandTester->execute($arguments, $options); + + return $commandTester->getDisplay(); + } +} diff --git a/Tests/Functional/Command/RemoveCacheTest.php b/Tests/Functional/Command/RemoveCacheTest.php index ad13bf3d9..ccf00bbf0 100644 --- a/Tests/Functional/Command/RemoveCacheTest.php +++ b/Tests/Functional/Command/RemoveCacheTest.php @@ -12,39 +12,12 @@ namespace Liip\ImagineBundle\Tests\Functional\Command; use Liip\ImagineBundle\Command\RemoveCacheCommand; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; -use Symfony\Component\Console\Application; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Filesystem\Filesystem; /** - * @covers Liip\ImagineBundle\Command\RemoveCacheCommand + * @covers \Liip\ImagineBundle\Command\RemoveCacheCommand */ -class RemoveCacheTest extends WebTestCase +class RemoveCacheTest extends AbstractCommandTestCase { - protected $client; - - protected $webRoot; - - protected $filesystem; - - protected $cacheRoot; - - public function setUp() - { - parent::setUp(); - - $this->client = $this->createClient(); - - $this->webRoot = self::$kernel->getContainer()->getParameter('kernel.root_dir').'/web'; - $this->cacheRoot = $this->webRoot.'/media/cache'; - - $this->filesystem = new Filesystem(); - $this->filesystem->remove($this->cacheRoot); - } - public function testExecuteSuccessfullyWithEmptyCacheAndWithoutParameters() { $this->assertFileNotExists($this->cacheRoot.'/thumbnail_web_path/images/cats.jpeg'); @@ -279,29 +252,4 @@ public function testShouldRemoveCacheByMultiplePathsAndSingleFilter() $this->assertFileNotExists($this->cacheRoot.'/thumbnail_web_path/images/cats2.jpeg'); $this->assertFileExists($this->cacheRoot.'/thumbnail_default/images/cats.jpeg'); } - - /** - * Helper function return the result of command execution. - * - * @param Command $command - * @param array $arguments - * @param array $options - * - * @return string - */ - protected function executeConsole(Command $command, array $arguments = array(), array $options = array()) - { - $command->setApplication(new Application($this->createClient()->getKernel())); - if ($command instanceof ContainerAwareCommand) { - $command->setContainer($this->createClient()->getContainer()); - } - - $arguments = array_replace(array('command' => $command->getName()), $arguments); - $options = array_replace(array('--env' => 'test'), $options); - - $commandTester = new CommandTester($command); - $commandTester->execute($arguments, $options); - - return $commandTester->getDisplay(); - } } diff --git a/Tests/Functional/Command/ResolveCacheTest.php b/Tests/Functional/Command/ResolveCacheTest.php index 3db992185..b0437e002 100644 --- a/Tests/Functional/Command/ResolveCacheTest.php +++ b/Tests/Functional/Command/ResolveCacheTest.php @@ -12,39 +12,12 @@ namespace Liip\ImagineBundle\Tests\Functional\Command; use Liip\ImagineBundle\Command\ResolveCacheCommand; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; -use Symfony\Component\Console\Application; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Filesystem\Filesystem; /** - * @covers Liip\ImagineBundle\Command\ResolveCacheCommand + * @covers \Liip\ImagineBundle\Command\ResolveCacheCommand */ -class ResolveCacheTest extends WebTestCase +class ResolveCacheTest extends AbstractCommandTestCase { - protected $client; - - protected $webRoot; - - protected $filesystem; - - protected $cacheRoot; - - public function setUp() - { - parent::setUp(); - - $this->client = $this->createClient(); - - $this->webRoot = self::$kernel->getContainer()->getParameter('kernel.root_dir').'/web'; - $this->cacheRoot = $this->webRoot.'/media/cache'; - - $this->filesystem = new Filesystem(); - $this->filesystem->remove($this->cacheRoot); - } - public function testShouldResolveWithEmptyCache() { $this->assertFileNotExists($this->cacheRoot.'/thumbnail_web_path/images/cats.jpeg'); @@ -143,29 +116,4 @@ public function testShouldResolveWithFewPathsAndWithoutFilters() $this->assertContains('http://localhost/media/cache/thumbnail_default/images/cats.jpeg', $output); $this->assertContains('http://localhost/media/cache/thumbnail_default/images/cats2.jpeg', $output); } - - /** - * Helper function return the result of command execution. - * - * @param Command $command - * @param array $arguments - * @param array $options - * - * @return string - */ - protected function executeConsole(Command $command, array $arguments = array(), array $options = array()) - { - $command->setApplication(new Application($this->createClient()->getKernel())); - if ($command instanceof ContainerAwareCommand) { - $command->setContainer($this->createClient()->getContainer()); - } - - $arguments = array_replace(array('command' => $command->getName()), $arguments); - $options = array_replace(array('--env' => 'test'), $options); - - $commandTester = new CommandTester($command); - $commandTester->execute($arguments, $options); - - return $commandTester->getDisplay(); - } } diff --git a/Tests/Functional/Controller/ImagineControllerTest.php b/Tests/Functional/Controller/ImagineControllerTest.php index 4cda6a00d..85d1d9c4e 100644 --- a/Tests/Functional/Controller/ImagineControllerTest.php +++ b/Tests/Functional/Controller/ImagineControllerTest.php @@ -12,47 +12,19 @@ namespace Liip\ImagineBundle\Tests\Functional\Controller; use Liip\ImagineBundle\Imagine\Cache\Signer; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; -use Symfony\Bundle\FrameworkBundle\Client; -use Symfony\Component\Filesystem\Filesystem; +use Liip\ImagineBundle\Tests\Functional\AbstractSetupWebTestCase; /** - * @covers Liip\ImagineBundle\Controller\ImagineController + * @covers \Liip\ImagineBundle\Controller\ImagineController */ -class ImagineControllerTest extends WebTestCase +class ImagineControllerTest extends AbstractSetupWebTestCase { - /** - * @var Client - */ - protected $client; - - protected $webRoot; - - protected $cacheRoot; - - /** - * @var Filesystem - */ - protected $filesystem; - - public function setUp() - { - parent::setUp(); - - $this->client = $this->createClient(); - - $this->webRoot = self::$kernel->getContainer()->getParameter('kernel.root_dir').'/web'; - $this->cacheRoot = $this->webRoot.'/media/cache'; - - $this->filesystem = new Filesystem(); - $this->filesystem->remove($this->cacheRoot); - } - public function testCouldBeGetFromContainer() { - $controller = self::$kernel->getContainer()->get('liip_imagine.controller'); - - $this->assertInstanceOf('Liip\ImagineBundle\Controller\ImagineController', $controller); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Controller\ImagineController', + self::$kernel->getContainer()->get('liip_imagine.controller') + ); } public function testShouldResolvePopulatingCacheFirst() @@ -64,7 +36,7 @@ public function testShouldResolvePopulatingCacheFirst() $response = $this->client->getResponse(); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $response); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://localhost/media/cache/thumbnail_web_path/images/cats.jpeg', $response->getTargetUrl()); @@ -82,7 +54,7 @@ public function testShouldResolveFromCache() $response = $this->client->getResponse(); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $response); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://localhost/media/cache/thumbnail_web_path/images/cats.jpeg', $response->getTargetUrl()); @@ -158,7 +130,7 @@ public function testShouldResolveWithCustomFiltersPopulatingCacheFirst() $response = $this->client->getResponse(); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $response); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://localhost/media/cache/'.$expectedCachePath, $response->getTargetUrl()); @@ -193,7 +165,7 @@ public function testShouldResolveWithCustomFiltersFromCache() $response = $this->client->getResponse(); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $response); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://localhost/media/cache'.'/'.$expectedCachePath, $response->getTargetUrl()); @@ -213,7 +185,7 @@ public function testShouldResolvePathWithSpecialCharactersAndWhiteSpaces() $response = $this->client->getResponse(); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $response); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://localhost/media/cache/thumbnail_web_path/images/foo bar.jpeg', $response->getTargetUrl()); diff --git a/Tests/Functional/Imagine/Cache/Resolver/NoCacheWebPathResolverTest.php b/Tests/Functional/Imagine/Cache/Resolver/NoCacheWebPathResolverTest.php index 88000152b..08d94841d 100644 --- a/Tests/Functional/Imagine/Cache/Resolver/NoCacheWebPathResolverTest.php +++ b/Tests/Functional/Imagine/Cache/Resolver/NoCacheWebPathResolverTest.php @@ -11,19 +11,20 @@ namespace Liip\ImagineBundle\Tests\Functional\Imagine\Cache\Resolver; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; /** - * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\NoCacheWebPathResolver + * @covers \Liip\ImagineBundle\Imagine\Cache\Resolver\NoCacheWebPathResolver */ -class NoCacheWebPathResolverTest extends WebTestCase +class NoCacheWebPathResolverTest extends AbstractWebTestCase { public function testCouldBeGetFromContainer() { $this->createClient(); - $resolver = self::$kernel->getContainer()->get('liip_imagine.cache.resolver.no_cache_web_path'); - - $this->assertInstanceOf('Liip\ImagineBundle\Imagine\Cache\Resolver\NoCacheWebPathResolver', $resolver); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Imagine\Cache\Resolver\NoCacheWebPathResolver', + self::$kernel->getContainer()->get('liip_imagine.cache.resolver.no_cache_web_path') + ); } } diff --git a/Tests/Functional/SignerTest.php b/Tests/Functional/Imagine/Cache/SignerTest.php similarity index 51% rename from Tests/Functional/SignerTest.php rename to Tests/Functional/Imagine/Cache/SignerTest.php index 066c8ce20..45a7e43b0 100644 --- a/Tests/Functional/SignerTest.php +++ b/Tests/Functional/Imagine/Cache/SignerTest.php @@ -9,15 +9,19 @@ * file that was distributed with this source code. */ -namespace Liip\ImagineBundle\Tests\Functional; +namespace Liip\ImagineBundle\Tests\Functional\Imagine\Cache; -class SignerTest extends WebTestCase +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; + +class SignerTest extends AbstractWebTestCase { public function testGetAsService() { $this->createClient(); - $service = self::$kernel->getContainer()->get('liip_imagine.cache.signer'); - $this->assertInstanceOf('Liip\ImagineBundle\Imagine\Cache\SignerInterface', $service); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Imagine\Cache\SignerInterface', + self::$kernel->getContainer()->get('liip_imagine.cache.signer') + ); } } diff --git a/Tests/Functional/Imagine/Data/DataManagerTest.php b/Tests/Functional/Imagine/Data/DataManagerTest.php index 1b4cd7f9d..12befbabc 100644 --- a/Tests/Functional/Imagine/Data/DataManagerTest.php +++ b/Tests/Functional/Imagine/Data/DataManagerTest.php @@ -11,15 +11,20 @@ namespace Liip\ImagineBundle\Tests\Functional\Imagine\Data; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; -class DataManagerTest extends WebTestCase +/** + * @covers \Liip\ImagineBundle\Imagine\Data\DataManager + */ +class DataManagerTest extends AbstractWebTestCase { public function testCouldBeGetFromContainerAsService() { $this->createClient(); - $service = self::$kernel->getContainer()->get('liip_imagine.data.manager'); - $this->assertInstanceOf('Liip\ImagineBundle\Imagine\Data\DataManager', $service); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Imagine\Data\DataManager', + self::$kernel->getContainer()->get('liip_imagine.data.manager') + ); } } diff --git a/Tests/Functional/Imagine/Filter/FilterManagerTest.php b/Tests/Functional/Imagine/Filter/FilterManagerTest.php index d318c30f3..8093d173a 100644 --- a/Tests/Functional/Imagine/Filter/FilterManagerTest.php +++ b/Tests/Functional/Imagine/Filter/FilterManagerTest.php @@ -11,15 +11,20 @@ namespace Liip\ImagineBundle\Tests\Functional\Imagine\Filter; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; -class FilterManagerTest extends WebTestCase +/** + * @covers \Liip\ImagineBundle\Imagine\Filter\FilterManager + */ +class FilterManagerTest extends AbstractWebTestCase { public function testCouldBeGetFromContainerAsService() { $this->createClient(); - $service = self::$kernel->getContainer()->get('liip_imagine.filter.manager'); - $this->assertInstanceOf('Liip\ImagineBundle\Imagine\Filter\FilterManager', $service); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Imagine\Filter\FilterManager', + self::$kernel->getContainer()->get('liip_imagine.filter.manager') + ); } } diff --git a/Tests/Functional/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php b/Tests/Functional/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php index e05c914b7..80814f77d 100644 --- a/Tests/Functional/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php +++ b/Tests/Functional/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php @@ -11,15 +11,20 @@ namespace Liip\ImagineBundle\Tests\Functional\Imagine\Filter\Loader; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; -class DownscaleFilterLoaderTest extends WebTestCase +/** + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\DownscaleFilterLoader + */ +class DownscaleFilterLoaderTest extends AbstractWebTestCase { public function testCouldBeGetFromContainerAsService() { $this->createClient(); - $service = self::$kernel->getContainer()->get('liip_imagine.filter.loader.downscale'); - $this->assertInstanceOf('Liip\ImagineBundle\Imagine\Filter\Loader\DownscaleFilterLoader', $service); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Imagine\Filter\Loader\DownscaleFilterLoader', + self::$kernel->getContainer()->get('liip_imagine.filter.loader.downscale') + ); } } diff --git a/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php b/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php index b789d6ca6..e82d1e906 100644 --- a/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php +++ b/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php @@ -11,20 +11,22 @@ namespace Liip\ImagineBundle\Tests\Functional\Imagine\Filter\Loader; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; /** - * Functional test cases for GrayscaleFilterLoader class. + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader * * @author Gregoire Humeau */ -class GrayscaleFilterLoaderTest extends WebTestCase +class GrayscaleFilterLoaderTest extends AbstractWebTestCase { public function testCouldBeGetFromContainerAsService() { $this->createClient(); - $service = self::$kernel->getContainer()->get('liip_imagine.filter.loader.grayscale'); - $this->assertInstanceOf('Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader', $service); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader', + self::$kernel->getContainer()->get('liip_imagine.filter.loader.grayscale') + ); } } diff --git a/Tests/Functional/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php b/Tests/Functional/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php index f92898e59..e5dd6832d 100644 --- a/Tests/Functional/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php +++ b/Tests/Functional/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php @@ -11,15 +11,20 @@ namespace Liip\ImagineBundle\Tests\Functional\Imagine\Filter\Loader; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; -class InterlaceFilterLoaderTest extends WebTestCase +/** + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\InterlaceFilterLoader + */ +class InterlaceFilterLoaderTest extends AbstractWebTestCase { public function testCouldBeGetFromContainerAsService() { $this->createClient(); - $service = self::$kernel->getContainer()->get('liip_imagine.filter.loader.interlace'); - $this->assertInstanceOf('Liip\ImagineBundle\Imagine\Filter\Loader\InterlaceFilterLoader', $service); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Imagine\Filter\Loader\InterlaceFilterLoader', + self::$kernel->getContainer()->get('liip_imagine.filter.loader.interlace') + ); } } diff --git a/Tests/Functional/Imagine/Filter/Loader/RotateFilterLoaderTest.php b/Tests/Functional/Imagine/Filter/Loader/RotateFilterLoaderTest.php index bf314e615..dd3c222c9 100644 --- a/Tests/Functional/Imagine/Filter/Loader/RotateFilterLoaderTest.php +++ b/Tests/Functional/Imagine/Filter/Loader/RotateFilterLoaderTest.php @@ -11,20 +11,22 @@ namespace Liip\ImagineBundle\Tests\Functional\Imagine\Filter\Loader; -use Liip\ImagineBundle\Tests\Functional\WebTestCase; +use Liip\ImagineBundle\Tests\Functional\AbstractWebTestCase; /** - * Functional test cases for RotateFilterLoader class. + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\RotateFilterLoader * * @author Bocharsky Victor */ -class RotateFilterLoaderTest extends WebTestCase +class RotateFilterLoaderTest extends AbstractWebTestCase { public function testCouldBeGetFromContainerAsService() { $this->createClient(); - $service = self::$kernel->getContainer()->get('liip_imagine.filter.loader.rotate'); - $this->assertInstanceOf('Liip\ImagineBundle\Imagine\Filter\Loader\RotateFilterLoader', $service); + $this->assertInstanceOf( + '\Liip\ImagineBundle\Imagine\Filter\Loader\RotateFilterLoader', + self::$kernel->getContainer()->get('liip_imagine.filter.loader.rotate') + ); } } diff --git a/Tests/Functional/app/config/config.yml b/Tests/Functional/app/config/config.yml index 49fd0d2db..125be17a4 100644 --- a/Tests/Functional/app/config/config.yml +++ b/Tests/Functional/app/config/config.yml @@ -1,61 +1,79 @@ +--- + parameters: - locale: en - secret: ThisTokenIsNotSoSecretChangeIt + + locale: en + secret: ThisTokenIsNotSoSecretChangeIt framework: - #esi: ~ - #translator: { fallback: "%locale%" } - test: ~ - templating: { engines: ['php'] } + + secret: "%secret%" + default_locale: "%locale%" + translator: ~ + test: ~ + + templating: + engines: [ 'php' ] + session: storage_id: session.storage.mock_file - secret: "%secret%" - router: { resource: "%kernel.root_dir%/config/routing.yml" } - default_locale: "%locale%" - translator: ~ + + router: + resource: "%kernel.root_dir%/config/routing.yml" liip_imagine: + loaders: + default: filesystem: data_root: "%kernel.root_dir%/web" + foo: filesystem: data_root: "%kernel.root_dir%/../../Fixtures/FileSystemLocator/root-01" + bar: filesystem: data_root: "%kernel.root_dir%/../../Fixtures/FileSystemLocator/root-02" + bundles_all: filesystem: data_root: ~ bundle_resources: enabled: true + bundles_only_foo: filesystem: data_root: ~ bundle_resources: - enabled: true + enabled: true access_control_type: blacklist - access_control_list: - - LiipBarBundle + access_control_list: [ 'LiipBarBundle' ] + bundles_only_bar: filesystem: data_root: ~ bundle_resources: - enabled: true + enabled: true access_control_type: whitelist - access_control_list: - - LiipBarBundle + access_control_list: [ 'LiipBarBundle' ] + resolvers: + default: web_path: - web_root: "%kernel.root_dir%/web" + web_root: "%kernel.root_dir%/web" cache_prefix: media/cache filter_sets: + thumbnail_web_path: filters: thumbnail: { size: [223, 223], mode: inset } + thumbnail_default: filters: thumbnail: { size: [223, 223], mode: inset } + +... diff --git a/Tests/Functional/app/config/routing.yml b/Tests/Functional/app/config/routing.yml index 437bdd9ed..a5ef2fc4f 100644 --- a/Tests/Functional/app/config/routing.yml +++ b/Tests/Functional/app/config/routing.yml @@ -1,2 +1,6 @@ +--- + _liip_imagine: resource: "@LiipImagineBundle/Resources/config/routing.xml" + +... diff --git a/Tests/Imagine/Cache/CacheManagerTest.php b/Tests/Imagine/Cache/CacheManagerTest.php index d81780494..0e44aadd5 100644 --- a/Tests/Imagine/Cache/CacheManagerTest.php +++ b/Tests/Imagine/Cache/CacheManagerTest.php @@ -13,6 +13,7 @@ use Liip\ImagineBundle\Events\CacheResolveEvent; use Liip\ImagineBundle\Imagine\Cache\CacheManager; +use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; use Liip\ImagineBundle\Imagine\Cache\Signer; use Liip\ImagineBundle\ImagineEvents; use Liip\ImagineBundle\Model\Binary; @@ -20,26 +21,37 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** - * @covers Liip\ImagineBundle\Imagine\Cache\CacheManager + * @covers \Liip\ImagineBundle\Imagine\Cache\CacheManager */ class CacheManagerTest extends AbstractTest { - protected $resolver; + /** + * @return \PHPUnit_Framework_MockObject_MockObject|ResolverInterface + */ + private function createCacheManagerAwareResolverMock() + { + return $resolver = $this + ->getMockBuilder('\Liip\ImagineBundle\Tests\Fixtures\CacheManagerAwareResolver') + ->getMock(); + } public function testAddCacheManagerAwareResolver() { - $cacheManager = new CacheManager($this->createFilterConfigurationMock(), $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($this->createFilterConfigurationMock(), $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); - $resolver = $this->getMock('Liip\ImagineBundle\Tests\Fixtures\CacheManagerAwareResolver'); + $resolver = $this->createCacheManagerAwareResolverMock(); $resolver ->expects($this->once()) ->method('setCacheManager') - ->with($cacheManager) - ; + ->with($cacheManager); $cacheManager->addResolver('thumbnail', $resolver); } + /** + * @expectedException \OutOfBoundsException + * @expectedExceptionMessage Could not find resolver "default" for "thumbnail" filter type + */ public function testGetBrowserPathWithoutResolver() { $config = $this->createFilterConfigurationMock(); @@ -51,19 +63,16 @@ public function testGetBrowserPathWithoutResolver() 'size' => array(180, 180), 'mode' => 'outbound', 'cache' => null, - ))) - ; - - $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + ))); - $this->setExpectedException('OutOfBoundsException', 'Could not find resolver "default" for "thumbnail" filter type'); + $cacheManager = new CacheManager($config, $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->getBrowserPath('cats.jpeg', 'thumbnail'); } public function testGetRuntimePath() { $config = $this->createFilterConfigurationMock(); - $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $rcPath = $cacheManager->getRuntimePath('image.jpg', array( 'thumbnail' => array( @@ -76,19 +85,17 @@ public function testGetRuntimePath() public function testDefaultResolverUsedIfNoneSetOnGetBrowserPath() { - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('isStored') ->with('cats.jpeg', 'thumbnail') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $resolver ->expects($this->once()) ->method('resolve') ->with('cats.jpeg', 'thumbnail') - ->will($this->returnValue('http://a/path/to/an/image.png')) - ; + ->will($this->returnValue('http://a/path/to/an/image.png')); $config = $this->createFilterConfigurationMock(); $config @@ -99,16 +106,14 @@ public function testDefaultResolverUsedIfNoneSetOnGetBrowserPath() 'size' => array(180, 180), 'mode' => 'outbound', 'cache' => null, - ))) - ; + ))); - $router = $this->createRouterMock(); + $router = $this->createRouterInterfaceMock(); $router ->expects($this->never()) - ->method('generate') - ; + ->method('generate'); - $cacheManager = new CacheManager($config, $router, new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $router, new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver('default', $resolver); $actualBrowserPath = $cacheManager->getBrowserPath('cats.jpeg', 'thumbnail'); @@ -118,17 +123,15 @@ public function testDefaultResolverUsedIfNoneSetOnGetBrowserPath() public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBrowserPath() { - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('isStored') ->with('cats.jpeg', 'thumbnail') - ->will($this->returnValue(false)) - ; + ->will($this->returnValue(false)); $resolver ->expects($this->never()) - ->method('resolve') - ; + ->method('resolve'); $config = $this->createFilterConfigurationMock(); $config @@ -139,17 +142,15 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr 'size' => array(180, 180), 'mode' => 'outbound', 'cache' => null, - ))) - ; + ))); - $router = $this->createRouterMock(); + $router = $this->createRouterInterfaceMock(); $router ->expects($this->once()) ->method('generate') - ->will($this->returnValue('/media/cache/thumbnail/cats.jpeg')) - ; + ->will($this->returnValue('/media/cache/thumbnail/cats.jpeg')); - $cacheManager = new CacheManager($config, $router, new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $router, new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver('default', $resolver); $actualBrowserPath = $cacheManager->getBrowserPath('cats.jpeg', 'thumbnail'); @@ -165,17 +166,15 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr ), ); - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('isStored') ->with('rc/VhOzTGRB/cats.jpeg', 'thumbnail') - ->will($this->returnValue(false)) - ; + ->will($this->returnValue(false)); $resolver ->expects($this->never()) - ->method('resolve') - ; + ->method('resolve'); $config = $this->createFilterConfigurationMock(); $config @@ -186,17 +185,15 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr 'size' => array(180, 180), 'mode' => 'outbound', 'cache' => null, - ))) - ; + ))); - $router = $this->createRouterMock(); + $router = $this->createRouterInterfaceMock(); $router ->expects($this->once()) ->method('generate') - ->will($this->returnValue('/media/cache/thumbnail/rc/VhOzTGRB/cats.jpeg')) - ; + ->will($this->returnValue('/media/cache/thumbnail/rc/VhOzTGRB/cats.jpeg')); - $cacheManager = new CacheManager($config, $router, new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $router, new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver('default', $resolver); $actualBrowserPath = $cacheManager->getBrowserPath('cats.jpeg', 'thumbnail', $runtimeConfig); @@ -206,30 +203,33 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr /** * @dataProvider invalidPathProvider + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testResolveInvalidPath($path) { $cacheManager = new CacheManager( $this->createFilterConfigurationMock(), - $this->createRouterMock(), + $this->createRouterInterfaceMock(), new Signer('secret'), - $this->createEventDispatcherMock() + $this->createEventDispatcherInterfaceMock() ); - $this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException'); $cacheManager->resolve($path, 'thumbnail'); } + /** + * @expectedException \OutOfBoundsException + * @expectedExceptionMessage Could not find resolver "default" for "thumbnail" filter type + */ public function testThrowsIfConcreteResolverNotExists() { $cacheManager = new CacheManager( $this->createFilterConfigurationMock(), - $this->createRouterMock(), + $this->createRouterInterfaceMock(), new Signer('secret'), - $this->createEventDispatcherMock() + $this->createEventDispatcherInterfaceMock() ); - $this->setExpectedException('OutOfBoundsException', 'Could not find resolver "default" for "thumbnail" filter type'); $this->assertFalse($cacheManager->resolve('cats.jpeg', 'thumbnail')); } @@ -237,24 +237,21 @@ public function testFallbackToDefaultResolver() { $binary = new Binary('aContent', 'image/png', 'png'); - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('resolve') ->with('cats.jpeg', 'thumbnail') - ->will($this->returnValue('/thumbs/cats.jpeg')) - ; + ->will($this->returnValue('/thumbs/cats.jpeg')); $resolver ->expects($this->once()) ->method('store') - ->with($binary, '/thumbs/cats.jpeg', 'thumbnail') - ; + ->with($binary, '/thumbs/cats.jpeg', 'thumbnail'); $resolver ->expects($this->once()) ->method('remove') ->with(array('/thumbs/cats.jpeg'), array('thumbnail')) - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $config = $this->createFilterConfigurationMock(); $config @@ -265,14 +262,13 @@ public function testFallbackToDefaultResolver() 'size' => array(180, 180), 'mode' => 'outbound', 'cache' => null, - ))) - ; + ))); $cacheManager = new CacheManager( $config, - $this->createRouterMock(), + $this->createRouterInterfaceMock(), new Signer('secret'), - $this->createEventDispatcherMock() + $this->createEventDispatcherInterfaceMock() ); $cacheManager->addResolver('default', $resolver); @@ -290,7 +286,7 @@ public function testGenerateUrl() $path = 'thePath'; $expectedUrl = 'theUrl'; - $routerMock = $this->createRouterMock(); + $routerMock = $this->createRouterInterfaceMock(); $routerMock ->expects($this->once()) ->method('generate') @@ -302,14 +298,13 @@ public function testGenerateUrl() ), UrlGeneratorInterface::ABSOLUTE_URL ) - ->will($this->returnValue($expectedUrl)) - ; + ->will($this->returnValue($expectedUrl)); $cacheManager = new CacheManager( $this->createFilterConfigurationMock(), $routerMock, new Signer('secret'), - $this->createEventDispatcherMock() + $this->createEventDispatcherInterfaceMock() ); $this->assertEquals( @@ -323,12 +318,11 @@ public function testRemoveCacheForPathAndFilterOnRemove() $expectedPath = 'thePath'; $expectedFilter = 'theFilter'; - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('remove') - ->with(array($expectedPath), array($expectedFilter)) - ; + ->with(array($expectedPath), array($expectedFilter)); $config = $this->createFilterConfigurationMock(); $config @@ -338,12 +332,10 @@ public function testRemoveCacheForPathAndFilterOnRemove() return array( 'cache' => $filter, ); - })) - ; + })); - $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver($expectedFilter, $resolver); - $cacheManager->remove($expectedPath, $expectedFilter); } @@ -353,19 +345,17 @@ public function testRemoveCacheForPathAndSomeFiltersOnRemove() $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $resolverOne = $this->createResolverMock(); + $resolverOne = $this->createCacheResolverInterfaceMock(); $resolverOne ->expects($this->once()) ->method('remove') - ->with(array($expectedPath), array($expectedFilterOne)) - ; + ->with(array($expectedPath), array($expectedFilterOne)); - $resolverTwo = $this->createResolverMock(); + $resolverTwo = $this->createCacheResolverInterfaceMock(); $resolverTwo ->expects($this->once()) ->method('remove') - ->with(array($expectedPath), array($expectedFilterTwo)) - ; + ->with(array($expectedPath), array($expectedFilterTwo)); $config = $this->createFilterConfigurationMock(); $config @@ -375,13 +365,11 @@ public function testRemoveCacheForPathAndSomeFiltersOnRemove() return array( 'cache' => $filter, ); - })) - ; + })); - $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver($expectedFilterOne, $resolverOne); $cacheManager->addResolver($expectedFilterTwo, $resolverTwo); - $cacheManager->remove($expectedPath, array($expectedFilterOne, $expectedFilterTwo)); } @@ -391,15 +379,14 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove() $expectedPathTwo = 'thePathTwo'; $expectedFilter = 'theFilter'; - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('remove') ->with( array($expectedPathOne, $expectedPathTwo), array($expectedFilter) - ) - ; + ); $config = $this->createFilterConfigurationMock(); $config @@ -409,12 +396,10 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove() return array( 'cache' => $filter, ); - })) - ; + })); - $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver($expectedFilter, $resolver); - $cacheManager->remove(array($expectedPathOne, $expectedPathTwo), $expectedFilter); } @@ -425,19 +410,17 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $resolverOne = $this->createResolverMock(); + $resolverOne = $this->createCacheResolverInterfaceMock(); $resolverOne ->expects($this->once()) ->method('remove') - ->with(array($expectedPathOne, $expectedPathTwo), array($expectedFilterOne)) - ; + ->with(array($expectedPathOne, $expectedPathTwo), array($expectedFilterOne)); - $resolverTwo = $this->createResolverMock(); + $resolverTwo = $this->createCacheResolverInterfaceMock(); $resolverTwo ->expects($this->once()) ->method('remove') - ->with(array($expectedPathOne, $expectedPathTwo), array($expectedFilterTwo)) - ; + ->with(array($expectedPathOne, $expectedPathTwo), array($expectedFilterTwo)); $config = $this->createFilterConfigurationMock(); $config @@ -447,13 +430,11 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() return array( 'cache' => $filter, ); - })) - ; + })); - $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver($expectedFilterOne, $resolverOne); $cacheManager->addResolver($expectedFilterTwo, $resolverTwo); - $cacheManager->remove( array($expectedPathOne, $expectedPathTwo), array($expectedFilterOne, $expectedFilterTwo) @@ -465,19 +446,17 @@ public function testRemoveCacheForAllFiltersOnRemove() $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $resolverOne = $this->createResolverMock(); + $resolverOne = $this->createCacheResolverInterfaceMock(); $resolverOne ->expects($this->once()) ->method('remove') - ->with(array(), array($expectedFilterOne)) - ; + ->with(array(), array($expectedFilterOne)); - $resolverTwo = $this->createResolverMock(); + $resolverTwo = $this->createCacheResolverInterfaceMock(); $resolverTwo ->expects($this->once()) ->method('remove') - ->with(array(), array($expectedFilterTwo)) - ; + ->with(array(), array($expectedFilterTwo)); $config = $this->createFilterConfigurationMock(); $config @@ -487,21 +466,18 @@ public function testRemoveCacheForAllFiltersOnRemove() return array( 'cache' => $filter, ); - })) - ; + })); $config ->expects($this->once()) ->method('all') ->will($this->returnValue(array( $expectedFilterOne => array(), $expectedFilterTwo => array(), - ))) - ; + ))); - $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver($expectedFilterOne, $resolverOne); $cacheManager->addResolver($expectedFilterTwo, $resolverTwo); - $cacheManager->remove(); } @@ -511,19 +487,17 @@ public function testRemoveCacheForPathAndAllFiltersOnRemove() $expectedFilterTwo = 'theFilterTwo'; $expectedPath = 'thePath'; - $resolverOne = $this->createResolverMock(); + $resolverOne = $this->createCacheResolverInterfaceMock(); $resolverOne ->expects($this->once()) ->method('remove') - ->with(array($expectedPath), array($expectedFilterOne)) - ; + ->with(array($expectedPath), array($expectedFilterOne)); - $resolverTwo = $this->createResolverMock(); + $resolverTwo = $this->createCacheResolverInterfaceMock(); $resolverTwo ->expects($this->once()) ->method('remove') - ->with(array($expectedPath), array($expectedFilterTwo)) - ; + ->with(array($expectedPath), array($expectedFilterTwo)); $config = $this->createFilterConfigurationMock(); $config @@ -533,21 +507,18 @@ public function testRemoveCacheForPathAndAllFiltersOnRemove() return array( 'cache' => $filter, ); - })) - ; + })); $config ->expects($this->once()) ->method('all') ->will($this->returnValue(array( $expectedFilterOne => array(), $expectedFilterTwo => array(), - ))) - ; + ))); - $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver($expectedFilterOne, $resolverOne); $cacheManager->addResolver($expectedFilterTwo, $resolverTwo); - $cacheManager->remove($expectedPath); } @@ -556,12 +527,11 @@ public function testAggregateFiltersByResolverOnRemove() $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('remove') - ->with(array(), array($expectedFilterOne, $expectedFilterTwo)) - ; + ->with(array(), array($expectedFilterOne, $expectedFilterTwo)); $config = $this->createFilterConfigurationMock(); $config @@ -571,173 +541,163 @@ public function testAggregateFiltersByResolverOnRemove() return array( 'cache' => $filter, ); - })) - ; + })); - $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); + $cacheManager = new CacheManager($config, $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); $cacheManager->addResolver($expectedFilterOne, $resolver); $cacheManager->addResolver($expectedFilterTwo, $resolver); - $cacheManager->remove(null, array($expectedFilterOne, $expectedFilterTwo)); } public function testShouldDispatchCachePreResolveEvent() { - $dispatcher = $this->createEventDispatcherMock(); + $dispatcher = $this->createEventDispatcherInterfaceMock(); $dispatcher ->expects($this->at(0)) ->method('dispatch') - ->with(ImagineEvents::PRE_RESOLVE, new CacheResolveEvent('cats.jpg', 'thumbnail')) - ; + ->with(ImagineEvents::PRE_RESOLVE, new CacheResolveEvent('cats.jpg', 'thumbnail')); $cacheManager = new CacheManager( $this->createFilterConfigurationMock(), - $this->createRouterMock(), + $this->createRouterInterfaceMock(), new Signer('secret'), $dispatcher ); - $cacheManager->addResolver('default', $this->createResolverMock()); + $cacheManager->addResolver('default', $this->createCacheResolverInterfaceMock()); $cacheManager->resolve('cats.jpg', 'thumbnail'); } public function testShouldDispatchCachePostResolveEvent() { - $dispatcher = $this->createEventDispatcherMock(); + $dispatcher = $this->createEventDispatcherInterfaceMock(); $dispatcher ->expects($this->at(1)) ->method('dispatch') - ->with(ImagineEvents::POST_RESOLVE, new CacheResolveEvent('cats.jpg', 'thumbnail')) - ; + ->with(ImagineEvents::POST_RESOLVE, new CacheResolveEvent('cats.jpg', 'thumbnail')); $cacheManager = new CacheManager( $this->createFilterConfigurationMock(), - $this->createRouterMock(), + $this->createRouterInterfaceMock(), new Signer('secret'), $dispatcher ); - $cacheManager->addResolver('default', $this->createResolverMock()); + $cacheManager->addResolver('default', $this->createCacheResolverInterfaceMock()); $cacheManager->resolve('cats.jpg', 'thumbnail'); } public function testShouldAllowToPassChangedDataFromPreResolveEventToResolver() { - $dispatcher = $this->createEventDispatcherMock(); + $dispatcher = $this->createEventDispatcherInterfaceMock(); $dispatcher ->expects($this->at(0)) ->method('dispatch') - ->with(ImagineEvents::PRE_RESOLVE, $this->isInstanceOf('Liip\ImagineBundle\Events\CacheResolveEvent')) + ->with(ImagineEvents::PRE_RESOLVE, $this->isInstanceOf('\Liip\ImagineBundle\Events\CacheResolveEvent')) ->will($this->returnCallback(function ($name, $event) { $event->setPath('changed_path'); $event->setFilter('changed_filter'); - })) - ; + })); - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('resolve') - ->with('changed_path', 'changed_filter') - ; + ->with('changed_path', 'changed_filter'); $cacheManager = new CacheManager( $this->createFilterConfigurationMock(), - $this->createRouterMock(), + $this->createRouterInterfaceMock(), new Signer('secret'), $dispatcher ); - $cacheManager->addResolver('default', $resolver); + $cacheManager->addResolver('default', $resolver); $cacheManager->resolve('cats.jpg', 'thumbnail'); } public function testShouldAllowToGetResolverByFilterChangedInPreResolveEvent() { - $dispatcher = $this->createEventDispatcherMock(); + $dispatcher = $this->createEventDispatcherInterfaceMock(); $dispatcher ->expects($this->at(0)) ->method('dispatch') ->will($this->returnCallback(function ($name, $event) { $event->setFilter('thumbnail'); - })) - ; - - $cacheManager = $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array('getResolver'), array( - $this->createFilterConfigurationMock(), - $this->createRouterMock(), - new Signer('secret'), - $dispatcher, - )); + })); + + $cacheManager = $this + ->getMockBuilder('\Liip\ImagineBundle\Imagine\Cache\CacheManager') + ->setMethods(array('getResolver')) + ->setConstructorArgs(array( + $this->createFilterConfigurationMock(), + $this->createRouterInterfaceMock(), + new Signer('secret'), + $dispatcher, + ))->getMock(); $cacheManager ->expects($this->once()) ->method('getResolver') ->with('thumbnail') - ->will($this->returnValue($this->createResolverMock())) - ; + ->will($this->returnValue($this->createCacheResolverInterfaceMock())); $cacheManager->resolve('cats.jpg', 'default'); } public function testShouldAllowToPassChangedDataFromPreResolveEventToPostResolveEvent() { - $dispatcher = $this->createEventDispatcherMock(); + $dispatcher = $this->createEventDispatcherInterfaceMock(); $dispatcher ->expects($this->at(0)) ->method('dispatch') - ->with(ImagineEvents::PRE_RESOLVE, $this->isInstanceOf('Liip\ImagineBundle\Events\CacheResolveEvent')) + ->with(ImagineEvents::PRE_RESOLVE, $this->isInstanceOf('\Liip\ImagineBundle\Events\CacheResolveEvent')) ->will($this->returnCallback(function ($name, $event) { $event->setPath('changed_path'); $event->setFilter('changed_filter'); })) ; - $dispatcher ->expects($this->at(1)) ->method('dispatch') ->with( ImagineEvents::POST_RESOLVE, $this->logicalAnd( - $this->isInstanceOf('Liip\ImagineBundle\Events\CacheResolveEvent'), + $this->isInstanceOf('\Liip\ImagineBundle\Events\CacheResolveEvent'), $this->attributeEqualTo('path', 'changed_path'), $this->attributeEqualTo('filter', 'changed_filter') - )) - ; + )); $cacheManager = new CacheManager( $this->createFilterConfigurationMock(), - $this->createRouterMock(), + $this->createRouterInterfaceMock(), new Signer('secret'), $dispatcher ); - $cacheManager->addResolver('default', $this->createResolverMock()); + $cacheManager->addResolver('default', $this->createCacheResolverInterfaceMock()); $cacheManager->resolve('cats.jpg', 'thumbnail'); } public function testShouldReturnUrlChangedInPostResolveEvent() { - $dispatcher = $this->createEventDispatcherMock(); + $dispatcher = $this->createEventDispatcherInterfaceMock(); $dispatcher ->expects($this->at(1)) ->method('dispatch') - ->with(ImagineEvents::POST_RESOLVE, $this->isInstanceOf('Liip\ImagineBundle\Events\CacheResolveEvent')) + ->with(ImagineEvents::POST_RESOLVE, $this->isInstanceOf('\Liip\ImagineBundle\Events\CacheResolveEvent')) ->will($this->returnCallback(function ($name, $event) { $event->setUrl('changed_url'); - })) - ; + })); $cacheManager = new CacheManager( $this->createFilterConfigurationMock(), - $this->createRouterMock(), + $this->createRouterInterfaceMock(), new Signer('secret'), $dispatcher ); - $cacheManager->addResolver('default', $this->createResolverMock()); - - $url = $cacheManager->resolve('cats.jpg', 'thumbnail'); + $cacheManager->addResolver('default', $this->createCacheResolverInterfaceMock()); - $this->assertEquals('changed_url', $url); + $this->assertEquals('changed_url', $cacheManager->resolve('cats.jpg', 'thumbnail')); } } diff --git a/Tests/Imagine/Cache/Resolver/AmazonS3ResolverTest.php b/Tests/Imagine/Cache/Resolver/AmazonS3ResolverTest.php index f71b69d2b..88695fc09 100644 --- a/Tests/Imagine/Cache/Resolver/AmazonS3ResolverTest.php +++ b/Tests/Imagine/Cache/Resolver/AmazonS3ResolverTest.php @@ -16,15 +16,15 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver + * @covers \Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver */ class AmazonS3ResolverTest extends AbstractTest { public function testImplementsResolverInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')); } public function testNoDoubleSlashesInObjectUrlOnResolve() @@ -33,8 +33,7 @@ public function testNoDoubleSlashesInObjectUrlOnResolve() $s3 ->expects($this->once()) ->method('get_object_url') - ->with('images.example.com', 'thumb/some-folder/path.jpg') - ; + ->with('images.example.com', 'thumb/some-folder/path.jpg'); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); $resolver->resolve('/some-folder/path.jpg', 'thumb'); @@ -46,14 +45,17 @@ public function testObjUrlOptionsPassedToAmazonOnResolve() $s3 ->expects($this->once()) ->method('get_object_url') - ->with('images.example.com', 'thumb/some-folder/path.jpg', 0, array('torrent' => true)) - ; + ->with('images.example.com', 'thumb/some-folder/path.jpg', 0, array('torrent' => true)); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); $resolver->setObjectUrlOption('torrent', true); $resolver->resolve('/some-folder/path.jpg', 'thumb'); } + /** + * @expectedException \Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException + * @expectedExceptionMessage The object could not be created on Amazon S3 + */ public function testThrowsAndLogIfCanNotCreateObjectOnAmazon() { $binary = new Binary('aContent', 'image/jpeg', 'jpeg'); @@ -62,22 +64,15 @@ public function testThrowsAndLogIfCanNotCreateObjectOnAmazon() $s3 ->expects($this->once()) ->method('create_object') - ->will($this->returnValue($this->createCFResponseMock(false))) - ; + ->will($this->returnValue($this->createCFResponseMock(false))); - $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger = $this->createLoggerInterfaceMock(); $logger ->expects($this->once()) - ->method('error') - ; + ->method('error'); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); $resolver->setLogger($logger); - - $this->setExpectedException( - 'Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException', - 'The object could not be created on Amazon S3.' - ); $resolver->store($binary, 'foobar.jpg', 'thumb'); } @@ -89,11 +84,9 @@ public function testCreatedObjectOnAmazon() $s3 ->expects($this->once()) ->method('create_object') - ->will($this->returnValue($this->createCFResponseMock(true))) - ; + ->will($this->returnValue($this->createCFResponseMock(true))); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); - $resolver->store($binary, 'foobar.jpg', 'thumb'); } @@ -103,8 +96,7 @@ public function testIsStoredChecksObjectExistence() $s3 ->expects($this->once()) ->method('if_object_exists') - ->will($this->returnValue(false)) - ; + ->will($this->returnValue(false)); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); @@ -118,8 +110,7 @@ public function testReturnResolvedImageUrlOnResolve() ->expects($this->once()) ->method('get_object_url') ->with('images.example.com', 'thumb/some-folder/path.jpg', 0, array()) - ->will($this->returnValue('http://images.example.com/some-folder/path.jpg')) - ; + ->will($this->returnValue('http://images.example.com/some-folder/path.jpg')); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); @@ -134,19 +125,15 @@ public function testDoNothingIfFiltersAndPathsEmptyOnRemove() $s3 = $this->createAmazonS3Mock(); $s3 ->expects($this->never()) - ->method('if_object_exists') - ; + ->method('if_object_exists'); $s3 ->expects($this->never()) - ->method('delete_object') - ; + ->method('delete_object'); $s3 ->expects($this->never()) - ->method('delete_all_objects') - ; + ->method('delete_all_objects'); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); - $resolver->remove(array(), array()); } @@ -157,17 +144,14 @@ public function testRemoveCacheForPathAndFilterOnRemove() ->expects($this->once()) ->method('if_object_exists') ->with('images.example.com', 'thumb/some-folder/path.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->once()) ->method('delete_object') ->with('images.example.com', 'thumb/some-folder/path.jpg') - ->will($this->returnValue($this->createCFResponseMock(true))) - ; + ->will($this->returnValue($this->createCFResponseMock(true))); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); - $resolver->remove(array('some-folder/path.jpg'), array('thumb')); } @@ -178,29 +162,24 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove() ->expects($this->at(0)) ->method('if_object_exists') ->with('images.example.com', 'filter/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(1)) ->method('delete_object') ->with('images.example.com', 'filter/pathOne.jpg') - ->will($this->returnValue($this->createCFResponseMock(true))) - ; + ->will($this->returnValue($this->createCFResponseMock(true))); $s3 ->expects($this->at(2)) ->method('if_object_exists') ->with('images.example.com', 'filter/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(3)) ->method('delete_object') ->with('images.example.com', 'filter/pathTwo.jpg') - ->will($this->returnValue($this->createCFResponseMock(true))) - ; + ->will($this->returnValue($this->createCFResponseMock(true))); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); - $resolver->remove(array('pathOne.jpg', 'pathTwo.jpg'), array('filter')); } @@ -211,53 +190,44 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() ->expects($this->at(0)) ->method('if_object_exists') ->with('images.example.com', 'filterOne/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(1)) ->method('delete_object') ->with('images.example.com', 'filterOne/pathOne.jpg') - ->will($this->returnValue($this->createCFResponseMock(true))) - ; + ->will($this->returnValue($this->createCFResponseMock(true))); $s3 ->expects($this->at(2)) ->method('if_object_exists') ->with('images.example.com', 'filterOne/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(3)) ->method('delete_object') ->with('images.example.com', 'filterOne/pathTwo.jpg') - ->will($this->returnValue($this->createCFResponseMock(true))) - ; + ->will($this->returnValue($this->createCFResponseMock(true))); $s3 ->expects($this->at(4)) ->method('if_object_exists') ->with('images.example.com', 'filterTwo/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(5)) ->method('delete_object') ->with('images.example.com', 'filterTwo/pathOne.jpg') - ->will($this->returnValue($this->createCFResponseMock(true))) - ; + ->will($this->returnValue($this->createCFResponseMock(true))); $s3 ->expects($this->at(6)) ->method('if_object_exists') ->with('images.example.com', 'filterTwo/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(7)) ->method('delete_object') ->with('images.example.com', 'filterTwo/pathTwo.jpg') - ->will($this->returnValue($this->createCFResponseMock(true))) - ; + ->will($this->returnValue($this->createCFResponseMock(true))); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); - $resolver->remove( array('pathOne.jpg', 'pathTwo.jpg'), array('filterOne', 'filterTwo') @@ -271,15 +241,12 @@ public function testDoNothingWhenObjectNotExistForPathAndFilterOnRemove() ->expects($this->once()) ->method('if_object_exists') ->with('images.example.com', 'filter/path.jpg') - ->will($this->returnValue(false)) - ; + ->will($this->returnValue(false)); $s3 ->expects($this->never()) - ->method('delete_object') - ; + ->method('delete_object'); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); - $resolver->remove(array('path.jpg'), array('filter')); } @@ -290,23 +257,19 @@ public function testLogIfNotDeletedForPathAndFilterOnRemove() ->expects($this->once()) ->method('if_object_exists') ->with('images.example.com', 'filter/path.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->once()) ->method('delete_object') - ->will($this->returnValue($this->createCFResponseMock(false))) - ; + ->will($this->returnValue($this->createCFResponseMock(false))); - $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger = $this->createLoggerInterfaceMock(); $logger ->expects($this->once()) - ->method('error') - ; + ->method('error'); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); $resolver->setLogger($logger); - $resolver->remove(array('path.jpg'), array('filter')); } @@ -317,11 +280,9 @@ public function testRemoveCacheForFilterOnRemove() ->expects($this->once()) ->method('delete_all_objects') ->with('images.example.com', '/filter/i') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); - $resolver->remove(array(), array('filter')); } @@ -332,11 +293,9 @@ public function testRemoveCacheForSomeFiltersOnRemove() ->expects($this->once()) ->method('delete_all_objects') ->with('images.example.com', '/filterOne|filterTwo/i') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); - $resolver->remove(array(), array('filterOne', 'filterTwo')); } @@ -347,18 +306,15 @@ public function testLogIfBatchNotDeletedForFilterOnRemove() ->expects($this->once()) ->method('delete_all_objects') ->with('images.example.com', '/filter/i') - ->will($this->returnValue(false)) - ; + ->will($this->returnValue(false)); - $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger = $this->createLoggerInterfaceMock(); $logger ->expects($this->once()) - ->method('error') - ; + ->method('error'); $resolver = new AmazonS3Resolver($s3, 'images.example.com'); $resolver->setLogger($logger); - $resolver->remove(array(), array('filter')); } @@ -369,12 +325,11 @@ public function testLogIfBatchNotDeletedForFilterOnRemove() */ protected function createCFResponseMock($ok = true) { - $s3Response = $this->getMock('CFResponse', array('isOK'), array(), '', false); + $s3Response = $this->createObjectMock('CFResponse', array('isOK'), false); $s3Response ->expects($this->once()) ->method('isOK') - ->will($this->returnValue($ok)) - ; + ->will($this->returnValue($ok)); return $s3Response; } @@ -384,15 +339,17 @@ protected function createCFResponseMock($ok = true) */ protected function createAmazonS3Mock() { - $mockedMethods = array( - 'if_object_exists', - 'create_object', - 'get_object_url', - 'delete_object', - 'delete_all_objects', - 'authenticate', - ); - - return $this->getMock('AmazonS3', $mockedMethods, array(), '', false); + return $this + ->getMockBuilder('AmazonS3') + ->disableOriginalConstructor() + ->setMethods(array( + 'if_object_exists', + 'create_object', + 'get_object_url', + 'delete_object', + 'delete_all_objects', + 'authenticate', + )) + ->getMock(); } } diff --git a/Tests/Imagine/Cache/Resolver/AwsS3ResolverTest.php b/Tests/Imagine/Cache/Resolver/AwsS3ResolverTest.php index d3ae52f96..17749715e 100644 --- a/Tests/Imagine/Cache/Resolver/AwsS3ResolverTest.php +++ b/Tests/Imagine/Cache/Resolver/AwsS3ResolverTest.php @@ -11,20 +11,21 @@ namespace Liip\ImagineBundle\Tests\Imagine\Cache\Resolver; +use Guzzle\Service\Resource\Model; use Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver + * @covers \Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver */ class AwsS3ResolverTest extends AbstractTest { public function testImplementsResolverInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')); } public function testNoDoubleSlashesInObjectUrlOnResolve() @@ -33,8 +34,7 @@ public function testNoDoubleSlashesInObjectUrlOnResolve() $s3 ->expects($this->once()) ->method('getObjectUrl') - ->with('images.example.com', 'thumb/some-folder/path.jpg') - ; + ->with('images.example.com', 'thumb/some-folder/path.jpg'); $resolver = new AwsS3Resolver($s3, 'images.example.com'); $resolver->resolve('/some-folder/path.jpg', 'thumb'); @@ -46,14 +46,17 @@ public function testObjUrlOptionsPassedToS3ClintOnResolve() $s3 ->expects($this->once()) ->method('getObjectUrl') - ->with('images.example.com', 'thumb/some-folder/path.jpg', 0, array('torrent' => true)) - ; + ->with('images.example.com', 'thumb/some-folder/path.jpg', 0, array('torrent' => true)); $resolver = new AwsS3Resolver($s3, 'images.example.com'); - $resolver->setObjectUrlOption('torrent', true); + $resolver->setGetOption('torrent', true); $resolver->resolve('/some-folder/path.jpg', 'thumb'); } + /** + * @expectedException \Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException + * @expectedExceptionMessage The object could not be created on Amazon S3 + */ public function testLogNotCreatedObjects() { $binary = new Binary('aContent', 'image/jpeg', 'jpeg'); @@ -62,22 +65,15 @@ public function testLogNotCreatedObjects() $s3 ->expects($this->once()) ->method('putObject') - ->will($this->throwException(new \Exception('Put object on amazon failed'))) - ; + ->will($this->throwException(new \Exception('Put object on amazon failed'))); - $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger = $this->createLoggerInterfaceMock(); $logger ->expects($this->once()) - ->method('error') - ; + ->method('error'); $resolver = new AwsS3Resolver($s3, 'images.example.com'); $resolver->setLogger($logger); - - $this->setExpectedException( - 'Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException', - 'The object could not be created on Amazon S3.' - ); $resolver->store($binary, 'foobar.jpg', 'thumb'); } @@ -89,12 +85,10 @@ public function testCreateObjectOnAmazon() $s3 ->expects($this->once()) ->method('putObject') - ->will($this->returnValue($this->getS3ResponseMock())) - ; + ->will($this->returnValue($this->getS3ResponseMock())); $resolver = new AwsS3Resolver($s3, 'images.example.com'); - - $this->assertNull($resolver->store($binary, 'thumb/foobar.jpg', 'thumb')); + $resolver->store($binary, 'thumb/foobar.jpg', 'thumb'); } public function testObjectOptionsPassedToS3ClintOnCreate() @@ -112,8 +106,7 @@ public function testObjectOptionsPassedToS3ClintOnCreate() 'Key' => 'filter/images/foobar.jpg', 'Body' => 'aContent', 'ContentType' => 'image/jpeg', - )) - ; + )); $resolver = new AwsS3Resolver($s3, 'images.example.com'); $resolver->setPutOption('CacheControl', 'max-age=86400'); @@ -126,8 +119,7 @@ public function testIsStoredChecksObjectExistence() $s3 ->expects($this->once()) ->method('doesObjectExist') - ->will($this->returnValue(false)) - ; + ->will($this->returnValue(false)); $resolver = new AwsS3Resolver($s3, 'images.example.com'); @@ -141,8 +133,7 @@ public function testReturnResolvedImageUrlOnResolve() ->expects($this->once()) ->method('getObjectUrl') ->with('images.example.com', 'thumb/some-folder/path.jpg', 0, array()) - ->will($this->returnValue('http://images.example.com/some-folder/path.jpg')) - ; + ->will($this->returnValue('http://images.example.com/some-folder/path.jpg')); $resolver = new AwsS3Resolver($s3, 'images.example.com'); @@ -157,19 +148,15 @@ public function testDoNothingIfFiltersAndPathsEmptyOnRemove() $s3 = $this->getS3ClientMock(); $s3 ->expects($this->never()) - ->method('doesObjectExist') - ; + ->method('doesObjectExist'); $s3 ->expects($this->never()) - ->method('deleteObject') - ; + ->method('deleteObject'); $s3 ->expects($this->never()) - ->method('deleteMatchingObjects') - ; + ->method('deleteMatchingObjects'); $resolver = new AwsS3Resolver($s3, 'images.example.com'); - $resolver->remove(array(), array()); } @@ -180,8 +167,7 @@ public function testRemoveCacheForPathAndFilterOnRemove() ->expects($this->once()) ->method('doesObjectExist') ->with('images.example.com', 'thumb/some-folder/path.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->once()) ->method('deleteObject') @@ -189,11 +175,9 @@ public function testRemoveCacheForPathAndFilterOnRemove() 'Bucket' => 'images.example.com', 'Key' => 'thumb/some-folder/path.jpg', )) - ->will($this->returnValue($this->getS3ResponseMock(true))) - ; + ->will($this->returnValue($this->getS3ResponseMock())); $resolver = new AwsS3Resolver($s3, 'images.example.com'); - $resolver->remove(array('some-folder/path.jpg'), array('thumb')); } @@ -204,8 +188,7 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove() ->expects($this->at(0)) ->method('doesObjectExist') ->with('images.example.com', 'thumb/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(1)) ->method('deleteObject') @@ -213,14 +196,12 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove() 'Bucket' => 'images.example.com', 'Key' => 'thumb/pathOne.jpg', )) - ->will($this->returnValue($this->getS3ResponseMock(true))) - ; + ->will($this->returnValue($this->getS3ResponseMock())); $s3 ->expects($this->at(2)) ->method('doesObjectExist') ->with('images.example.com', 'thumb/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(3)) ->method('deleteObject') @@ -228,11 +209,9 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove() 'Bucket' => 'images.example.com', 'Key' => 'thumb/pathTwo.jpg', )) - ->will($this->returnValue($this->getS3ResponseMock(true))) - ; + ->will($this->returnValue($this->getS3ResponseMock())); $resolver = new AwsS3Resolver($s3, 'images.example.com'); - $resolver->remove( array('pathOne.jpg', 'pathTwo.jpg'), array('thumb') @@ -246,8 +225,7 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() ->expects($this->at(0)) ->method('doesObjectExist') ->with('images.example.com', 'filterOne/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(1)) ->method('deleteObject') @@ -255,14 +233,12 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() 'Bucket' => 'images.example.com', 'Key' => 'filterOne/pathOne.jpg', )) - ->will($this->returnValue($this->getS3ResponseMock(true))) - ; + ->will($this->returnValue($this->getS3ResponseMock())); $s3 ->expects($this->at(2)) ->method('doesObjectExist') ->with('images.example.com', 'filterOne/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(3)) ->method('deleteObject') @@ -270,14 +246,12 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() 'Bucket' => 'images.example.com', 'Key' => 'filterOne/pathTwo.jpg', )) - ->will($this->returnValue($this->getS3ResponseMock(true))) - ; + ->will($this->returnValue($this->getS3ResponseMock())); $s3 ->expects($this->at(4)) ->method('doesObjectExist') ->with('images.example.com', 'filterTwo/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(5)) ->method('deleteObject') @@ -285,14 +259,12 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() 'Bucket' => 'images.example.com', 'Key' => 'filterTwo/pathOne.jpg', )) - ->will($this->returnValue($this->getS3ResponseMock(true))) - ; + ->will($this->returnValue($this->getS3ResponseMock())); $s3 ->expects($this->at(6)) ->method('doesObjectExist') ->with('images.example.com', 'filterTwo/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->at(7)) ->method('deleteObject') @@ -300,11 +272,9 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() 'Bucket' => 'images.example.com', 'Key' => 'filterTwo/pathTwo.jpg', )) - ->will($this->returnValue($this->getS3ResponseMock(true))) - ; + ->will($this->returnValue($this->getS3ResponseMock())); $resolver = new AwsS3Resolver($s3, 'images.example.com'); - $resolver->remove( array('pathOne.jpg', 'pathTwo.jpg'), array('filterOne', 'filterTwo') @@ -318,12 +288,10 @@ public function testDoNothingWhenObjectNotExistForPathAndFilterOnRemove() ->expects($this->once()) ->method('doesObjectExist') ->with('images.example.com', 'thumb/some-folder/path.jpg') - ->will($this->returnValue(false)) - ; + ->will($this->returnValue(false)); $s3 ->expects($this->never()) - ->method('deleteObject') - ; + ->method('deleteObject'); $resolver = new AwsS3Resolver($s3, 'images.example.com'); $resolver->remove(array('some-folder/path.jpg'), array('thumb')); @@ -336,19 +304,16 @@ public function testCatchAndLogExceptionsForPathAndFilterOnRemove() ->expects($this->once()) ->method('doesObjectExist') ->with('images.example.com', 'thumb/some-folder/path.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $s3 ->expects($this->once()) ->method('deleteObject') - ->will($this->throwException(new \Exception())) - ; + ->will($this->throwException(new \Exception())); - $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger = $this->createLoggerInterfaceMock(); $logger ->expects($this->once()) - ->method('error') - ; + ->method('error'); $resolver = new AwsS3Resolver($s3, 'images.example.com'); $resolver->setLogger($logger); @@ -364,11 +329,9 @@ public function testRemoveCacheForFilterOnRemove() $s3 ->expects($this->once()) ->method('deleteMatchingObjects') - ->with($expectedBucket, null, "/$expectedFilter/i") - ; + ->with($expectedBucket, null, "/$expectedFilter/i"); $resolver = new AwsS3Resolver($s3, $expectedBucket); - $resolver->remove(array(), array($expectedFilter)); } @@ -382,11 +345,9 @@ public function testRemoveCacheForSomeFiltersOnRemove() $s3 ->expects($this->once()) ->method('deleteMatchingObjects') - ->with($expectedBucket, null, "/{$expectedFilterOne}|{$expectedFilterTwo}/i") - ; + ->with($expectedBucket, null, "/{$expectedFilterOne}|{$expectedFilterTwo}/i"); $resolver = new AwsS3Resolver($s3, $expectedBucket); - $resolver->remove(array(), array($expectedFilterOne, $expectedFilterTwo)); } @@ -399,26 +360,24 @@ public function testCatchAndLogExceptionForFilterOnRemove() $s3 ->expects($this->once()) ->method('deleteMatchingObjects') - ->will($this->throwException(new \Exception())) - ; + ->will($this->throwException(new \Exception())); - $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger = $this->createLoggerInterfaceMock(); $logger ->expects($this->once()) - ->method('error') - ; + ->method('error'); $resolver = new AwsS3Resolver($s3, $expectedBucket); $resolver->setLogger($logger); - $resolver->remove(array(), array($expectedFilter)); } - protected function getS3ResponseMock($ok = true) + /** + * @return \PHPUnit_Framework_MockObject_MockObject|Model + */ + protected function getS3ResponseMock() { - $s3Response = $this->getMock('Guzzle\Service\Resource\Model'); - - return $s3Response; + return $this->createObjectMock('Guzzle\Service\Resource\Model'); } /** @@ -426,15 +385,16 @@ protected function getS3ResponseMock($ok = true) */ protected function getS3ClientMock() { - $mockedMethods = array( - 'deleteObject', - 'deleteMatchingObjects', - 'createObject', - 'putObject', - 'doesObjectExist', - 'getObjectUrl', - ); - - return $this->getMock('Aws\S3\S3Client', $mockedMethods, array(), '', false); + return $this + ->getMockBuilder('Aws\S3\S3Client') + ->disableOriginalConstructor() + ->setMethods(array( + 'deleteObject', + 'deleteMatchingObjects', + 'createObject', + 'putObject', + 'doesObjectExist', + 'getObjectUrl', + ))->getMock(); } } diff --git a/Tests/Imagine/Cache/Resolver/CacheResolverTest.php b/Tests/Imagine/Cache/Resolver/CacheResolverTest.php index d7b8a05a9..193a3442e 100644 --- a/Tests/Imagine/Cache/Resolver/CacheResolverTest.php +++ b/Tests/Imagine/Cache/Resolver/CacheResolverTest.php @@ -17,7 +17,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\CacheResolver + * @covers \Liip\ImagineBundle\Imagine\Cache\Resolver\CacheResolver */ class CacheResolverTest extends AbstractTest { @@ -27,13 +27,12 @@ class CacheResolverTest extends AbstractTest public function testResolveIsSavedToCache() { - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('resolve') ->with($this->path, $this->filter) - ->will($this->returnValue($this->webPath)) - ; + ->will($this->returnValue($this->webPath)); $cacheResolver = new CacheResolver(new ArrayCache(), $resolver); @@ -46,17 +45,15 @@ public function testResolveIsSavedToCache() public function testNotCallInternalResolverIfCachedOnIsStored() { - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('resolve') ->with($this->path, $this->filter) - ->will($this->returnValue($this->webPath)) - ; + ->will($this->returnValue($this->webPath)); $resolver ->expects($this->never()) - ->method('isStored') - ; + ->method('isStored'); $cacheResolver = new CacheResolver(new ArrayCache(), $resolver); @@ -69,12 +66,11 @@ public function testNotCallInternalResolverIfCachedOnIsStored() public function testCallInternalResolverIfNotCachedOnIsStored() { - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->exactly(2)) ->method('isStored') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $cacheResolver = new CacheResolver(new ArrayCache(), $resolver); @@ -86,12 +82,11 @@ public function testStoreIsForwardedToResolver() { $binary = new Binary('aContent', 'image/jpeg', 'jpg'); - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->exactly(2)) ->method('store') - ->with($this->identicalTo($binary), $this->webPath, $this->filter) - ; + ->with($this->identicalTo($binary), $this->webPath, $this->filter); $cacheResolver = new CacheResolver(new ArrayCache(), $resolver); @@ -102,19 +97,17 @@ public function testStoreIsForwardedToResolver() public function testSavesToCacheIfInternalResolverReturnUrlOnResolve() { - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('resolve') ->with($this->path, $this->filter) - ->will($this->returnValue('/the/expected/browser')) - ; + ->will($this->returnValue('/the/expected/browser')); - $cache = $this->getMock('Doctrine\Common\Cache\Cache'); + $cache = $this->getMockBuilder('\Doctrine\Common\Cache\Cache')->getMock(); $cache ->expects($this->exactly(1)) - ->method('save') - ; + ->method('save'); $cacheResolver = new CacheResolver($cache, $resolver); @@ -123,17 +116,15 @@ public function testSavesToCacheIfInternalResolverReturnUrlOnResolve() public function testRemoveSinglePathCacheOnRemove() { - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->once()) ->method('resolve') ->with($this->path, $this->filter) - ->will($this->returnValue($this->webPath)) - ; + ->will($this->returnValue($this->webPath)); $resolver ->expects($this->once()) - ->method('remove') - ; + ->method('remove'); $cache = new ArrayCache(); @@ -142,8 +133,8 @@ public function testRemoveSinglePathCacheOnRemove() /* * Checking 2 items: - * * The result of one resolve execution. - * * The index of entity. + * - The result of one resolve execution. + * - The index of entity. */ $this->assertCount(2, $this->getCacheEntries($cache)); @@ -155,16 +146,14 @@ public function testRemoveSinglePathCacheOnRemove() public function testRemoveAllFilterCacheOnRemove() { - $resolver = $this->createResolverMock(); + $resolver = $this->createCacheResolverInterfaceMock(); $resolver ->expects($this->exactly(4)) ->method('resolve') - ->will($this->returnValue('aCachePath')) - ; + ->will($this->returnValue('aCachePath')); $resolver ->expects($this->once()) - ->method('remove') - ; + ->method('remove'); $cache = new ArrayCache(); @@ -176,8 +165,8 @@ public function testRemoveAllFilterCacheOnRemove() /* * Checking 6 items: - * * The result of four resolve execution. - * * The index of two entities. + * - The result of four resolve execution. + * - The index of two entities. */ $this->assertCount(6, $this->getCacheEntries($cache)); diff --git a/Tests/Imagine/Cache/Resolver/FlysystemResolverTest.php b/Tests/Imagine/Cache/Resolver/FlysystemResolverTest.php index cfb768bcf..8b9244d72 100644 --- a/Tests/Imagine/Cache/Resolver/FlysystemResolverTest.php +++ b/Tests/Imagine/Cache/Resolver/FlysystemResolverTest.php @@ -18,7 +18,7 @@ use Symfony\Component\Routing\RequestContext; /** - * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\FlysystemResolver + * @covers \Liip\ImagineBundle\Imagine\Cache\Resolver\FlysystemResolver */ class FlysystemResolverTest extends AbstractTest { @@ -35,29 +35,29 @@ public function setUp() public function testImplementsResolverInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Imagine\Cache\Resolver\FlysystemResolver'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\Imagine\Cache\Resolver\FlysystemResolver'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')); } public function testResolveUriForFilter() { - $fs = $this->getFlysystemMock(); + $resolver = new FlysystemResolver($this->createFlySystemMock(), new RequestContext(), 'http://images.example.com'); - $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $uri = $resolver->resolve('/some-folder/path.jpg', 'thumb'); - $this->assertEquals('http://images.example.com/media/cache/thumb/some-folder/path.jpg', $uri); + $this->assertEquals( + 'http://images.example.com/media/cache/thumb/some-folder/path.jpg', + $resolver->resolve('/some-folder/path.jpg', 'thumb') + ); } public function testRemoveObjectsForFilter() { $expectedFilter = 'theFilter'; - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $fs ->expects($this->once()) ->method('deleteDir') - ->with('media/cache/theFilter') - ; + ->with('media/cache/theFilter'); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); $resolver->remove(array(), array($expectedFilter)); @@ -67,12 +67,11 @@ public function testCreateObjectInAdapter() { $binary = new Binary('aContent', 'image/jpeg', 'jpeg'); - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $fs ->expects($this->once()) ->method('put') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); @@ -81,12 +80,11 @@ public function testCreateObjectInAdapter() public function testIsStoredChecksObjectExistence() { - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $fs ->expects($this->once()) ->method('has') - ->will($this->returnValue(false)) - ; + ->will($this->returnValue(false)); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); @@ -95,7 +93,7 @@ public function testIsStoredChecksObjectExistence() public function testReturnResolvedImageUrlOnResolve() { - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); @@ -107,55 +105,47 @@ public function testReturnResolvedImageUrlOnResolve() public function testRemoveCacheForPathAndFilterOnRemove() { - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $fs ->expects($this->once()) ->method('has') ->with('media/cache/thumb/some-folder/path.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->once()) ->method('delete') ->with('media/cache/thumb/some-folder/path.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove(array('some-folder/path.jpg'), array('thumb')); } public function testRemoveCacheForSomePathsAndFilterOnRemove() { - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $fs ->expects($this->at(0)) ->method('has') ->with('media/cache/thumb/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(1)) ->method('delete') ->with('media/cache/thumb/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(2)) ->method('has') ->with('media/cache/thumb/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(3)) ->method('delete') ->with('media/cache/thumb/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove( array('pathOne.jpg', 'pathTwo.jpg'), array('thumb') @@ -164,58 +154,49 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove() public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() { - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $fs ->expects($this->at(0)) ->method('has') ->with('media/cache/filterOne/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(1)) ->method('delete') ->with('media/cache/filterOne/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(2)) ->method('has') ->with('media/cache/filterTwo/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(3)) ->method('delete') ->with('media/cache/filterTwo/pathOne.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(4)) ->method('has') ->with('media/cache/filterOne/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(5)) ->method('delete') ->with('media/cache/filterOne/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(6)) ->method('has') ->with('media/cache/filterTwo/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $fs ->expects($this->at(7)) ->method('delete') ->with('media/cache/filterTwo/pathTwo.jpg') - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove( array('pathOne.jpg', 'pathTwo.jpg'), array('filterOne', 'filterTwo') @@ -224,17 +205,15 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() public function testDoNothingWhenObjectNotExistForPathAndFilterOnRemove() { - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $fs ->expects($this->once()) ->method('has') ->with('media/cache/thumb/some-folder/path.jpg') - ->will($this->returnValue(false)) - ; + ->will($this->returnValue(false)); $fs ->expects($this->never()) - ->method('delete') - ; + ->method('delete'); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); $resolver->remove(array('some-folder/path.jpg'), array('thumb')); @@ -244,15 +223,13 @@ public function testRemoveCacheForFilterOnRemove() { $expectedFilter = 'theFilter'; - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $fs ->expects($this->once()) ->method('deleteDir') - ->with('media/cache/theFilter') - ; + ->with('media/cache/theFilter'); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove(array(), array($expectedFilter)); } @@ -261,36 +238,35 @@ public function testRemoveCacheForSomeFiltersOnRemove() $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; - $fs = $this->getFlysystemMock(); + $fs = $this->createFlySystemMock(); $fs ->expects($this->at(0)) ->method('deleteDir') - ->with('media/cache/theFilterOne') - ; + ->with('media/cache/theFilterOne'); $fs ->expects($this->at(1)) ->method('deleteDir') - ->with('media/cache/theFilterTwo') - ; + ->with('media/cache/theFilterTwo'); $resolver = new FlysystemResolver($fs, new RequestContext(), 'http://images.example.com'); - $resolver->remove(array(), array($expectedFilterOne, $expectedFilterTwo)); } /** * @return \PHPUnit_Framework_MockObject_MockObject|Filesystem */ - protected function getFlysystemMock() + protected function createFlySystemMock() { - $mockedMethods = array( - 'delete', - 'deleteDir', - 'has', - 'put', - 'remove', - ); - - return $this->getMock('League\Flysystem\Filesystem', $mockedMethods, array(), '', false); + return $this + ->getMockBuilder('\League\Flysystem\Filesystem') + ->disableOriginalConstructor() + ->setMethods(array( + 'delete', + 'deleteDir', + 'has', + 'put', + 'remove', + )) + ->getMock(); } } diff --git a/Tests/Imagine/Cache/Resolver/NoCacheWebPathResolverTest.php b/Tests/Imagine/Cache/Resolver/NoCacheWebPathResolverTest.php index bbad9fd6c..0da5e14a8 100644 --- a/Tests/Imagine/Cache/Resolver/NoCacheWebPathResolverTest.php +++ b/Tests/Imagine/Cache/Resolver/NoCacheWebPathResolverTest.php @@ -17,7 +17,7 @@ use Symfony\Component\Routing\RequestContext; /** - * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\NoCacheWebPathResolver + * @covers \Liip\ImagineBundle\Imagine\Cache\Resolver\NoCacheWebPathResolver */ class NoCacheWebPathResolverTest extends AbstractTest { @@ -28,9 +28,7 @@ public function testCouldBeConstructedWithRequestContextAsArgument() public function testComposeSchemaHostAndPathOnResolve() { - $context = new RequestContext('', 'GET', 'thehost', 'theSchema'); - - $resolver = new NoCacheWebPathResolver($context); + $resolver = new NoCacheWebPathResolver(new RequestContext('', 'GET', 'thehost', 'theSchema')); $this->assertEquals('theschema://thehost/aPath', $resolver->resolve('aPath', 'aFilter')); } @@ -39,31 +37,24 @@ public function testDoNothingOnStore() { $resolver = new NoCacheWebPathResolver(new RequestContext()); - $this->assertNull($resolver->store( - new Binary('aContent', 'image/jpeg', 'jpg'), - 'a/path', - 'aFilter' - )); + $this->assertNull($resolver->store(new Binary('aContent', 'image/jpeg', 'jpg'), 'a/path', 'aFilter')); } public function testDoNothingForPathAndFilterOnRemove() { $resolver = new NoCacheWebPathResolver(new RequestContext()); - $resolver->remove(array('a/path'), array('aFilter')); } public function testDoNothingForSomePathsAndSomeFiltersOnRemove() { $resolver = new NoCacheWebPathResolver(new RequestContext()); - $resolver->remove(array('foo', 'bar'), array('foo', 'bar')); } public function testDoNothingForEmptyPathAndEmptyFilterOnRemove() { $resolver = new NoCacheWebPathResolver(new RequestContext()); - $resolver->remove(array(), array()); } } diff --git a/Tests/Imagine/Cache/Resolver/ProxyResolverTest.php b/Tests/Imagine/Cache/Resolver/ProxyResolverTest.php index 2869eeb8a..aca30f271 100644 --- a/Tests/Imagine/Cache/Resolver/ProxyResolverTest.php +++ b/Tests/Imagine/Cache/Resolver/ProxyResolverTest.php @@ -14,14 +14,15 @@ use Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver; use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; use Liip\ImagineBundle\Model\Binary; +use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver + * @covers \Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver */ -class ProxyResolverTest extends \Phpunit_Framework_TestCase +class ProxyResolverTest extends AbstractTest { /** - * @var ResolverInterface + * @var \PHPUnit_Framework_MockObject_MockObject|ResolverInterface */ private $primaryResolver; @@ -32,8 +33,7 @@ class ProxyResolverTest extends \Phpunit_Framework_TestCase public function setUp() { - $this->primaryResolver = $this->getMock('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface'); - + $this->primaryResolver = $this->createObjectMock('\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface'); $this->resolver = new ProxyResolver($this->primaryResolver, array('http://images.example.com')); } @@ -46,8 +46,7 @@ public function testProxyCallAndRewriteReturnedUrlOnResolve() ->expects($this->once()) ->method('resolve') ->with($expectedPath, $expectedFilter) - ->will($this->returnValue('http://foo.com/thumbs/foo/bar/bazz.png')) - ; + ->will($this->returnValue('http://foo.com/thumbs/foo/bar/bazz.png')); $result = $this->resolver->resolve($expectedPath, $expectedFilter); @@ -63,8 +62,7 @@ public function testProxyCallAndRewriteReturnedUrlEvenSchemesDiffersOnResolve() ->expects($this->once()) ->method('resolve') ->with($expectedPath, $expectedFilter) - ->will($this->returnValue('http://foo.com/thumbs/foo/bar/bazz.png')) - ; + ->will($this->returnValue('http://foo.com/thumbs/foo/bar/bazz.png')); $result = $this->resolver->resolve($expectedPath, $expectedFilter); @@ -80,8 +78,7 @@ public function testProxyCallAndRewriteReturnedUrlWithMatchReplaceOnResolve() ->expects($this->once()) ->method('resolve') ->with($expectedPath, $expectedFilter) - ->will($this->returnValue('https://s3-eu-west-1.amazonaws.com/s3-cache.example.com/thumbs/foo/bar/bazz.png')) - ; + ->will($this->returnValue('https://s3-eu-west-1.amazonaws.com/s3-cache.example.com/thumbs/foo/bar/bazz.png')); $this->resolver = new ProxyResolver($this->primaryResolver, array( 'https://s3-eu-west-1.amazonaws.com/s3-cache.example.com' => 'http://images.example.com', @@ -101,8 +98,7 @@ public function testProxyCallAndRewriteReturnedUrlWithRegExpOnResolve() ->expects($this->once()) ->method('resolve') ->with($expectedPath, $expectedFilter) - ->will($this->returnValue('http://foo.com/thumbs/foo/bar/bazz.png')) - ; + ->will($this->returnValue('http://foo.com/thumbs/foo/bar/bazz.png')); $this->resolver = new ProxyResolver($this->primaryResolver, array( 'regexp/http:\/\/.*?\//' => 'http://bar.com/', @@ -122,8 +118,7 @@ public function testProxyCallAndReturnedValueOnIsStored() ->expects($this->once()) ->method('isStored') ->with($expectedPath, $expectedFilter) - ->will($this->returnValue(true)) - ; + ->will($this->returnValue(true)); $this->assertTrue($this->resolver->isStored($expectedPath, $expectedFilter)); } @@ -137,8 +132,7 @@ public function testProxyCallOnStore() $this->primaryResolver ->expects($this->once()) ->method('store') - ->with($expectedBinary, $expectedPath, $expectedFilter) - ; + ->with($expectedBinary, $expectedPath, $expectedFilter); $this->resolver->store($expectedBinary, $expectedPath, $expectedFilter); } @@ -151,8 +145,7 @@ public function testProxyCallOnRemove() $this->primaryResolver ->expects($this->once()) ->method('remove') - ->with($expectedPaths, $expectedFilters) - ; + ->with($expectedPaths, $expectedFilters); $this->resolver->remove($expectedPaths, $expectedFilters); } diff --git a/Tests/Imagine/Cache/Resolver/WebPathResolverTest.php b/Tests/Imagine/Cache/Resolver/WebPathResolverTest.php index a17760138..bc97afc70 100644 --- a/Tests/Imagine/Cache/Resolver/WebPathResolverTest.php +++ b/Tests/Imagine/Cache/Resolver/WebPathResolverTest.php @@ -17,17 +17,23 @@ use Symfony\Component\Routing\RequestContext; /** - * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver + * @covers \Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver */ class WebPathResolverTest extends \PHPUnit_Framework_TestCase { - /** @var Filesystem */ + /** + * @var Filesystem + */ private $filesystem; - /** @var string */ + /** + * @var string + */ private $basePath; - /** @var string */ + /** + * @var string + */ private $existingFile; public function setUp() @@ -46,9 +52,9 @@ public function tearDown() public function testImplementsResolverInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')); } public function testCouldBeConstructedWithRequiredArguments() @@ -287,8 +293,7 @@ public function testDumpBinaryContentOnStore() $filesystemMock ->expects($this->once()) ->method('dumpFile') - ->with('/aWebRoot/aCachePrefix/aFilter/aPath', 'theContent') - ; + ->with('/aWebRoot/aCachePrefix/aFilter/aPath', 'theContent'); $resolver = new WebPathResolver( $filesystemMock, @@ -305,8 +310,7 @@ public function testDoNothingIfFiltersAndPathsEmptyOnRemove() $filesystemMock = $this->createFilesystemMock(); $filesystemMock ->expects($this->never()) - ->method('remove') - ; + ->method('remove'); $resolver = new WebPathResolver( $filesystemMock, @@ -324,8 +328,7 @@ public function testRemoveCacheForPathAndFilterOnRemove() $filesystemMock ->expects($this->once()) ->method('remove') - ->with('/aWebRoot/aCachePrefix/aFilter/aPath') - ; + ->with('/aWebRoot/aCachePrefix/aFilter/aPath'); $resolver = new WebPathResolver( $filesystemMock, @@ -343,13 +346,11 @@ public function testRemoveCacheForSomePathsAndFilterOnRemove() $filesystemMock ->expects($this->at(0)) ->method('remove') - ->with('/aWebRoot/aCachePrefix/aFilter/aPathOne') - ; + ->with('/aWebRoot/aCachePrefix/aFilter/aPathOne'); $filesystemMock ->expects($this->at(1)) ->method('remove') - ->with('/aWebRoot/aCachePrefix/aFilter/aPathTwo') - ; + ->with('/aWebRoot/aCachePrefix/aFilter/aPathTwo'); $resolver = new WebPathResolver( $filesystemMock, @@ -367,23 +368,19 @@ public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove() $filesystemMock ->expects($this->at(0)) ->method('remove') - ->with('/aWebRoot/aCachePrefix/aFilterOne/aPathOne') - ; + ->with('/aWebRoot/aCachePrefix/aFilterOne/aPathOne'); $filesystemMock ->expects($this->at(1)) ->method('remove') - ->with('/aWebRoot/aCachePrefix/aFilterTwo/aPathOne') - ; + ->with('/aWebRoot/aCachePrefix/aFilterTwo/aPathOne'); $filesystemMock ->expects($this->at(2)) ->method('remove') - ->with('/aWebRoot/aCachePrefix/aFilterOne/aPathTwo') - ; + ->with('/aWebRoot/aCachePrefix/aFilterOne/aPathTwo'); $filesystemMock ->expects($this->at(3)) ->method('remove') - ->with('/aWebRoot/aCachePrefix/aFilterTwo/aPathTwo') - ; + ->with('/aWebRoot/aCachePrefix/aFilterTwo/aPathTwo'); $resolver = new WebPathResolver( $filesystemMock, @@ -406,8 +403,7 @@ public function testRemoveCacheForFilterOnRemove() ->method('remove') ->with(array( '/aWebRoot/aCachePrefix/aFilter', - )) - ; + )); $resolver = new WebPathResolver( $filesystemMock, @@ -428,8 +424,7 @@ public function testRemoveCacheForSomeFiltersOnRemove() ->with(array( '/aWebRoot/aCachePrefix/aFilterOne', '/aWebRoot/aCachePrefix/aFilterTwo', - )) - ; + )); $resolver = new WebPathResolver( $filesystemMock, @@ -482,6 +477,6 @@ public function testShouldSanitizeSeparatorBetweenSchemeAndAuthorityInUrl() */ protected function createFilesystemMock() { - return $this->getMock('Symfony\Component\Filesystem\Filesystem'); + return $this->getMockBuilder('\Symfony\Component\Filesystem\Filesystem')->getMock(); } } diff --git a/Tests/Imagine/Cache/SignerTest.php b/Tests/Imagine/Cache/SignerTest.php index bd3989f2f..6230f7127 100644 --- a/Tests/Imagine/Cache/SignerTest.php +++ b/Tests/Imagine/Cache/SignerTest.php @@ -14,13 +14,16 @@ use Liip\ImagineBundle\Imagine\Cache\Signer; use Liip\ImagineBundle\Tests\AbstractTest; +/** + * @covers \Liip\ImagineBundle\Imagine\Cache\Signer + */ class SignerTest extends AbstractTest { public function testImplementsSignerInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Imagine\Cache\Signer'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\Imagine\Cache\Signer'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Imagine\Cache\SignerInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\Imagine\Cache\SignerInterface')); } public function testCouldBeConstructedWithSecret() diff --git a/Tests/Imagine/Data/DataManagerTest.php b/Tests/Imagine/Data/DataManagerTest.php index a831392c6..c9a3fa613 100644 --- a/Tests/Imagine/Data/DataManagerTest.php +++ b/Tests/Imagine/Data/DataManagerTest.php @@ -11,24 +11,22 @@ namespace Liip\ImagineBundle\Tests\Imagine\Data; -use Liip\ImagineBundle\Binary\Loader\LoaderInterface; use Liip\ImagineBundle\Imagine\Data\DataManager; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Data\DataManager + * @covers \Liip\ImagineBundle\Imagine\Data\DataManager */ class DataManagerTest extends AbstractTest { public function testUseDefaultLoaderUsedIfNoneSet() { - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('find') - ->with('cats.jpeg') - ; + ->with('cats.jpeg'); $config = $this->createFilterConfigurationMock(); $config @@ -39,17 +37,15 @@ public function testUseDefaultLoaderUsedIfNoneSet() 'size' => array(180, 180), 'mode' => 'outbound', 'data_loader' => null, - ))) - ; + ))); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->once()) ->method('guess') - ->will($this->returnValue('image/png')) - ; + ->will($this->returnValue('image/png')); - $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config, 'default'); + $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config, 'default'); $dataManager->addLoader('default', $loader); $dataManager->find('thumbnail', 'cats.jpeg'); @@ -57,12 +53,11 @@ public function testUseDefaultLoaderUsedIfNoneSet() public function testUseLoaderRegisteredForFilterOnFind() { - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('find') - ->with('cats.jpeg') - ; + ->with('cats.jpeg'); $config = $this->createFilterConfigurationMock(); $config @@ -73,30 +68,31 @@ public function testUseLoaderRegisteredForFilterOnFind() 'size' => array(180, 180), 'mode' => 'outbound', 'data_loader' => 'the_loader', - ))) - ; + ))); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->once()) ->method('guess') - ->will($this->returnValue('image/png')) - ; + ->will($this->returnValue('image/png')); - $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); $dataManager->addLoader('the_loader', $loader); $dataManager->find('thumbnail', 'cats.jpeg'); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage The mime type of image cats.jpeg was not guessed + */ public function testThrowsIfMimeTypeWasNotGuessedOnFind() { - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('find') - ->with('cats.jpeg') - ; + ->with('cats.jpeg'); $config = $this->createFilterConfigurationMock(); $config @@ -107,32 +103,31 @@ public function testThrowsIfMimeTypeWasNotGuessedOnFind() 'size' => array(180, 180), 'mode' => 'outbound', 'data_loader' => 'the_loader', - ))) - ; + ))); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->once()) ->method('guess') - ->will($this->returnValue(null)) - ; + ->will($this->returnValue(null)); - $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); $dataManager->addLoader('the_loader', $loader); - - $this->setExpectedException('LogicException', 'The mime type of image cats.jpeg was not guessed.'); $dataManager->find('thumbnail', 'cats.jpeg'); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage The mime type of image cats.jpeg must be image/xxx got text/plain + */ public function testThrowsIfMimeTypeNotImageOneOnFind() { - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('find') ->with('cats.jpeg') - ->will($this->returnValue('content')) - ; + ->will($this->returnValue('content')); $config = $this->createFilterConfigurationMock(); $config @@ -143,32 +138,31 @@ public function testThrowsIfMimeTypeNotImageOneOnFind() 'size' => array(180, 180), 'mode' => 'outbound', 'data_loader' => 'the_loader', - ))) - ; + ))); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->once()) ->method('guess') - ->will($this->returnValue('text/plain')) - ; + ->will($this->returnValue('text/plain')); - $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); $dataManager->addLoader('the_loader', $loader); - - $this->setExpectedException('LogicException', 'The mime type of image cats.jpeg must be image/xxx got text/plain.'); $dataManager->find('thumbnail', 'cats.jpeg'); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage The mime type of image cats.jpeg was not guessed + */ public function testThrowsIfLoaderReturnBinaryWithEmtptyMimeTypeOnFind() { - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('find') ->with('cats.jpeg') - ->will($this->returnValue(new Binary('content', null))) - ; + ->will($this->returnValue(new Binary('content', null))); $config = $this->createFilterConfigurationMock(); $config @@ -179,33 +173,32 @@ public function testThrowsIfLoaderReturnBinaryWithEmtptyMimeTypeOnFind() 'size' => array(180, 180), 'mode' => 'outbound', 'data_loader' => 'the_loader', - ))) - ; + ))); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->never()) - ->method('guess') - ; + ->method('guess'); - $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); $dataManager->addLoader('the_loader', $loader); - - $this->setExpectedException('LogicException', 'The mime type of image cats.jpeg was not guessed.'); $dataManager->find('thumbnail', 'cats.jpeg'); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage The mime type of image cats.jpeg must be image/xxx got text/plain + */ public function testThrowsIfLoaderReturnBinaryWithMimeTypeNotImageOneOnFind() { $binary = new Binary('content', 'text/plain'); - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('find') ->with('cats.jpeg') - ->will($this->returnValue($binary)) - ; + ->will($this->returnValue($binary)); $config = $this->createFilterConfigurationMock(); $config @@ -216,22 +209,22 @@ public function testThrowsIfLoaderReturnBinaryWithMimeTypeNotImageOneOnFind() 'size' => array(180, 180), 'mode' => 'outbound', 'data_loader' => 'the_loader', - ))) - ; + ))); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->never()) - ->method('guess') - ; + ->method('guess'); - $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config); + $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config); $dataManager->addLoader('the_loader', $loader); - - $this->setExpectedException('LogicException', 'The mime type of image cats.jpeg must be image/xxx got text/plain.'); $dataManager->find('thumbnail', 'cats.jpeg'); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Could not find data loader "" for "thumbnail" filter type + */ public function testThrowIfLoaderNotRegisteredForGivenFilterOnFind() { $config = $this->createFilterConfigurationMock(); @@ -243,12 +236,9 @@ public function testThrowIfLoaderNotRegisteredForGivenFilterOnFind() 'size' => array(180, 180), 'mode' => 'outbound', 'data_loader' => null, - ))) - ; + ))); - $dataManager = new DataManager($this->getMockMimeTypeGuesser(), $this->getMockExtensionGuesser(), $config); - - $this->setExpectedException('InvalidArgumentException', 'Could not find data loader "" for "thumbnail" filter type'); + $dataManager = new DataManager($this->createMimeTypeGuesserInterfaceMock(), $this->createExtensionGuesserInterfaceMock(), $config); $dataManager->find('thumbnail', 'cats.jpeg'); } @@ -257,20 +247,18 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedMimeTypeOnFind( $expectedContent = 'theImageBinaryContent'; $expectedMimeType = 'image/png'; - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('find') - ->will($this->returnValue($expectedContent)) - ; + ->will($this->returnValue($expectedContent)); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->with($expectedContent) - ->will($this->returnValue($expectedMimeType)) - ; + ->will($this->returnValue($expectedMimeType)); $config = $this->createFilterConfigurationMock(); $config @@ -281,10 +269,9 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedMimeTypeOnFind( 'size' => array(180, 180), 'mode' => 'outbound', 'data_loader' => null, - ))) - ; + ))); - $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config, 'default'); + $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config, 'default'); $dataManager->addLoader('default', $loader); $binary = $dataManager->find('thumbnail', 'cats.jpeg'); @@ -300,28 +287,25 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedFormatOnFind() $mimeType = 'image/png'; $expectedFormat = 'png'; - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('find') - ->will($this->returnValue($content)) - ; + ->will($this->returnValue($content)); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->with($content) - ->will($this->returnValue($mimeType)) - ; + ->will($this->returnValue($mimeType)); - $extensionGuesser = $this->getMockExtensionGuesser(); + $extensionGuesser = $this->createExtensionGuesserInterfaceMock(); $extensionGuesser ->expects($this->once()) ->method('guess') ->with($mimeType) - ->will($this->returnValue($expectedFormat)) - ; + ->will($this->returnValue($expectedFormat)); $config = $this->createFilterConfigurationMock(); $config @@ -332,8 +316,7 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedFormatOnFind() 'size' => array(180, 180), 'mode' => 'outbound', 'data_loader' => null, - ))) - ; + ))); $dataManager = new DataManager($mimeTypeGuesser, $extensionGuesser, $config, 'default'); $dataManager->addLoader('default', $loader); @@ -346,7 +329,7 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedFormatOnFind() public function testUseDefaultGlobalImageUsedIfImageNotFound() { - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $config = $this->createFilterConfigurationMock(); $config @@ -355,17 +338,15 @@ public function testUseDefaultGlobalImageUsedIfImageNotFound() ->with('thumbnail') ->will($this->returnValue(array( 'default_image' => null, - ))) - ; + ))); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->never()) - ->method('guess') - ; + ->method('guess'); $defaultGlobalImage = 'cats.jpeg'; - $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config, 'default', 'cats.jpeg'); + $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config, 'default', 'cats.jpeg'); $dataManager->addLoader('default', $loader); $defaultImage = $dataManager->getDefaultImageUrl('thumbnail'); @@ -374,7 +355,7 @@ public function testUseDefaultGlobalImageUsedIfImageNotFound() public function testUseDefaultFilterImageUsedIfImageNotFound() { - $loader = $this->getMockLoader(); + $loader = $this->createBinaryLoaderInterfaceMock(); $defaultFilterImage = 'cats.jpeg'; @@ -385,43 +366,17 @@ public function testUseDefaultFilterImageUsedIfImageNotFound() ->with('thumbnail') ->will($this->returnValue(array( 'default_image' => $defaultFilterImage, - ))) - ; + ))); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->never()) - ->method('guess') - ; + ->method('guess'); - $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config, 'default', null); + $dataManager = new DataManager($mimeTypeGuesser, $this->createExtensionGuesserInterfaceMock(), $config, 'default', null); $dataManager->addLoader('default', $loader); $defaultImage = $dataManager->getDefaultImageUrl('thumbnail'); $this->assertEquals($defaultImage, $defaultFilterImage); } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|LoaderInterface - */ - protected function getMockLoader() - { - return $this->getMock('Liip\ImagineBundle\Binary\Loader\LoaderInterface'); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\Liip\ImagineBundle\Binary\MimeTypeGuesserInterface - */ - protected function getMockMimeTypeGuesser() - { - return $this->getMock('Liip\ImagineBundle\Binary\MimeTypeGuesserInterface'); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface - */ - protected function getMockExtensionGuesser() - { - return $this->getMock('Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface'); - } } diff --git a/Tests/Imagine/Filter/FilterConfigurationTest.php b/Tests/Imagine/Filter/FilterConfigurationTest.php index 5e1c97216..c9d4df68f 100644 --- a/Tests/Imagine/Filter/FilterConfigurationTest.php +++ b/Tests/Imagine/Filter/FilterConfigurationTest.php @@ -15,7 +15,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Filter\FilterConfiguration + * @covers \Liip\ImagineBundle\Imagine\Filter\FilterConfiguration */ class FilterConfigurationTest extends AbstractTest { @@ -54,11 +54,13 @@ public function testReturnAllFilters() $this->assertEquals(array('barConfig'), $filters['bar']); } + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage Could not find configuration for a filter: thumbnail + */ public function testGetUndefinedFilter() { $filterConfiguration = new FilterConfiguration(); - - $this->setExpectedException('RuntimeException', 'Could not find configuration for a filter: thumbnail'); $filterConfiguration->get('thumbnail'); } diff --git a/Tests/Imagine/Filter/FilterManagerTest.php b/Tests/Imagine/Filter/FilterManagerTest.php index f77fec6b6..27c7ddd1c 100644 --- a/Tests/Imagine/Filter/FilterManagerTest.php +++ b/Tests/Imagine/Filter/FilterManagerTest.php @@ -12,15 +12,18 @@ namespace Liip\ImagineBundle\Tests\Filter; use Liip\ImagineBundle\Imagine\Filter\FilterManager; -use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; use Liip\ImagineBundle\Model\Binary; use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Filter\FilterManager + * @covers \Liip\ImagineBundle\Imagine\Filter\FilterManager */ class FilterManagerTest extends AbstractTest { + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Could not find filter loader for "thumbnail" filter type + */ public function testThrowsIfNoLoadersAddedForFilterOnApplyFilter() { $config = $this->createFilterConfigurationMock(); @@ -36,18 +39,16 @@ public function testThrowsIfNoLoadersAddedForFilterOnApplyFilter() ), ), 'post_processors' => array(), - ))) - ; + ))); $binary = new Binary('aContent', 'image/png', 'png'); $filterManager = new FilterManager( $config, - $this->createImagineMock(), - $this->getMockMimeTypeGuesser() + $this->createImagineInterfaceMock(), + $this->createMimeTypeGuesserInterfaceMock() ); - $this->setExpectedException('InvalidArgumentException', 'Could not find filter loader for "thumbnail" filter type'); $filterManager->applyFilter($binary, 'thumbnail'); } @@ -73,42 +74,38 @@ public function testReturnFilteredBinaryWithExpectedContentOnApplyFilter() 'thumbnail' => $thumbConfig, ), 'post_processors' => array(), - ))) - ; + ))); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue($expectedFilteredContent)) - ; + ->will($this->returnValue($expectedFilteredContent)); - $imagine = $this->createImagineMock(); + $imagine = $this->createImagineInterfaceMock(); $imagine ->expects($this->once()) ->method('load') ->with($originalContent) - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $config, $imagine, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail'); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedFilteredContent, $filteredBinary->getContent()); } @@ -134,41 +131,37 @@ public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApplyFilter( 'thumbnail' => $thumbConfig, ), 'post_processors' => array(), - ))) - ; + ))); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagine = $this->createImagineMock(); + $imagine = $this->createImagineInterfaceMock(); $imagine ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $config, $imagine, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail'); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedFormat, $filteredBinary->getFormat()); } @@ -196,41 +189,37 @@ public function testReturnFilteredBinaryWithCustomFormatIfSetOnApplyFilter() 'thumbnail' => $thumbConfig, ), 'post_processors' => array(), - ))) - ; + ))); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagine = $this->createImagineMock(); + $imagine = $this->createImagineInterfaceMock(); $imagine ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $config, $imagine, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail'); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedFormat, $filteredBinary->getFormat()); } @@ -256,36 +245,31 @@ public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApplyFilte 'thumbnail' => $thumbConfig, ), 'post_processors' => array(), - ))) - ; + ))); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagine = $this->createImagineMock(); + $imagine = $this->createImagineInterfaceMock(); $imagine ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->never()) - ->method('guess') - ; + ->method('guess'); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $config, @@ -296,7 +280,7 @@ public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApplyFilte $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail'); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType()); } @@ -325,38 +309,33 @@ public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApplyFi 'thumbnail' => $thumbConfig, ), 'post_processors' => array(), - ))) - ; + ))); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue($expectedContent)) - ; + ->will($this->returnValue($expectedContent)); - $imagine = $this->createImagineMock(); + $imagine = $this->createImagineInterfaceMock(); $imagine ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->with($expectedContent) - ->will($this->returnValue($expectedMimeType)) - ; + ->will($this->returnValue($expectedMimeType)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $config, @@ -367,7 +346,7 @@ public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApplyFi $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail'); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType()); } @@ -394,40 +373,36 @@ public function testAltersQualityOnApplyFilter() 'thumbnail' => $thumbConfig, ), 'post_processors' => array(), - ))) - ; + ))); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') ->with('png', array('quality' => $expectedQuality)) - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagine = $this->createImagineMock(); + $imagine = $this->createImagineInterfaceMock(); $imagine ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $config, $imagine, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail')); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail')); } public function testAlters100QualityIfNotSetOnApplyFilter() @@ -452,40 +427,36 @@ public function testAlters100QualityIfNotSetOnApplyFilter() 'thumbnail' => $thumbConfig, ), 'post_processors' => array(), - ))) - ; + ))); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') ->with('png', array('quality' => $expectedQuality)) - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagine = $this->createImagineMock(); + $imagine = $this->createImagineInterfaceMock(); $imagine ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $config, $imagine, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail')); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail')); } public function testMergeRuntimeConfigWithOneFromFilterConfigurationOnApplyFilter() @@ -521,55 +492,53 @@ public function testMergeRuntimeConfigWithOneFromFilterConfigurationOnApplyFilte 'thumbnail' => $thumbConfig, ), 'post_processors' => array(), - ))) - ; + ))); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagine = $this->createImagineMock(); + $imagine = $this->createImagineInterfaceMock(); $imagine ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbMergedConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $config, $imagine, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); $this->assertInstanceOf( - 'Liip\ImagineBundle\Model\Binary', + '\Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail', $runtimeConfig) ); } - + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Could not find filter loader for "thumbnail" filter type + */ public function testThrowsIfNoLoadersAddedForFilterOnApply() { $binary = new Binary('aContent', 'image/png', 'png'); $filterManager = new FilterManager( $this->createFilterConfigurationMock(), - $this->createImagineMock(), - $this->getMockMimeTypeGuesser() + $this->createImagineInterfaceMock(), + $this->createMimeTypeGuesserInterfaceMock() ); - $this->setExpectedException('InvalidArgumentException', 'Could not find filter loader for "thumbnail" filter type'); $filterManager->apply($binary, array( 'filters' => array( 'thumbnail' => array( @@ -592,33 +561,30 @@ public function testReturnFilteredBinaryWithExpectedContentOnApply() 'mode' => 'outbound', ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue($expectedFilteredContent)) - ; + ->will($this->returnValue($expectedFilteredContent)); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->expects($this->once()) ->method('load') ->with($originalContent) - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $this->createFilterConfigurationMock(), $imagineMock, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); @@ -629,7 +595,7 @@ public function testReturnFilteredBinaryWithExpectedContentOnApply() 'post_processors' => array(), )); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedFilteredContent, $filteredBinary->getContent()); } @@ -645,32 +611,29 @@ public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApply() 'mode' => 'outbound', ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $this->createFilterConfigurationMock(), $imagineMock, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); @@ -681,7 +644,7 @@ public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApply() 'post_processors' => array(), )); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedFormat, $filteredBinary->getFormat()); } @@ -698,32 +661,29 @@ public function testReturnFilteredBinaryWithCustomFormatIfSetOnApply() 'mode' => 'outbound', ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $this->createFilterConfigurationMock(), $imagineMock, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); @@ -735,7 +695,7 @@ public function testReturnFilteredBinaryWithCustomFormatIfSetOnApply() 'post_processors' => array(), )); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedFormat, $filteredBinary->getFormat()); } @@ -751,33 +711,29 @@ public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApply() 'mode' => 'outbound', ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->never()) - ->method('guess') - ; + ->method('guess'); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $this->createFilterConfigurationMock(), @@ -793,7 +749,7 @@ public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApply() 'post_processors' => array(), )); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType()); } @@ -811,35 +767,31 @@ public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApply() 'mode' => 'outbound', ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue($expectedContent)) - ; + ->will($this->returnValue($expectedContent)); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $mimeTypeGuesser = $this->getMockMimeTypeGuesser(); + $mimeTypeGuesser = $this->createMimeTypeGuesserInterfaceMock(); $mimeTypeGuesser ->expects($this->once()) ->method('guess') ->with($expectedContent) - ->will($this->returnValue($expectedMimeType)) - ; + ->will($this->returnValue($expectedMimeType)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $this->createFilterConfigurationMock(), @@ -856,7 +808,7 @@ public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApply() 'post_processors' => array(), )); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType()); } @@ -872,33 +824,30 @@ public function testAltersQualityOnApply() 'mode' => 'outbound', ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') ->with('png', array('quality' => $expectedQuality)) - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $this->createFilterConfigurationMock(), $imagineMock, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); @@ -910,7 +859,7 @@ public function testAltersQualityOnApply() 'post_processors' => array(), )); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); } public function testAlters100QualityIfNotSetOnApply() @@ -925,33 +874,30 @@ public function testAlters100QualityIfNotSetOnApply() 'mode' => 'outbound', ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') ->with('png', array('quality' => $expectedQuality)) - ->will($this->returnValue('aFilteredContent')) - ; + ->will($this->returnValue('aFilteredContent')); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->expects($this->once()) ->method('load') - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $this->createFilterConfigurationMock(), $imagineMock, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); @@ -962,7 +908,7 @@ public function testAlters100QualityIfNotSetOnApply() 'post_processors' => array(), )); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); } public function testApplyPostProcessor() @@ -988,40 +934,36 @@ public function testApplyPostProcessor() 'post_processors' => array( 'foo' => array(), ), - ))) - ; + ))); $thumbConfig = array( 'size' => array(180, 180), 'mode' => 'outbound', ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue($originalContent)) - ; + ->will($this->returnValue($originalContent)); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->expects($this->once()) ->method('load') ->with($originalContent) - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $processedBinary = new Binary($expectedPostProcessedContent, 'image/png', 'png'); - $postProcessor = $this->getPostProcessorMock(); + $postProcessor = $this->createPostProcessorInterfaceMock(); $postProcessor ->expects($this->once()) ->method('process') @@ -1031,16 +973,19 @@ public function testApplyPostProcessor() $filterManager = new FilterManager( $config, $imagineMock, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); $filterManager->addLoader('thumbnail', $loader); $filterManager->addPostProcessor('foo', $postProcessor); $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail'); - $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); + $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedPostProcessedContent, $filteredBinary->getContent()); } - + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Could not find post processor "foo" + */ public function testThrowsIfNoPostProcessorAddedForFilterOnApplyFilter() { $originalContent = 'aContent'; @@ -1063,56 +1008,50 @@ public function testThrowsIfNoPostProcessorAddedForFilterOnApplyFilter() 'post_processors' => array( 'foo' => array(), ), - ))) - ; + ))); $thumbConfig = array( 'size' => array(180, 180), 'mode' => 'outbound', ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('get') - ->will($this->returnValue($originalContent)) - ; + ->will($this->returnValue($originalContent)); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->expects($this->once()) ->method('load') ->with($originalContent) - ->will($this->returnValue($image)) - ; + ->will($this->returnValue($image)); - $loader = $this->getMockLoader(); + $loader = $this->createFilterLoaderInterfaceMock(); $loader ->expects($this->once()) ->method('load') ->with($this->identicalTo($image), $thumbConfig) - ->will($this->returnArgument(0)) - ; + ->will($this->returnArgument(0)); $filterManager = new FilterManager( $config, $imagineMock, - $this->getMockMimeTypeGuesser() + $this->createMimeTypeGuesserInterfaceMock() ); - $filterManager->addLoader('thumbnail', $loader); - - $this->setExpectedException('InvalidArgumentException', 'Could not find post processor "foo"'); + $filterManager->addLoader('thumbnail', $loader); $filterManager->applyFilter($binary, 'thumbnail'); } public function testApplyPostProcessorsWhenNotDefined() { - $binary = $this->getMock('Liip\ImagineBundle\Binary\BinaryInterface'); + $binary = $this->getMockBuilder('\Liip\ImagineBundle\Binary\BinaryInterface')->getMock(); $filterManager = new FilterManager( $this->createFilterConfigurationMock(), - $this->createImagineMock(), - $this->getMockMimeTypeGuesser() + $this->createImagineInterfaceMock(), + $this->createMimeTypeGuesserInterfaceMock() ); $this->assertSame($binary, $filterManager->applyPostProcessors($binary, array())); @@ -1121,21 +1060,9 @@ public function testApplyPostProcessorsWhenNotDefined() /** * @return \PHPUnit_Framework_MockObject_MockObject|LoaderInterface */ - protected function getMockLoader() - { - return $this->getMock('Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface'); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\Liip\ImagineBundle\Binary\MimeTypeGuesserInterface - */ - protected function getMockMimeTypeGuesser() - { - return $this->getMock('Liip\ImagineBundle\Binary\MimeTypeGuesserInterface'); - } - - protected function getPostProcessorMock() + protected function createFilterLoaderInterfaceMock() { - return $this->getMock('Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface'); +// $this->getMock() + return $this->createObjectMock('\Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface'); } } diff --git a/Tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php index b2d08d80a..8c0900c95 100644 --- a/Tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php @@ -15,10 +15,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for RotateFilterLoader class. - * Depending on the EXIF value checks whether rotate and flip are called. - * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\AutoRotateFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\AutoRotateFilterLoader */ class AutoRotateFilterLoaderTest extends AbstractTest { @@ -36,12 +33,12 @@ private function loadExif($exifValue, $expectCallRotateValue, $expectCallFlip) $loader = new AutoRotateFilterLoader(); // Mocks the image and makes it use the fake meta data. - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); - if (method_exists('Imagine\Image\ImageInterface', 'metadata')) { + if (method_exists('\Imagine\Image\ImageInterface', 'metadata')) { // Mocks the metadata and makes it return the expected exif value for the rotation. // If $exifValue is null, it means the image doesn't contain any metadata. - $metaData = $this->getMockMetaData(); + $metaData = $this->getMetadataBagMock(); $metaData ->expects($this->atLeastOnce()) diff --git a/Tests/Imagine/Filter/Loader/CropFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/CropFilterLoaderTest.php index 62b1246ae..e3aef20d1 100644 --- a/Tests/Imagine/Filter/Loader/CropFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/CropFilterLoaderTest.php @@ -17,9 +17,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for CropFilterLoader class. - * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader * * @author Alex Wilson */ @@ -29,7 +27,7 @@ class CropFilterLoaderTest extends AbstractTest * @param int[] $coordinates * @param int[] $area * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader::load + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader::load * * @dataProvider cropDataProvider */ @@ -43,7 +41,7 @@ public function testLoad($coordinates, $area) $loader = new CropFilterLoader(); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $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 05764968d..99158d03d 100644 --- a/Tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php @@ -16,9 +16,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for DownscaleFilterLoader class. - * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\DownscaleFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\DownscaleFilterLoader * * @author Minin Anton */ @@ -31,17 +29,15 @@ public function testItWorksSomeHow() $initialSize = new Box(50, 200); $resultSize = new Box(50, 200); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->method('getSize') - ->willReturn($initialSize) - ; + ->willReturn($initialSize); $image ->method('resize') ->willReturnCallback(function ($box) use (&$resultSize) { $resultSize = $box; - }) - ; + }); $loader->load($image, array('max' => array(100, 90))); diff --git a/Tests/Imagine/Filter/Loader/FloatToIntCastByRoundDownscaleFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/FloatToIntCastByRoundDownscaleFilterLoaderTest.php index a7768b525..602ad1ff3 100644 --- a/Tests/Imagine/Filter/Loader/FloatToIntCastByRoundDownscaleFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/FloatToIntCastByRoundDownscaleFilterLoaderTest.php @@ -16,7 +16,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\DownscaleFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\DownscaleFilterLoader * * Due to int casting in Imagine\Image\Box which can lead to wrong pixel * numbers ( e.g. float(201) casted to int(200) ). Solved by round the diff --git a/Tests/Imagine/Filter/Loader/FloatToIntCastByRoundUpscaleFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/FloatToIntCastByRoundUpscaleFilterLoaderTest.php index 3e01e5c47..16b4d726f 100644 --- a/Tests/Imagine/Filter/Loader/FloatToIntCastByRoundUpscaleFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/FloatToIntCastByRoundUpscaleFilterLoaderTest.php @@ -16,7 +16,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader * * Due to int casting in Imagine\Image\Box which can lead to wrong pixel * numbers ( e.g. float(201) casted to int(200) ). Solved by round the diff --git a/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php index 289552e8a..9e5904331 100644 --- a/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php @@ -19,9 +19,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for GrayscaleFilterLoader class. - * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader * * @author Gregoire Humeau */ diff --git a/Tests/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php index 98fa41777..7d971ff8e 100644 --- a/Tests/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/InterlaceFilterLoaderTest.php @@ -15,7 +15,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\InterlaceFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\InterlaceFilterLoader */ class InterlaceFilterLoaderTest extends AbstractTest { @@ -23,7 +23,7 @@ public function testLoad() { $loader = new InterlaceFilterLoader(); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image ->expects($this->once()) ->method('interlace') @@ -32,6 +32,6 @@ public function testLoad() $result = $loader->load($image, array('mode' => 'TEST')); - $this->assertInstanceOf('Imagine\Image\ImageInterface', $result); + $this->assertInstanceOf('\Imagine\Image\ImageInterface', $result); } } diff --git a/Tests/Imagine/Filter/Loader/PasteFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/PasteFilterLoaderTest.php index 7cd8c4e11..746010b05 100644 --- a/Tests/Imagine/Filter/Loader/PasteFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/PasteFilterLoaderTest.php @@ -17,9 +17,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for PasteFilterLoader class. - * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader * * @author Alex Wilson */ @@ -40,7 +38,7 @@ class PasteFilterLoaderTest extends AbstractTest * @param int $y * @param Point $expected * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader::load + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader::load * * @dataProvider pasteProvider */ @@ -50,7 +48,7 @@ public function testLoad($x, $y, $expected) self::DUMMY_IMAGE_WIDTH, self::DUMMY_IMAGE_HEIGHT ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image->method('getSize')->willReturn($mockImageSize); $image->method('copy')->willReturn($image); $image->expects($this->once()) @@ -58,7 +56,7 @@ public function testLoad($x, $y, $expected) ->with($image, $expected) ->willReturn($image); - $imagineMock = $this->createImagineMock(); + $imagineMock = $this->createImagineInterfaceMock(); $imagineMock ->method('open') ->willReturn($image); diff --git a/Tests/Imagine/Filter/Loader/RelativeResizeLoaderTest.php b/Tests/Imagine/Filter/Loader/RelativeResizeLoaderTest.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Tests/Imagine/Filter/Loader/ResizeFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/ResizeFilterLoaderTest.php index f5060ed24..77cb4e7b0 100644 --- a/Tests/Imagine/Filter/Loader/ResizeFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/ResizeFilterLoaderTest.php @@ -16,9 +16,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for ResizeFilterLoader class. - * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader * * @author Alex Wilson */ @@ -28,7 +26,7 @@ class ResizeFilterLoaderTest extends AbstractTest * @param int $width * @param int $height * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader::load + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader::load * * @dataProvider resizeDataProvider */ @@ -36,7 +34,7 @@ public function testLoad($width, $height) { $loader = new ResizeFilterLoader(); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $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 6def5f79b..7fee6f88f 100644 --- a/Tests/Imagine/Filter/Loader/RotateFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/RotateFilterLoaderTest.php @@ -15,9 +15,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for RotateFilterLoader class. - * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\RotateFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\RotateFilterLoader * * @author Bocharsky Victor */ @@ -27,7 +25,7 @@ public function testLoadRotate0Degrees() { $loader = new RotateFilterLoader(); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $result = $loader->load($image, array('angle' => 0)); $this->assertSame($image, $result); @@ -37,8 +35,8 @@ public function testLoadRotate90Degrees() { $loader = new RotateFilterLoader(); - $image = $this->getMockImage(); - $rotatedImage = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); + $rotatedImage = $this->getImageInterfaceMock(); $image ->expects($this->once()) diff --git a/Tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php index 98232bc61..da9d3eaf7 100644 --- a/Tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php @@ -17,9 +17,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for ScaleFilterLoader class. - * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader * * @author Alex Wilson */ @@ -51,7 +49,7 @@ protected function getUpscaleMockImage() self::UPSCALE_DUMMY_IMAGE_WIDTH, self::UPSCALE_DUMMY_IMAGE_HEIGHT ); - $mockImage = parent::getMockImage(); + $mockImage = parent::getImageInterfaceMock(); $mockImage->method('getSize')->willReturn(new Box( self::UPSCALE_DUMMY_IMAGE_WIDTH, self::UPSCALE_DUMMY_IMAGE_HEIGHT @@ -60,13 +58,13 @@ protected function getUpscaleMockImage() return $mockImage; } - protected function getMockImage() + protected function getImageInterfaceMock() { $mockImageSize = new Box( self::DUMMY_IMAGE_WIDTH, self::DUMMY_IMAGE_HEIGHT ); - $mockImage = parent::getMockImage(); + $mockImage = parent::getImageInterfaceMock(); $mockImage->method('getSize')->willReturn(new Box( self::DUMMY_IMAGE_WIDTH, self::DUMMY_IMAGE_HEIGHT @@ -76,12 +74,12 @@ protected function getMockImage() } /** - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader::load + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader::load */ public function testItShouldPreserveRatio() { $loader = new ScaleFilterLoader(); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image->expects($this->once()) ->method('resize') ->with(new Box( @@ -99,7 +97,7 @@ public function testItShouldPreserveRatio() * @param int[] $dimension * @param Box $expected * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader::load + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader::load * * @dataProvider dimensionsDataProvider */ @@ -107,7 +105,7 @@ public function testItShouldUseDimensions($dimensions, $expected) { $loader = new ScaleFilterLoader(); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image->expects($this->once()) ->method('resize') ->with($expected) @@ -121,14 +119,14 @@ public function testItShouldUseDimensions($dimensions, $expected) } /** - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader::load + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader::load * * @expectedException \InvalidArgumentException */ public function itShouldThrowInvalidArgumentException() { $scale = new ScaleFilterLoader('foo', 'bar'); - $scale->load($this->getMockImage(), array()); + $scale->load($this->getImageInterfaceMock(), array()); } /** diff --git a/Tests/Imagine/Filter/Loader/ThumbnailFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/ThumbnailFilterLoaderTest.php index 64079ace1..8e75ceb7a 100644 --- a/Tests/Imagine/Filter/Loader/ThumbnailFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/ThumbnailFilterLoaderTest.php @@ -16,9 +16,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for ThumbnailFilterLoader class. - * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader * * @author Alex Wilson */ @@ -39,7 +37,7 @@ class ThumbnailFilterLoaderTest extends AbstractTest * @param int $height * @param Box $expected * - * @covers Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader::load + * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader::load * * @dataProvider heightWidthProvider */ @@ -51,7 +49,7 @@ public function testLoad($width, $height, $expected) self::DUMMY_IMAGE_WIDTH, self::DUMMY_IMAGE_HEIGHT ); - $image = $this->getMockImage(); + $image = $this->getImageInterfaceMock(); $image->method('getSize')->willReturn($mockImageSize); $image->method('copy')->willReturn($image); $image->expects($this->once()) diff --git a/Tests/LiipImagineBundleTest.php b/Tests/LiipImagineBundleTest.php index 70a7c4606..288a5cbeb 100644 --- a/Tests/LiipImagineBundleTest.php +++ b/Tests/LiipImagineBundleTest.php @@ -11,12 +11,14 @@ namespace Liip\ImagineBundle\Tests; +use Liip\ImagineBundle\DependencyInjection\LiipImagineExtension; use Liip\ImagineBundle\LiipImagineBundle; +use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @covers \Liip\ImagineBundle\LiipImagineBundle */ -class LiipImagineBundleTest extends \Phpunit_Framework_TestCase +class LiipImagineBundleTest extends AbstractTest { public function testSubClassOfBundle() { @@ -30,7 +32,7 @@ public function testLocatorsCompilerPassOnBuild() ->expects($this->atLeastOnce()) ->method('getExtension') ->with('liip_imagine') - ->will($this->returnValue($this->createExtensionMock())); + ->will($this->returnValue($this->createLiipImagineExtensionMock())); $containerMock ->expects($this->at(0)) ->method('addCompilerPass') @@ -47,7 +49,7 @@ public function testAddLoadersCompilerPassOnBuild() ->expects($this->atLeastOnce()) ->method('getExtension') ->with('liip_imagine') - ->will($this->returnValue($this->createExtensionMock())); + ->will($this->returnValue($this->createLiipImagineExtensionMock())); $containerMock ->expects($this->at(1)) ->method('addCompilerPass') @@ -64,7 +66,7 @@ public function testAddFiltersCompilerPassOnBuild() ->expects($this->atLeastOnce()) ->method('getExtension') ->with('liip_imagine') - ->will($this->returnValue($this->createExtensionMock())); + ->will($this->returnValue($this->createLiipImagineExtensionMock())); $containerMock ->expects($this->at(2)) ->method('addCompilerPass') @@ -81,7 +83,7 @@ public function testAddPostProcessorsCompilerPassOnBuild() ->expects($this->atLeastOnce()) ->method('getExtension') ->with('liip_imagine') - ->will($this->returnValue($this->createExtensionMock())); + ->will($this->returnValue($this->createLiipImagineExtensionMock())); $containerMock ->expects($this->at(3)) ->method('addCompilerPass') @@ -98,7 +100,7 @@ public function testAddResolversCompilerPassOnBuild() ->expects($this->atLeastOnce()) ->method('getExtension') ->with('liip_imagine') - ->will($this->returnValue($this->createExtensionMock())); + ->will($this->returnValue($this->createLiipImagineExtensionMock())); $containerMock ->expects($this->at(4)) ->method('addCompilerPass') @@ -110,7 +112,7 @@ public function testAddResolversCompilerPassOnBuild() public function testAddWebPathResolverFactoryOnBuild() { - $extensionMock = $this->createExtensionMock(); + $extensionMock = $this->createLiipImagineExtensionMock(); $extensionMock ->expects($this->at(0)) ->method('addResolverFactory') @@ -129,7 +131,7 @@ public function testAddWebPathResolverFactoryOnBuild() public function testAddAwsS3ResolverFactoryOnBuild() { - $extensionMock = $this->createExtensionMock(); + $extensionMock = $this->createLiipImagineExtensionMock(); $extensionMock ->expects($this->at(1)) ->method('addResolverFactory') @@ -148,7 +150,7 @@ public function testAddAwsS3ResolverFactoryOnBuild() public function testAddFlysystemResolverFactoryOnBuild() { - $extensionMock = $this->createExtensionMock(); + $extensionMock = $this->createLiipImagineExtensionMock(); $extensionMock ->expects($this->at(2)) ->method('addResolverFactory') @@ -167,7 +169,7 @@ public function testAddFlysystemResolverFactoryOnBuild() public function testAddStreamLoaderFactoryOnBuild() { - $extensionMock = $this->createExtensionMock(); + $extensionMock = $this->createLiipImagineExtensionMock(); $extensionMock ->expects($this->at(3)) ->method('addLoaderFactory') @@ -186,7 +188,7 @@ public function testAddStreamLoaderFactoryOnBuild() public function testAddFilesystemLoaderFactoryOnBuild() { - $extensionMock = $this->createExtensionMock(); + $extensionMock = $this->createLiipImagineExtensionMock(); $extensionMock ->expects($this->at(4)) ->method('addLoaderFactory') @@ -205,7 +207,7 @@ public function testAddFilesystemLoaderFactoryOnBuild() public function testAddFlysystemLoaderFactoryOnBuild() { - $extensionMock = $this->createExtensionMock(); + $extensionMock = $this->createLiipImagineExtensionMock(); $extensionMock ->expects($this->at(5)) ->method('addLoaderFactory') @@ -222,19 +224,23 @@ public function testAddFlysystemLoaderFactoryOnBuild() $bundle->build($containerMock); } + /** + * @return \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder + */ protected function createContainerBuilderMock() { - return $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array(), array(), '', false); + return $this->createObjectMock('Symfony\Component\DependencyInjection\ContainerBuilder', array(), false); } - protected function createExtensionMock() + /** + * @return \PHPUnit_Framework_MockObject_MockObject|LiipImagineExtension + */ + protected function createLiipImagineExtensionMock() { - $methods = array( + return $this->createObjectMock('Liip\ImagineBundle\DependencyInjection\LiipImagineExtension', array( 'getNamespace', 'addResolverFactory', 'addLoaderFactory', - ); - - return $this->getMock('Liip\ImagineBundle\DependencyInjection\LiipImagineExtension', $methods, array(), '', false); + ), false); } } diff --git a/Tests/Model/BinaryTest.php b/Tests/Model/BinaryTest.php index 8be314a62..4033a1ff0 100644 --- a/Tests/Model/BinaryTest.php +++ b/Tests/Model/BinaryTest.php @@ -14,15 +14,15 @@ use Liip\ImagineBundle\Model\Binary; /** - * @covers Liip\ImagineBundle\Model\Binary + * @covers \Liip\ImagineBundle\Model\Binary */ class BinaryTest extends \PHPUnit_Framework_TestCase { public function testImplementsBinaryInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Model\Binary'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\Model\Binary'); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Binary\BinaryInterface')); + $this->assertTrue($rc->implementsInterface('\Liip\ImagineBundle\Binary\BinaryInterface')); } public function testAllowGetContentSetInConstructor() diff --git a/Tests/Templating/Helper/ImagineHelperTest.php b/Tests/Templating/Helper/ImagineHelperTest.php index 651f124f8..a2a4f9b86 100644 --- a/Tests/Templating/Helper/ImagineHelperTest.php +++ b/Tests/Templating/Helper/ImagineHelperTest.php @@ -11,19 +11,19 @@ namespace Liip\ImagineBundle\Tests\Templating\Helper; -use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Templating\Helper\ImagineHelper; +use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Templating\Helper\ImagineHelper + * @covers \Liip\ImagineBundle\Templating\Helper\ImagineHelper */ -class ImagineHelperTest extends \PHPUnit_Framework_TestCase +class ImagineHelperTest extends AbstractTest { public function testSubClassOfHelper() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Templating\Helper\ImagineHelper'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\Templating\Helper\ImagineHelper'); - $this->assertTrue($rc->isSubclassOf('Symfony\Component\Templating\Helper\Helper')); + $this->assertTrue($rc->isSubclassOf('\Symfony\Component\Templating\Helper\Helper')); } public function testCouldBeConstructedWithCacheManagerAsArgument() @@ -49,19 +49,10 @@ public function testProxyCallToCacheManagerOnFilter() ->expects($this->once()) ->method('getBrowserPath') ->with($expectedPath, $expectedFilter) - ->will($this->returnValue($expectedCachePath)) - ; + ->will($this->returnValue($expectedCachePath)); $helper = new ImagineHelper($cacheManager); $this->assertEquals($expectedCachePath, $helper->filter($expectedPath, $expectedFilter)); } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|CacheManager - */ - protected function createCacheManagerMock() - { - return $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array(), array(), '', false); - } } diff --git a/Tests/Templating/ImagineExtensionTest.php b/Tests/Templating/ImagineExtensionTest.php index f357a83cd..1d3ce5629 100644 --- a/Tests/Templating/ImagineExtensionTest.php +++ b/Tests/Templating/ImagineExtensionTest.php @@ -13,17 +13,18 @@ use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Templating\ImagineExtension; +use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Templating\ImagineExtension + * @covers \Liip\ImagineBundle\Templating\ImagineExtension */ -class ImagineExtensionTest extends \PHPUnit_Framework_TestCase +class ImagineExtensionTest extends AbstractTest { public function testSubClassOfHelper() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Templating\ImagineExtension'); + $rc = new \ReflectionClass('\Liip\ImagineBundle\Templating\ImagineExtension'); - $this->assertTrue($rc->isSubclassOf('Twig_Extension')); + $this->assertTrue($rc->isSubclassOf('\Twig_Extension')); } public function testCouldBeConstructedWithCacheManagerAsArgument() @@ -49,8 +50,7 @@ public function testProxyCallToCacheManagerOnFilter() ->expects($this->once()) ->method('getBrowserPath') ->with($expectedPath, $expectedFilter) - ->will($this->returnValue($expectedCachePath)) - ; + ->will($this->returnValue($expectedCachePath)); $extension = new ImagineExtension($cacheManager); @@ -66,12 +66,4 @@ public function testAddsFilterMethodToFiltersList() $this->assertInternalType('array', $filters); $this->assertCount(1, $filters); } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|CacheManager - */ - protected function createCacheManagerMock() - { - return $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array(), array(), '', false); - } } diff --git a/composer.json b/composer.json index 3cd2d79a6..79e1f97a7 100644 --- a/composer.json +++ b/composer.json @@ -30,13 +30,13 @@ "symfony/translation": "~2.3|~3.0" }, "require-dev": { + "ext-gd": "*", "amazonwebservices/aws-sdk-for-php": "~1.0", "aws/aws-sdk-php": "~2.4", "doctrine/cache": "~1.1", "doctrine/orm": "~2.3", - "ext-gd": "*", "friendsofphp/php-cs-fixer": "~2.0", - "phpunit/phpunit": "~4.3", + "phpunit/phpunit": "~4.3|~5.0", "psr/log": "~1.0", "satooshi/php-coveralls": "~1.0", "sllh/php-cs-fixer-styleci-bridge": "~2.1", @@ -50,16 +50,16 @@ "twig/twig": "~1.12|~2.0" }, "suggest": { - "alcaeus/mongo-php-adapter": "required on PHP >= 7.0 to use mongo components with mongodb extension", - "amazonwebservices/aws-sdk-for-php": "required to use AWS version 1 cache resolver", - "aws/aws-sdk-php": "required to use AWS version 2/3 cache resolver", - "doctrine/mongodb-odm": "required to use mongodb-backed doctrine components", "ext-exif": "required to read EXIF metadata from images", "ext-gd": "required to use gd driver", "ext-gmagick": "required to use gmagick driver", "ext-imagick": "required to use imagick driver", "ext-mongo": "required for mongodb components on PHP <7.0", "ext-mongodb": "required for mongodb components on PHP >=7.0", + "alcaeus/mongo-php-adapter": "required on PHP >= 7.0 to use mongo components with mongodb extension", + "amazonwebservices/aws-sdk-for-php": "required to use AWS version 1 cache resolver", + "aws/aws-sdk-php": "required to use AWS version 2/3 cache resolver", + "doctrine/mongodb-odm": "required to use mongodb-backed doctrine components", "league/flysystem": "required to use FlySystem data loader or cache resolver", "monolog/monolog": "A psr/log compatible logger is required to enable logging", "twig/twig": "required to use the provided Twig extension. Version 1.12 or greater needed"