Permalink
Browse files

added a bunch of tests and covers annotations

  • Loading branch information...
1 parent be933eb commit 59fb67dc46cdd0074764dbdeb65d9b05f75db0e2 @digitalkaoz digitalkaoz committed Apr 25, 2014
Showing with 364 additions and 173 deletions.
  1. +2 −0 .travis.yml
  2. +1 −4 Binary/Loader/AbstractDoctrineLoader.php
  3. +0 −44 Binary/Loader/ExtendedFileSystemLoader.php
  4. +0 −1 Binary/Loader/FileSystemLoader.php
  5. +1 −0 Command/RemoveCacheCommand.php
  6. +3 −0 Command/ResolveCacheCommand.php
  7. +0 −38 Imagine/Data/Transformer/PdfTransformer.php
  8. +1 −5 ImagineEvents.php
  9. +76 −0 Tests/Binary/Loader/AbstractDoctrineLoaderTest.php
  10. +3 −3 Tests/Binary/Loader/FileSystemLoaderTest.php
  11. +55 −0 Tests/Binary/Loader/GridFSLoaderTest.php
  12. +1 −1 Tests/Binary/Loader/StreamLoaderTest.php
  13. +3 −0 Tests/Binary/SimpleMimeTypeGuesserTest.php
  14. +33 −0 Tests/DependencyInjection/Compiler/FiltersCompilerPassTest.php
  15. +33 −0 Tests/DependencyInjection/Compiler/LoadersCompilerPassTest.php
  16. +33 −0 Tests/DependencyInjection/Compiler/ResolversCompilerPassTest.php
  17. +3 −0 Tests/DependencyInjection/ConfigurationTest.php
  18. +3 −0 Tests/DependencyInjection/Factory/Loader/FileSystemLoaderFactoryTest.php
  19. +3 −0 Tests/DependencyInjection/Factory/Loader/StreamLoaderFactoryTest.php
  20. +3 −0 Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php
  21. +3 −0 Tests/DependencyInjection/Factory/Resolver/WebPathResolverFactoryTest.php
  22. +1 −1 Tests/Events/CacheResolveEventTest.php
  23. +9 −4 Tests/Exception/Imagine/Cache/Resolver/NotResolvableExceptionTest.php
  24. +9 −4 Tests/Exception/Imagine/Cache/Resolver/NotStorableExceptionTest.php
  25. +68 −0 Tests/Form/Type/ImageTypeTest.php
  26. +3 −0 Tests/Functional/Command/RemoveCacheTest.php
  27. +3 −0 Tests/Functional/Command/ResolveCacheTest.php
  28. +1 −4 Tests/Imagine/Cache/Resolver/ProxyResolverTest.php
  29. +0 −54 Tests/Imagine/Data/Transformer/PdfTransformerTest.php
  30. +4 −10 Tests/LiipImagineBundleTest.php
  31. +3 −0 Tests/Model/BinaryTest.php
  32. +3 −0 composer.json
View
@@ -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
@@ -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) {
@@ -1,44 +0,0 @@
-<?php
-
-namespace Liip\ImagineBundle\Binary\Loader;
-
-use Imagine\Image\ImagineInterface;
-use Liip\ImagineBundle\Imagine\Data\Transformer\TransformerInterface;
-
-class ExtendedFileSystemLoader extends FileSystemLoader
-{
- /**
- * @var TransformerInterface[]
- */
- protected $transformers;
-
- /**
- * @param array $formats
- * @param string $rootPath
- * @param TransformerInterface[] $transformers
- */
- public function __construct($formats, $rootPath, array $transformers)
- {
- parent::__construct($formats, $rootPath);
-
- $this->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);
- }
-}
@@ -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;
@@ -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;
@@ -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;
@@ -1,38 +0,0 @@
-<?php
-
-namespace Liip\ImagineBundle\Imagine\Data\Transformer;
-
-class PdfTransformer implements TransformerInterface
-{
- /**
- * @var \Imagick
- */
- protected $imagick;
-
- public function __construct(\Imagick $imagick)
- {
- $this->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;
- }
-}
View
@@ -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()
- {
- }
}
@@ -0,0 +1,76 @@
+<?php
+
+
+namespace Liip\ImagineBundle\Tests\Binary\Loader;
+
+
+use Doctrine\Common\Persistence\ObjectRepository;
+use Liip\ImagineBundle\Binary\Loader\AbstractDoctrineLoader;
+
+/**
+ * @covers Liip\ImagineBundle\Binary\Loader\AbstractDoctrineLoader<extended>
+ */
+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');
+ }
+}
+
@@ -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()
@@ -0,0 +1,55 @@
+<?php
+
+
+namespace Liip\ImagineBundle\Tests\Binary\Loader;
+
+use Doctrine\MongoDB\GridFSFile;
+use Doctrine\ODM\MongoDB\DocumentRepository;
+use Liip\ImagineBundle\Binary\Loader\GridFSLoader;
+
+/**
+ * @covers Liip\ImagineBundle\Binary\Loader\GridFSLoader<extended>
+ */
+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');
+ }
+}
+
@@ -6,7 +6,7 @@
use Liip\ImagineBundle\Tests\AbstractTest;
/**
- * @covers Liip\ImagineBundle\Binary\Loader\StreamLoader
+ * @covers Liip\ImagineBundle\Binary\Loader\StreamLoader<extended>
*/
class StreamLoaderTest extends AbstractTest
{
@@ -4,6 +4,9 @@
use Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
+/**
+ * @covers Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser<extended>
+ */
class SimpleMimeTypeGuesserTest extends \PHPUnit_Framework_TestCase
{
public function provideImages()
@@ -0,0 +1,33 @@
+<?php
+
+
+namespace Liip\ImagineBundle\Tests\DependencyInjection\Compiler;
+
+use Liip\ImagineBundle\DependencyInjection\Compiler\FiltersCompilerPass;
+use Symfony\Component\DependencyInjection\Definition;
+
+/**
+ * @covers Liip\ImagineBundle\DependencyInjection\Compiler\FiltersCompilerPass
+ */
+class FiltersCompilerPassTest extends \PHPUnit_Framework_TestCase
+{
+ public function testProcess()
+ {
+ $d = new Definition();
+ $cb = $this->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());
+ }
+}
+
@@ -0,0 +1,33 @@
+<?php
+
+
+namespace Liip\ImagineBundle\Tests\DependencyInjection\Compiler;
+
+use Liip\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass;
+use Symfony\Component\DependencyInjection\Definition;
+
+/**
+ * @covers Liip\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass
+ */
+class LoadersCompilerPassTest extends \PHPUnit_Framework_TestCase
+{
+ public function testProcess()
+ {
+ $d = new Definition();
+ $cb = $this->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());
+ }
+}
+
Oops, something went wrong.

0 comments on commit 59fb67d

Please sign in to comment.