From 59fb67dc46cdd0074764dbdeb65d9b05f75db0e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Scho=CC=88nthal?= Date: Fri, 25 Apr 2014 13:05:01 +0200 Subject: [PATCH] added a bunch of tests and covers annotations --- .travis.yml | 2 + Binary/Loader/AbstractDoctrineLoader.php | 5 +- Binary/Loader/ExtendedFileSystemLoader.php | 44 ----------- Binary/Loader/FileSystemLoader.php | 1 - Command/RemoveCacheCommand.php | 1 + Command/ResolveCacheCommand.php | 3 + Imagine/Data/Transformer/PdfTransformer.php | 38 ---------- ImagineEvents.php | 6 +- .../Loader/AbstractDoctrineLoaderTest.php | 76 +++++++++++++++++++ Tests/Binary/Loader/FileSystemLoaderTest.php | 6 +- Tests/Binary/Loader/GridFSLoaderTest.php | 55 ++++++++++++++ Tests/Binary/Loader/StreamLoaderTest.php | 2 +- Tests/Binary/SimpleMimeTypeGuesserTest.php | 3 + .../Compiler/FiltersCompilerPassTest.php | 33 ++++++++ .../Compiler/LoadersCompilerPassTest.php | 33 ++++++++ .../Compiler/ResolversCompilerPassTest.php | 33 ++++++++ .../DependencyInjection/ConfigurationTest.php | 3 + .../Loader/FileSystemLoaderFactoryTest.php | 3 + .../Loader/StreamLoaderFactoryTest.php | 3 + .../Resolver/AwsS3ResolverFactoryTest.php | 3 + .../Resolver/WebPathResolverFactoryTest.php | 3 + Tests/Events/CacheResolveEventTest.php | 2 +- .../Resolver/NotResolvableExceptionTest.php | 13 +++- .../Resolver/NotStorableExceptionTest.php | 13 +++- Tests/Form/Type/ImageTypeTest.php | 68 +++++++++++++++++ Tests/Functional/Command/RemoveCacheTest.php | 3 + Tests/Functional/Command/ResolveCacheTest.php | 3 + .../Cache/Resolver/ProxyResolverTest.php | 5 +- .../Data/Transformer/PdfTransformerTest.php | 54 ------------- Tests/LiipImagineBundleTest.php | 14 +--- Tests/Model/BinaryTest.php | 3 + composer.json | 3 + 32 files changed, 364 insertions(+), 173 deletions(-) delete mode 100644 Binary/Loader/ExtendedFileSystemLoader.php delete mode 100644 Imagine/Data/Transformer/PdfTransformer.php create mode 100644 Tests/Binary/Loader/AbstractDoctrineLoaderTest.php create mode 100644 Tests/Binary/Loader/GridFSLoaderTest.php create mode 100644 Tests/DependencyInjection/Compiler/FiltersCompilerPassTest.php create mode 100644 Tests/DependencyInjection/Compiler/LoadersCompilerPassTest.php create mode 100644 Tests/DependencyInjection/Compiler/ResolversCompilerPassTest.php create mode 100644 Tests/Form/Type/ImageTypeTest.php delete mode 100644 Tests/Imagine/Data/Transformer/PdfTransformerTest.php diff --git a/.travis.yml b/.travis.yml index 97a81a44b..8e914f24b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,8 @@ env: - SYMFONY_VERSION=2.3.* before_script: + - yes '' | pecl -q install -f mongo + - composer self-update - composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source - composer install --dev --prefer-source diff --git a/Binary/Loader/AbstractDoctrineLoader.php b/Binary/Loader/AbstractDoctrineLoader.php index f65189560..1b0d418b8 100644 --- a/Binary/Loader/AbstractDoctrineLoader.php +++ b/Binary/Loader/AbstractDoctrineLoader.php @@ -57,10 +57,7 @@ public function find($path) $info = pathinfo($path); $name = $info['dirname'].'/'.$info['filename']; - // maybe the image has an id without extension - if (!$image) { - $image = $this->manager->find($this->class, $this->mapPathToId($name)); - } + $image = $this->manager->find($this->class, $this->mapPathToId($name)); } if (!$image) { diff --git a/Binary/Loader/ExtendedFileSystemLoader.php b/Binary/Loader/ExtendedFileSystemLoader.php deleted file mode 100644 index ef2a8eed7..000000000 --- a/Binary/Loader/ExtendedFileSystemLoader.php +++ /dev/null @@ -1,44 +0,0 @@ -transformers = $transformers; - } - - /** - * Apply transformers to the file. - * - * @param $absolutePath - * - * @return array - */ - protected function getFileInfo($absolutePath) - { - if (!empty($this->transformers)) { - foreach ($this->transformers as $transformer) { - $absolutePath = $transformer->apply($absolutePath); - } - } - - return pathinfo($absolutePath); - } -} diff --git a/Binary/Loader/FileSystemLoader.php b/Binary/Loader/FileSystemLoader.php index 959e7b975..f8210c710 100644 --- a/Binary/Loader/FileSystemLoader.php +++ b/Binary/Loader/FileSystemLoader.php @@ -3,7 +3,6 @@ namespace Liip\ImagineBundle\Binary\Loader; use Liip\ImagineBundle\Model\Binary; -use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser; use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; diff --git a/Command/RemoveCacheCommand.php b/Command/RemoveCacheCommand.php index bdf562e44..df1fa9e7c 100644 --- a/Command/RemoveCacheCommand.php +++ b/Command/RemoveCacheCommand.php @@ -2,6 +2,7 @@ namespace Liip\ImagineBundle\Command; +use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; diff --git a/Command/ResolveCacheCommand.php b/Command/ResolveCacheCommand.php index 81ff0c7b7..f62dde2c1 100644 --- a/Command/ResolveCacheCommand.php +++ b/Command/ResolveCacheCommand.php @@ -2,6 +2,9 @@ namespace Liip\ImagineBundle\Command; +use Liip\ImagineBundle\Imagine\Cache\CacheManager; +use Liip\ImagineBundle\Imagine\Data\DataManager; +use Liip\ImagineBundle\Imagine\Filter\FilterManager; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; diff --git a/Imagine/Data/Transformer/PdfTransformer.php b/Imagine/Data/Transformer/PdfTransformer.php deleted file mode 100644 index 5d0e2acaa..000000000 --- a/Imagine/Data/Transformer/PdfTransformer.php +++ /dev/null @@ -1,38 +0,0 @@ -imagick = $imagick; - } - - /** - * {@inheritDoc} - */ - public function apply($absolutePath) - { - $info = pathinfo($absolutePath); - - if (isset($info['extension']) && false !== strpos(strtolower($info['extension']), 'pdf')) { - // If it doesn't exists, extract the first page of the PDF - if (!file_exists("$absolutePath.png")) { - $this->imagick->readImage($absolutePath.'[0]'); - $this->imagick->setImageFormat('png'); - $this->imagick->writeImage("$absolutePath.png"); - $this->imagick->clear(); - } - - $absolutePath .= '.png'; - } - - return $absolutePath; - } -} diff --git a/ImagineEvents.php b/ImagineEvents.php index cce7bb1cf..c16780d8b 100644 --- a/ImagineEvents.php +++ b/ImagineEvents.php @@ -2,13 +2,9 @@ namespace Liip\ImagineBundle; -final class ImagineEvents +interface ImagineEvents { const PRE_RESOLVE = 'liip_imagine.pre_resolve'; const POST_RESOLVE = 'liip_imagine.post_resolve'; - - private function __construct() - { - } } diff --git a/Tests/Binary/Loader/AbstractDoctrineLoaderTest.php b/Tests/Binary/Loader/AbstractDoctrineLoaderTest.php new file mode 100644 index 000000000..cc2526c7c --- /dev/null +++ b/Tests/Binary/Loader/AbstractDoctrineLoaderTest.php @@ -0,0 +1,76 @@ + + */ +class AbstractDoctrineLoaderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ObjectRepository + */ + private $om; + + /** + * @var 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(); + } + + 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->om->expects($this->atLeastOnce())->method('find')->with(null, 1337)->will($this->returnValue($image)); + + $this->assertEquals('foo', $this->loader->find('/foo/bar')); + } + + 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->assertEquals('foo', $this->loader->find('/foo/bar.png')); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + */ + 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->find('/foo/bar'); + } +} + \ No newline at end of file diff --git a/Tests/Binary/Loader/FileSystemLoaderTest.php b/Tests/Binary/Loader/FileSystemLoaderTest.php index 087374f10..25d51cb9f 100644 --- a/Tests/Binary/Loader/FileSystemLoaderTest.php +++ b/Tests/Binary/Loader/FileSystemLoaderTest.php @@ -3,12 +3,12 @@ namespace Liip\ImagineBundle\Tests\Binary\Loader; use Liip\ImagineBundle\Binary\Loader\FileSystemLoader; -use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser; -use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; -use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; +/** + * @covers Liip\ImagineBundle\Binary\Loader\FileSystemLoader + */ class FileSystemLoaderTest extends \PHPUnit_Framework_TestCase { public static function provideLoadCases() diff --git a/Tests/Binary/Loader/GridFSLoaderTest.php b/Tests/Binary/Loader/GridFSLoaderTest.php new file mode 100644 index 000000000..b495a8acb --- /dev/null +++ b/Tests/Binary/Loader/GridFSLoaderTest.php @@ -0,0 +1,55 @@ + + */ +class GridFSLoaderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var DocumentRepository + */ + private $repo; + + /** + * @var GridFSLoader + */ + private $loader; + + public function setUp() + { + $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)); + + $this->loader = new GridFSLoader($dm, '\Foo\Bar'); + } + + public function testFindWithValidDocument() + { + $image = new GridFSFile(); + $image->setBytes('01010101'); + + $this->repo->expects($this->atLeastOnce())->method('find')->with($this->isInstanceOf('\MongoId'))->will($this->returnValue(array('file'=>$image))); + + $this->assertEquals('01010101', $this->loader->find('0123456789abcdef01234567')); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + */ + public function testFindWithInValidDocument() + { + $this->repo->expects($this->atLeastOnce())->method('find')->with($this->isInstanceOf('\MongoId'))->will($this->returnValue(null)); + + $this->loader->find('0123456789abcdef01234567'); + } +} + \ No newline at end of file diff --git a/Tests/Binary/Loader/StreamLoaderTest.php b/Tests/Binary/Loader/StreamLoaderTest.php index 09e640198..167419b0a 100644 --- a/Tests/Binary/Loader/StreamLoaderTest.php +++ b/Tests/Binary/Loader/StreamLoaderTest.php @@ -6,7 +6,7 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * @covers Liip\ImagineBundle\Binary\Loader\StreamLoader + * @covers Liip\ImagineBundle\Binary\Loader\StreamLoader */ class StreamLoaderTest extends AbstractTest { diff --git a/Tests/Binary/SimpleMimeTypeGuesserTest.php b/Tests/Binary/SimpleMimeTypeGuesserTest.php index 5313a0164..0c8bdbcbe 100644 --- a/Tests/Binary/SimpleMimeTypeGuesserTest.php +++ b/Tests/Binary/SimpleMimeTypeGuesserTest.php @@ -4,6 +4,9 @@ use Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; +/** + * @covers Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser + */ class SimpleMimeTypeGuesserTest extends \PHPUnit_Framework_TestCase { public function provideImages() diff --git a/Tests/DependencyInjection/Compiler/FiltersCompilerPassTest.php b/Tests/DependencyInjection/Compiler/FiltersCompilerPassTest.php new file mode 100644 index 000000000..0e119998c --- /dev/null +++ b/Tests/DependencyInjection/Compiler/FiltersCompilerPassTest.php @@ -0,0 +1,33 @@ +getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); + + $cb->expects($this->atLeastOnce())->method('hasDefinition')->with('liip_imagine.filter.manager')->will($this->returnValue(true)); + $cb->expects($this->atLeastOnce())->method('getDefinition')->with('liip_imagine.filter.manager')->will($this->returnValue($d)); + + $cb->expects($this->atLeastOnce())->method('findTaggedServiceIds')->with('liip_imagine.filter.loader')->will($this->returnValue(array( + 'a' => array(array('loader'=>'foo')) + ))); + + $pass = new FiltersCompilerPass(); + + $pass->process($cb); + + $this->assertCount(1,$d->getMethodCalls()); + } +} + \ No newline at end of file diff --git a/Tests/DependencyInjection/Compiler/LoadersCompilerPassTest.php b/Tests/DependencyInjection/Compiler/LoadersCompilerPassTest.php new file mode 100644 index 000000000..6da44c966 --- /dev/null +++ b/Tests/DependencyInjection/Compiler/LoadersCompilerPassTest.php @@ -0,0 +1,33 @@ +getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); + + $cb->expects($this->atLeastOnce())->method('hasDefinition')->with('liip_imagine.data.manager')->will($this->returnValue(true)); + $cb->expects($this->atLeastOnce())->method('getDefinition')->with('liip_imagine.data.manager')->will($this->returnValue($d)); + + $cb->expects($this->atLeastOnce())->method('findTaggedServiceIds')->with('liip_imagine.binary.loader')->will($this->returnValue(array( + 'a' => array(array('loader'=>'foo')) + ))); + + $pass = new LoadersCompilerPass(); + + $pass->process($cb); + + $this->assertCount(1,$d->getMethodCalls()); + } +} + \ No newline at end of file diff --git a/Tests/DependencyInjection/Compiler/ResolversCompilerPassTest.php b/Tests/DependencyInjection/Compiler/ResolversCompilerPassTest.php new file mode 100644 index 000000000..68c3e90e7 --- /dev/null +++ b/Tests/DependencyInjection/Compiler/ResolversCompilerPassTest.php @@ -0,0 +1,33 @@ +getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); + + $cb->expects($this->atLeastOnce())->method('hasDefinition')->with('liip_imagine.cache.manager')->will($this->returnValue(true)); + $cb->expects($this->atLeastOnce())->method('getDefinition')->with('liip_imagine.cache.manager')->will($this->returnValue($d)); + + $cb->expects($this->atLeastOnce())->method('findTaggedServiceIds')->with('liip_imagine.cache.resolver')->will($this->returnValue(array( + 'a' => array(array('resolver'=>'foo')) + ))); + + $pass = new ResolversCompilerPass(); + + $pass->process($cb); + + $this->assertCount(1,$d->getMethodCalls()); + } +} + \ No newline at end of file diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index f64e4a8bc..981f2a13c 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -11,6 +11,9 @@ use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** + * @covers Liip\ImagineBundle\DependencyInjection\Configuration + */ class ConfigurationTest extends \Phpunit_Framework_TestCase { public function testImplementsConfigurationInterface() diff --git a/Tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php b/Tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php index 673e390fc..314d291cf 100644 --- a/Tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php @@ -6,6 +6,9 @@ use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** + * @covers Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory + */ class FileSystemLoaderFactoryTest extends \Phpunit_Framework_TestCase { public function testImplementsLoaderFactoryInterface() diff --git a/Tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php b/Tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php index fb01f8368..4da27e848 100644 --- a/Tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php @@ -6,6 +6,9 @@ use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** + * @covers Liip\ImagineBundle\DependencyInjection\Factory\Loader\StreamLoaderFactory + */ class StreamLoaderFactoryTest extends \Phpunit_Framework_TestCase { public function testImplementsLoaderFactoryInterface() diff --git a/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php b/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php index 226a1fd4a..22f83a0de 100644 --- a/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php @@ -6,6 +6,9 @@ use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** + * @covers Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory + */ class AwsS3ResolverFactoryTest extends \Phpunit_Framework_TestCase { public function testImplementsResolverFactoryInterface() diff --git a/Tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php b/Tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php index 7ca8f2197..3eafdf638 100644 --- a/Tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php @@ -6,6 +6,9 @@ use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** + * @covers Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory + */ class WebPathResolverFactoryTest extends \Phpunit_Framework_TestCase { public function testImplementsResolverFactoryInterface() diff --git a/Tests/Events/CacheResolveEventTest.php b/Tests/Events/CacheResolveEventTest.php index 41e826345..2b639e5f5 100644 --- a/Tests/Events/CacheResolveEventTest.php +++ b/Tests/Events/CacheResolveEventTest.php @@ -4,7 +4,7 @@ use Liip\ImagineBundle\Events\CacheResolveEvent; /** - * Test class for 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 d2d6cb6c4..7e3ba6927 100644 --- a/Tests/Exception/Imagine/Cache/Resolver/NotResolvableExceptionTest.php +++ b/Tests/Exception/Imagine/Cache/Resolver/NotResolvableExceptionTest.php @@ -2,19 +2,24 @@ namespace Liip\ImagineBundle\Tests\Exception\Imagine\Cache\Resolver; +use Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException; + +/** + * @covers Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException + */ class NotResolvableExceptionTest extends \PHPUnit_Framework_TestCase { public function testSubClassOfRuntimeException() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException'); + $e = new NotResolvableException(); - $this->assertTrue($rc->isSubclassOf('RuntimeException')); + $this->assertInstanceOf('\RuntimeException', $e); } public function testImplementsExceptionInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException'); + $e = new NotResolvableException(); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Exception\ExceptionInterface')); + $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 46c36c279..1db0eecc8 100644 --- a/Tests/Exception/Imagine/Cache/Resolver/NotStorableExceptionTest.php +++ b/Tests/Exception/Imagine/Cache/Resolver/NotStorableExceptionTest.php @@ -2,19 +2,24 @@ namespace Liip\ImagineBundle\Tests\Exception\Imagine\Cache\Resolver; +use Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException; + +/** + * @covers Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException + */ class NotStorableExceptionTest extends \PHPUnit_Framework_TestCase { public function testSubClassOfRuntimeException() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException'); + $e = new NotStorableException(); - $this->assertTrue($rc->isSubclassOf('RuntimeException')); + $this->assertInstanceOf('\RuntimeException',$e); } public function testImplementsExceptionInterface() { - $rc = new \ReflectionClass('Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException'); + $e = new NotStorableException(); - $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Exception\ExceptionInterface')); + $this->assertInstanceOf('Liip\ImagineBundle\Exception\ExceptionInterface',$e); } } diff --git a/Tests/Form/Type/ImageTypeTest.php b/Tests/Form/Type/ImageTypeTest.php new file mode 100644 index 000000000..abad42569 --- /dev/null +++ b/Tests/Form/Type/ImageTypeTest.php @@ -0,0 +1,68 @@ +assertEquals('liip_imagine_image', $type->getName()); + } + + public function testGetParent() + { + $type = new ImageType(); + + $this->assertEquals('file', $type->getParent()); + } + + public function testSetDefaultOptions() + { + $resolver = new OptionsResolver(); + $type = new ImageType(); + + $type->setDefaultOptions($resolver); + + $this->assertTrue($resolver->isRequired('image_path')); + $this->assertTrue($resolver->isRequired('image_filter')); + + $this->assertTrue($resolver->isKnown('image_attr')); + $this->assertTrue($resolver->isKnown('link_url')); + $this->assertTrue($resolver->isKnown('link_filter')); + $this->assertTrue($resolver->isKnown('link_attr')); + } + + public function testBuildView() + { + $options = array( + 'image_path' => 'foo', + 'image_filter' => 'bar', + 'image_attr' => 'bazz', + 'link_url' => 'http://liip.com', + 'link_filter' => 'foo', + 'link_attr' => 'bazz' + ); + + $view = new FormView(); + $type = new ImageType(); + $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); + + $type->buildView($view, $form, $options); + + foreach ($options as $name => $value) { + $this->assertArrayHasKey($name, $view->vars); + $this->assertEquals($value, $view->vars[$name]); + } + } +} + \ No newline at end of file diff --git a/Tests/Functional/Command/RemoveCacheTest.php b/Tests/Functional/Command/RemoveCacheTest.php index a0499161c..681236839 100644 --- a/Tests/Functional/Command/RemoveCacheTest.php +++ b/Tests/Functional/Command/RemoveCacheTest.php @@ -10,6 +10,9 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; +/** + * @covers Liip\ImagineBundle\Command\RemoveCacheCommand + */ class RemoveCacheTest extends WebTestCase { protected $client; diff --git a/Tests/Functional/Command/ResolveCacheTest.php b/Tests/Functional/Command/ResolveCacheTest.php index c18a9acc7..369237d4f 100644 --- a/Tests/Functional/Command/ResolveCacheTest.php +++ b/Tests/Functional/Command/ResolveCacheTest.php @@ -10,6 +10,9 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; +/** + * @covers Liip\ImagineBundle\Command\ResolveCacheCommand + */ class ResolveCacheTest extends WebTestCase { protected $client; diff --git a/Tests/Imagine/Cache/Resolver/ProxyResolverTest.php b/Tests/Imagine/Cache/Resolver/ProxyResolverTest.php index 9ac5cccca..9c17b4126 100644 --- a/Tests/Imagine/Cache/Resolver/ProxyResolverTest.php +++ b/Tests/Imagine/Cache/Resolver/ProxyResolverTest.php @@ -5,11 +5,8 @@ use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; use Liip\ImagineBundle\Model\Binary; - /** - * ProxyResolverTest - * - * @author Robert Schönthal + * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver */ class ProxyResolverTest extends \Phpunit_Framework_TestCase { diff --git a/Tests/Imagine/Data/Transformer/PdfTransformerTest.php b/Tests/Imagine/Data/Transformer/PdfTransformerTest.php deleted file mode 100644 index b582eb317..000000000 --- a/Tests/Imagine/Data/Transformer/PdfTransformerTest.php +++ /dev/null @@ -1,54 +0,0 @@ -markTestSkipped('Imagick is not available.'); - } - - parent::setUp(); - } - - public function testApplyWritesPng() - { - $pdfFilename = $this->tempDir.'/cats.pdf'; - $pngFilename = $pdfFilename.'.png'; - - $pdf = $this->fixturesDir.'/assets/cats.pdf'; - $this->filesystem->copy($pdf, $pdfFilename); - $this->assertTrue(file_exists($pdfFilename)); - - $transformer = new PdfTransformer(new \Imagick()); - $absolutePath = $transformer->apply($pdfFilename); - - $this->assertEquals($pngFilename, $absolutePath); - $this->assertTrue(file_exists($pngFilename)); - $this->assertNotEmpty(file_get_contents($pngFilename)); - } - - public function testApplyDoesNotOverwriteExisting() - { - $pdfFilename = $this->tempDir.'/cats.pdf'; - $pngFilename = $pdfFilename.'.png'; - $this->filesystem->touch(array( - $pdfFilename, - $pngFilename, - )); - - $transformer = new PdfTransformer(new \Imagick()); - $absolutePath = $transformer->apply($pdfFilename); - - $this->assertEquals($pngFilename, $absolutePath); - $this->assertEmpty(file_get_contents($pngFilename)); - } -} diff --git a/Tests/LiipImagineBundleTest.php b/Tests/LiipImagineBundleTest.php index 2f88b567a..cc1131ee1 100644 --- a/Tests/LiipImagineBundleTest.php +++ b/Tests/LiipImagineBundleTest.php @@ -1,22 +1,16 @@ assertTrue($rc->isSubclassOf('Symfony\Component\HttpKernel\Bundle\Bundle')); - } - - public function testCouldBeConstructedWithoutAnyArguments() - { - new LiipImagineBundle; + $this->assertInstanceOf('Symfony\Component\HttpKernel\Bundle\Bundle', new LiipImagineBundle()); } public function testAddLoadersCompilerPassOnBuild() diff --git a/Tests/Model/BinaryTest.php b/Tests/Model/BinaryTest.php index e2d8c64d0..46e7fe163 100644 --- a/Tests/Model/BinaryTest.php +++ b/Tests/Model/BinaryTest.php @@ -3,6 +3,9 @@ use Liip\ImagineBundle\Model\Binary; +/** + * @covers Liip\ImagineBundle\Model\Binary + */ class BinaryTest extends \PHPUnit_Framework_TestCase { public function testImplementsBinaryInterface() diff --git a/composer.json b/composer.json index 1097c5caa..cafa8da29 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,10 @@ "require-dev": { "phpunit/phpunit": "~3.7", "symfony/browser-kit": "~2.3", + "doctrine/orm": "~2.3", + "doctrine/mongodb-odm": "1.0.*", "symfony/yaml": "~2.3", + "symfony/form": "~2.3", "twig/twig": "~1.0", "doctrine/cache": "~1.1", "aws/aws-sdk-php": "~2.4",