Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[data loader] rework to return binary instance. add mime type guesser.

commit 81ba74c34c12e75327e21e6266082b870a349543 1 parent 0d61582
@makasim makasim authored havvg committed
Showing with 812 additions and 185 deletions.
  1. +20 −0 Binary/BinaryInterface.php
  2. +12 −0 Binary/MimeTypeGuesserInterface.php
  3. +42 −0 Binary/SimpleMimeTypeGuesser.php
  4. +11 −4 Controller/ImagineController.php
  5. +49 −8 Imagine/Data/DataManager.php
  6. +4 −24 Imagine/Data/Loader/AbstractDoctrineLoader.php
  7. +2 −5 Imagine/Data/Loader/ExtendedFileSystemLoader.php
  8. +30 −12 Imagine/Data/Loader/FileSystemLoader.php
  9. +2 −12 Imagine/Data/Loader/GridFSLoader.php
  10. +1 −1  Imagine/Data/Loader/LoaderInterface.php
  11. +2 −12 Imagine/Data/Loader/StreamLoader.php
  12. +58 −0 Model/Binary.php
  13. +26 −1 Resources/config/imagine.xml
  14. +41 −0 Tests/Binary/SimpleMimeTypeGuesserTest.php
  15. +22 −6 Tests/Controller/ImagineControllerTest.php
  16. +6 −1 Tests/DependencyInjection/LiipImagineExtensionTest.php
  17. BIN  Tests/Fixtures/assets/cats.gif
  18. BIN  Tests/Fixtures/assets/cats.png
  19. +1 −0  Tests/Fixtures/assets/cats.txt
  20. +16 −0 Tests/Functional/Binary/SimpleMimeTypeGuesserTest.php
  21. +13 −0 Tests/Functional/ExtensionGuesserTest.php
  22. +15 −0 Tests/Functional/Imagine/DataManagerTest.php
  23. +13 −0 Tests/Functional/MimeTypeGuesserTest.php
  24. +301 −6 Tests/Imagine/Data/DataManagerTest.php
  25. +69 −54 Tests/Imagine/Data/Loader/FileSystemLoaderTest.php
  26. +19 −39 Tests/Imagine/Data/Loader/StreamLoaderTest.php
  27. +35 −0 Tests/Model/BinaryTest.php
  28. +2 −0  UPGRADE.md
View
20 Binary/BinaryInterface.php
@@ -0,0 +1,20 @@
+<?php
+namespace Liip\ImagineBundle\Binary;
+
+interface BinaryInterface
+{
+ /**
+ * @return string
+ */
+ public function getContent();
+
+ /**
+ * @return string
+ */
+ public function getMimeType();
+
+ /**
+ * @return string
+ */
+ public function getFormat();
+}
View
12 Binary/MimeTypeGuesserInterface.php
@@ -0,0 +1,12 @@
+<?php
+namespace Liip\ImagineBundle\Binary;
+
+interface MimeTypeGuesserInterface
+{
+ /**
+ * @param string $binary The image binary
+ *
+ * @return string|null mime type or null if it could be not be guessed.
+ */
+ function guess($binary);
+}
View
42 Binary/SimpleMimeTypeGuesser.php
@@ -0,0 +1,42 @@
+<?php
+namespace Liip\ImagineBundle\Binary;
+
+use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface as SymfonyMimeTypeGuesserInterface;
+
+class SimpleMimeTypeGuesser implements MimeTypeGuesserInterface
+{
+ /**
+ * @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface
+ */
+ protected $mimeTypeGuesser;
+
+ /**
+ * @param SymfonyMimeTypeGuesserInterface $mimeTypeGuesser
+ */
+ public function __construct(SymfonyMimeTypeGuesserInterface $mimeTypeGuesser)
+ {
+ $this->mimeTypeGuesser = $mimeTypeGuesser;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function guess($binary)
+ {
+ $tmpFile = tempnam(sys_get_temp_dir(), 'liip-imagine-bundle');
+
+ try {
+ file_put_contents($tmpFile, $binary);
+
+ $mimeType = $this->mimeTypeGuesser->guess($tmpFile);
+
+ unlink($tmpFile);
+
+ return $mimeType;
+ } catch (\Exception $e) {
+ unlink($tmpFile);
+
+ throw $e;
+ }
+ }
+}
View
15 Controller/ImagineController.php
@@ -2,6 +2,7 @@
namespace Liip\ImagineBundle\Controller;
+use Imagine\Image\ImagineInterface;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
@@ -28,17 +29,22 @@ class ImagineController
protected $cacheManager;
/**
- * Constructor.
- *
+ * @var ImagineInterface
+ */
+ protected $imagine;
+
+ /**
* @param DataManager $dataManager
* @param FilterManager $filterManager
* @param CacheManager $cacheManager
+ * @param ImagineInterface $imagine
*/
- public function __construct(DataManager $dataManager, FilterManager $filterManager, CacheManager $cacheManager)
+ public function __construct(DataManager $dataManager, FilterManager $filterManager, CacheManager $cacheManager, ImagineInterface $imagine)
{
$this->dataManager = $dataManager;
$this->filterManager = $filterManager;
$this->cacheManager = $cacheManager;
+ $this->imagine = $imagine;
}
/**
@@ -56,7 +62,8 @@ public function filterAction(Request $request, $path, $filter)
return new RedirectResponse($this->cacheManager->resolve($path, $filter), 301);
}
- $image = $this->dataManager->find($filter, $path);
+ $binary = $this->dataManager->find($filter, $path);
+ $image = $this->imagine->load($binary->getContent());
$response = $this->filterManager->get($request, $filter, $image, $path);
View
57 Imagine/Data/DataManager.php
@@ -4,10 +4,24 @@
use Liip\ImagineBundle\Imagine\Data\Loader\LoaderInterface;
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
+use Liip\ImagineBundle\Binary\MimeTypeGuesserInterface;
+use Liip\ImagineBundle\Model\Binary;
+use Liip\ImagineBundle\Binary\BinaryInterface;
+use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface;
class DataManager
{
/**
+ * @var MimeTypeGuesserInterface
+ */
+ protected $mimeTypeGuesser;
+
+ /**
+ * @var ExtensionGuesserInterface
+ */
+ protected $extensionGuesser;
+
+ /**
* @var FilterConfiguration
*/
protected $filterConfig;
@@ -23,15 +37,21 @@ class DataManager
protected $loaders = array();
/**
- * Constructor.
- *
- * @param FilterConfiguration $filterConfig
- * @param string $defaultLoader
+ * @param MimeTypeGuesserInterface $mimeTypeGuesser
+ * @param ExtensionGuesserInterface $extensionGuesser
+ * @param FilterConfiguration $filterConfig
+ * @param string $defaultLoader
*/
- public function __construct(FilterConfiguration $filterConfig, $defaultLoader = null)
- {
+ public function __construct(
+ MimeTypeGuesserInterface $mimeTypeGuesser,
+ ExtensionGuesserInterface $extensionGuesser,
+ FilterConfiguration $filterConfig,
+ $defaultLoader = null
+ ) {
+ $this->mimeTypeGuesser = $mimeTypeGuesser;
$this->filterConfig = $filterConfig;
$this->defaultLoader = $defaultLoader;
+ $this->extensionGuesser = $extensionGuesser;
}
/**
@@ -78,12 +98,33 @@ public function getLoader($filter)
* @param string $filter
* @param string $path
*
- * @return \Imagine\Image\ImageInterface
+ * @throws \LogicException
+ *
+ * @return \Liip\ImagineBundle\Binary\BinaryInterface
*/
public function find($filter, $path)
{
$loader = $this->getLoader($filter);
- return $loader->find($path);
+ $binary = $loader->find($path);
+ if (!$binary instanceof BinaryInterface) {
+ $mimeType = $this->mimeTypeGuesser->guess($binary);
+
+ $binary = new Binary(
+ $binary,
+ $mimeType,
+ $this->extensionGuesser->guess($mimeType)
+ );
+ }
+
+ if (null === $binary->getMimeType()) {
+ throw new \LogicException(sprintf('The mime type of image %s was not guessed.', $path));
+ }
+
+ if (0 !== strpos($binary->getMimeType(), 'image/')) {
+ throw new \LogicException(sprintf('The mime type of image %s must be image/xxx got %s.', $path, $binary->getMimeType()));
+ }
+
+ return $binary;
}
}
View
28 Imagine/Data/Loader/AbstractDoctrineLoader.php
@@ -9,11 +9,6 @@
abstract class AbstractDoctrineLoader implements LoaderInterface
{
/**
- * @var ImagineInterface
- */
- protected $imagine;
-
- /**
* @var ObjectManager
*/
protected $manager;
@@ -24,25 +19,12 @@
protected $class;
/**
- * @var array
- */
- protected $formats;
-
- /**
- * Constructor.
- *
- * @param ImagineInterface $imagine
* @param ObjectManager $manager
* @param string $class
* @param array $formats possible image formats to look up file ids
*/
- public function __construct(
- ImagineInterface $imagine,
- ObjectManager $manager,
- $class = null,
- array $formats = array()
- ) {
- $this->imagine = $imagine;
+ public function __construct(ObjectManager $manager, $class = null)
@lsmith77 Owner

this is of course a BC break, though we are below 1.0 for a reason, just FYI:
symfony-cmf/MediaBundle#95

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ {
$this->manager = $manager;
$this->class = $class;
$this->formats = $formats;
@@ -67,9 +49,7 @@ public function __construct(
abstract protected function getStreamFromImage($image);
/**
- * @param string $path
- *
- * @return \Imagine\Image\ImageInterface
+ * {@inheritDoc}
*/
public function find($path)
{
@@ -97,6 +77,6 @@ public function find($path)
throw new NotFoundHttpException(sprintf('Source image not found with id "%s"', $path));
}
- return $this->imagine->load(stream_get_contents($this->getStreamFromImage($image)));
+ return stream_get_contents($this->getStreamFromImage($image));
}
}
View
7 Imagine/Data/Loader/ExtendedFileSystemLoader.php
@@ -13,16 +13,13 @@ class ExtendedFileSystemLoader extends FileSystemLoader
protected $transformers;
/**
- * Constructor.
- *
- * @param ImagineInterface $imagine
* @param array $formats
* @param string $rootPath
* @param TransformerInterface[] $transformers
*/
- public function __construct(ImagineInterface $imagine, $formats, $rootPath, array $transformers)
+ public function __construct($formats, $rootPath, array $transformers)
{
- parent::__construct($imagine, $formats, $rootPath);
+ parent::__construct($formats, $rootPath);
$this->transformers = $transformers;
}
View
42 Imagine/Data/Loader/FileSystemLoader.php
@@ -2,15 +2,23 @@
namespace Liip\ImagineBundle\Imagine\Data\Loader;
-use Imagine\Image\ImagineInterface;
+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;
class FileSystemLoader implements LoaderInterface
{
/**
- * @var ImagineInterface
+ * @var MimeTypeGuesserInterface
*/
- protected $imagine;
+ protected $mimeTypeGuesser;
+
+ /**
+ * @var ExtensionGuesserInterface
+ */
+ protected $extensionGuesser;
/**
* @var array
@@ -23,17 +31,21 @@ class FileSystemLoader implements LoaderInterface
protected $rootPath;
/**
- * Constructor.
- *
- * @param ImagineInterface $imagine
- * @param array $formats
- * @param string $rootPath
+ * @param MimeTypeGuesserInterface $mimeTypeGuesser
+ * @param ExtensionGuesserInterface $extensionGuesser
+ * @param array $formats
+ * @param string $rootPath
*/
- public function __construct(ImagineInterface $imagine, array $formats, $rootPath)
- {
- $this->imagine = $imagine;
+ public function __construct(
+ MimeTypeGuesserInterface $mimeTypeGuesser,
+ ExtensionGuesserInterface $extensionGuesser,
+ array $formats,
+ $rootPath
+ ){
$this->formats = $formats;
$this->rootPath = realpath($rootPath);
+ $this->mimeTypeGuesser = $mimeTypeGuesser;
+ $this->extensionGuesser = $extensionGuesser;
}
/**
@@ -93,6 +105,12 @@ public function find($path)
}
}
- return $this->imagine->open($absolutePath);
+ $mimeType = $this->mimeTypeGuesser->guess($absolutePath);
+
+ return new Binary(
+ file_get_contents($absolutePath),
+ $mimeType,
+ $this->extensionGuesser->guess($mimeType)
+ );
}
}
View
14 Imagine/Data/Loader/GridFSLoader.php
@@ -2,18 +2,12 @@
namespace Liip\ImagineBundle\Imagine\Data\Loader;
-use Imagine\Image\ImagineInterface;
use Doctrine\ODM\MongoDB\DocumentManager;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class GridFSLoader implements LoaderInterface
{
/**
- * @var ImagineInterface
- */
- protected $imagine;
-
- /**
* @var DocumentManager
*/
protected $dm;
@@ -24,15 +18,11 @@ class GridFSLoader implements LoaderInterface
protected $class;
/**
- * Constructs
- *
- * @param ImagineInterface $imagine
* @param DocumentManager $dm
* @param string $class
*/
- public function __construct(ImagineInterface $imagine, DocumentManager $dm, $class)
+ public function __construct(DocumentManager $dm, $class)
{
- $this->imagine = $imagine;
$this->dm = $dm;
$this->class = $class;
}
@@ -50,6 +40,6 @@ public function find($id)
throw new NotFoundHttpException(sprintf('Source image not found with id "%s"', $id));
}
- return $this->imagine->load($image->getFile()->getBytes());
+ return $image['file']->getBytes();
}
}
View
2  Imagine/Data/Loader/LoaderInterface.php
@@ -11,7 +11,7 @@
*
* @param mixed $path
*
- * @return \Imagine\Image\ImageInterface
+ * @return \Liip\ImagineBundle\Binary\BinaryInterface|string An image binary content
*/
function find($path);
}
View
14 Imagine/Data/Loader/StreamLoader.php
@@ -2,17 +2,11 @@
namespace Liip\ImagineBundle\Imagine\Data\Loader;
-use Imagine\Image\ImagineInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class StreamLoader implements LoaderInterface
{
/**
- * @var ImagineInterface
- */
- protected $imagine;
-
- /**
* The wrapper prefix to append to the path to be loaded.
*
* @var string
@@ -27,17 +21,13 @@ class StreamLoader implements LoaderInterface
protected $context;
/**
- * Constructor.
- *
- * @param ImagineInterface $imagine
* @param string $wrapperPrefix
* @param resource|null $context
*
* @throws \InvalidArgumentException
*/
- public function __construct(ImagineInterface $imagine, $wrapperPrefix, $context = null)
+ public function __construct($wrapperPrefix, $context = null)
{
- $this->imagine = $imagine;
$this->wrapperPrefix = $wrapperPrefix;
if ($context && !is_resource($context)) {
@@ -68,6 +58,6 @@ public function find($path)
// Closing the opened stream to avoid locking of the resource to find.
fclose($resource);
- return $this->imagine->load(file_get_contents($name, null, $this->context));
+ return file_get_contents($name, null, $this->context);
}
}
View
58 Model/Binary.php
@@ -0,0 +1,58 @@
+<?php
+namespace Liip\ImagineBundle\Model;
+
+use Liip\ImagineBundle\Binary\BinaryInterface;
+
+class Binary implements BinaryInterface
+{
+ /**
+ * @var string
+ */
+ protected $content;
+
+ /**
+ * @var string
+ */
+ protected $mimeType;
+
+ /**
+ * @var string
+ */
+ protected $format;
+
+ /**
+ * @param string $content
+ * @param string $mimeType
+ * @param string $format
+ */
+ public function __construct($content, $mimeType, $format = null)
+ {
+ $this->content = $content;
+ $this->mimeType = $mimeType;
+ $this->format = $format;
+ }
+
+ /**
+ * @return string
+ */
+ public function getContent()
+ {
+ return $this->content;
+ }
+
+ /**
+ * @return string
+ */
+ public function getMimeType()
+ {
+ return $this->mimeType;
+ }
+
+ /**
+ * @return string
+ */
+ public function getFormat()
+ {
+ return $this->format;
+ }
+}
View
27 Resources/config/imagine.xml
@@ -11,6 +11,7 @@
<parameter key="liip_imagine.filter.manager.class">Liip\ImagineBundle\Imagine\Filter\FilterManager</parameter>
<parameter key="liip_imagine.data.manager.class">Liip\ImagineBundle\Imagine\Data\DataManager</parameter>
<parameter key="liip_imagine.cache.manager.class">Liip\ImagineBundle\Imagine\Cache\CacheManager</parameter>
+ <parameter key="liip_imagine.binary.mime_type_guesser.class">Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser</parameter>
<!-- Controller class -->
@@ -69,6 +70,8 @@
</service>
<service id="liip_imagine.data.manager" class="%liip_imagine.data.manager.class%">
+ <argument type="service" id="liip_imagine.binary.mime_type_guesser" />
+ <argument type="service" id="liip_imagine.extension_guesser" />
<argument type="service" id="liip_imagine.filter.configuration" />
<argument>%liip_imagine.data.loader.default%</argument>
</service>
@@ -90,6 +93,7 @@
<argument type="service" id="liip_imagine.data.manager" />
<argument type="service" id="liip_imagine.filter.manager" />
<argument type="service" id="liip_imagine.cache.manager" />
+ <argument type="service" id="liip_imagine" />
</service>
<!-- Route Loader -->
@@ -174,7 +178,8 @@
<service id="liip_imagine.data.loader.filesystem" class="%liip_imagine.data.loader.filesystem.class%">
<tag name="liip_imagine.data.loader" loader="filesystem" />
- <argument type="service" id="liip_imagine" />
+ <argument type="service" id="liip_imagine.mime_type_guesser" />
+ <argument type="service" id="liip_imagine.extension_guesser" />
<argument>%liip_imagine.formats%</argument>
<argument>%liip_imagine.data_root%</argument>
</service>
@@ -208,5 +213,25 @@
<tag name="form.type" alias="liip_imagine_image" />
</service>
+ <!-- Guessers -->
+
+ <service
+ id="liip_imagine.mime_type_guesser"
+ class="Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface"
+ factory-class="Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser"
+ factory-method="getInstance"
+ />
+
+ <service
+ id="liip_imagine.extension_guesser"
+ class="Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface"
+ factory-class="Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser"
+ factory-method="getInstance"
+ />
+
+ <service id="liip_imagine.binary.mime_type_guesser" class="%liip_imagine.binary.mime_type_guesser.class%">
+ <argument type="service" id="liip_imagine.mime_type_guesser" />
+ </service>
+
</services>
</container>
View
41 Tests/Binary/SimpleMimeTypeGuesserTest.php
@@ -0,0 +1,41 @@
+<?php
+namespace Liip\ImagineBundle\Tests\Binary;
+
+use Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser;
+use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
+
+class SimpleMimeTypeGuesserTest extends \PHPUnit_Framework_TestCase
+{
+ public function provideImages()
+ {
+ 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'),
+ );
+ }
+
+ public function testImplementsMimeTypeGuesserInterface()
+ {
+ $rc = new \ReflectionClass('Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser');
+
+ $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Binary\MimeTypeGuesserInterface'));
+ }
+
+ public function testCouldBeConstructedWithSymfonyMimeTypeGuesserAsFirstArgument()
+ {
+ new SimpleMimeTypeGuesser(MimeTypeGuesser::getInstance());
+ }
+
+ /**
+ * @dataProvider provideImages
+ */
+ public function testGuessMimeType($imageFile, $expectedMimeType)
+ {
+ $guesser = new SimpleMimeTypeGuesser(MimeTypeGuesser::getInstance());
+
+ $this->assertEquals($expectedMimeType, $guesser->guess(file_get_contents($imageFile)));
+ }
+}
View
28 Tests/Controller/ImagineControllerTest.php
@@ -16,8 +16,11 @@
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
use Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader;
+use Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser;
use Liip\ImagineBundle\Tests\AbstractTest;
+use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
+use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
use Symfony\Component\HttpFoundation\Request;
/**
@@ -82,9 +85,19 @@ public function testFilterActionLive()
->will($this->returnValue('/media/cache/thumbnail/cats.jpeg'))
;
- $dataLoader = new FileSystemLoader($this->imagine, array(), $this->dataDir);
-
- $dataManager = new DataManager($this->configuration, 'filesystem');
+ $dataLoader = new FileSystemLoader(
+ MimeTypeGuesser::getInstance(),
+ ExtensionGuesser::getInstance(),
+ array(),
+ $this->dataDir
+ );
+
+ $dataManager = new DataManager(
+ new SimpleMimeTypeGuesser(MimeTypeGuesser::getInstance()),
+ ExtensionGuesser::getInstance(),
+ $this->configuration,
+ 'filesystem'
+ );
$dataManager->addLoader('filesystem', $dataLoader);
$filterLoader = new ThumbnailFilterLoader();
@@ -97,7 +110,7 @@ public function testFilterActionLive()
$cacheManager = new CacheManager($this->configuration, $router, $this->webRoot, 'web_path');
$cacheManager->addResolver('web_path', $webPathResolver);
- $controller = new ImagineController($dataManager, $filterManager, $cacheManager);
+ $controller = new ImagineController($dataManager, $filterManager, $cacheManager, $this->imagine);
$request = Request::create('/media/cache/thumbnail/cats.jpeg');
@@ -129,10 +142,13 @@ public function testFilterDelegatesResolverResponse()
->will($this->returnValue('http://foo.com/a/path/image.jpg'))
;
- $dataManager = $this->getMock('Liip\ImagineBundle\Imagine\Data\DataManager', array(), array($this->configuration));
+ $mimeTypeGuesser = new SimpleMimeTypeGuesser(MimeTypeGuesser::getInstance());
+ $extensionGuesser = ExtensionGuesser::getInstance();
+
+ $dataManager = $this->getMock('Liip\ImagineBundle\Imagine\Data\DataManager', array(), array($mimeTypeGuesser, $extensionGuesser, $this->configuration));
$filterManager = $this->getMock('Liip\ImagineBundle\Imagine\Filter\FilterManager', array(), array($this->configuration));
- $controller = new ImagineController($dataManager, $filterManager, $cacheManager);
+ $controller = new ImagineController($dataManager, $filterManager, $cacheManager, $this->imagine);
$request = Request::create('/media/cache/thumbnail/cats.jpeg');
View
7 Tests/DependencyInjection/LiipImagineExtensionTest.php
@@ -40,7 +40,12 @@ public function testLoadWithDefaults()
$this->assertHasDefinition('liip_imagine.controller');
$this->assertDICConstructorArguments(
$this->containerBuilder->getDefinition('liip_imagine.controller'),
- array(new Reference('liip_imagine.data.manager'), new Reference('liip_imagine.filter.manager'), new Reference('liip_imagine.cache.manager'))
+ array(
+ new Reference('liip_imagine.data.manager'),
+ new Reference('liip_imagine.filter.manager'),
+ new Reference('liip_imagine.cache.manager'),
+ new Reference('liip_imagine')
+ )
);
}
View
BIN  Tests/Fixtures/assets/cats.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Tests/Fixtures/assets/cats.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
1  Tests/Fixtures/assets/cats.txt
@@ -0,0 +1 @@
+some cats here
View
16 Tests/Functional/Binary/SimpleMimeTypeGuesserTest.php
@@ -0,0 +1,16 @@
+<?php
+namespace Liip\ImagineBundle\Tests\Functional\Binary;
+
+use Liip\ImagineBundle\Tests\Functional\WebTestCase;
+
+class SimpleMimeTypeGuesserTest extends WebTestCase
+{
+ public function testCouldBeGetFromContainerAsService()
+ {
+ $this->createClient();
+
+ $service = self::$kernel->getContainer()->get('liip_imagine.binary.mime_type_guesser');
+
+ $this->assertInstanceOf('Liip\ImagineBundle\Binary\SimpleMimeTypeGuesser', $service);
+ }
+}
View
13 Tests/Functional/ExtensionGuesserTest.php
@@ -0,0 +1,13 @@
+<?php
+namespace Liip\ImagineBundle\Tests\Functional;
+
+class ExtensionGuesserTest extends WebTestCase
+{
+ public function testCouldBeGetFromContainerAsService()
+ {
+ $this->createClient();
+ $guesser = self::$kernel->getContainer()->get('liip_imagine.extension_guesser');
+
+ $this->assertInstanceOf('Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser', $guesser);
+ }
+}
View
15 Tests/Functional/Imagine/DataManagerTest.php
@@ -0,0 +1,15 @@
+<?php
+namespace Liip\ImagineBundle\Tests\Functional\Imagine;
+
+use Liip\ImagineBundle\Tests\Functional\WebTestCase;
+
+class DataManagerTest extends WebTestCase
+{
+ public function testCouldBeGetFromContainerAsService()
+ {
+ $this->createClient();
+ $service =self::$kernel->getContainer()->get('liip_imagine.data.manager');
+
+ $this->assertInstanceOf('Liip\ImagineBundle\Imagine\Data\DataManager', $service);
+ }
+}
View
13 Tests/Functional/MimeTypeGuesserTest.php
@@ -0,0 +1,13 @@
+<?php
+namespace Liip\ImagineBundle\Tests\Functional;
+
+class MimeTypeGuesserTest extends WebTestCase
+{
+ public function testCouldBeGetFromContainerAsService()
+ {
+ $this->createClient();
+ $guesser = self::$kernel->getContainer()->get('liip_imagine.mime_type_guesser');
+
+ $this->assertInstanceOf('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', $guesser);
+ }
+}
View
307 Tests/Imagine/Data/DataManagerTest.php
@@ -3,6 +3,8 @@
namespace Liip\ImagineBundle\Tests\Imagine\Data;
use Liip\ImagineBundle\Imagine\Data\DataManager;
+use Liip\ImagineBundle\Imagine\Data\Loader\LoaderInterface;
+use Liip\ImagineBundle\Model\Binary;
use Liip\ImagineBundle\Tests\AbstractTest;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -12,9 +14,7 @@
*/
class DataManagerTest extends AbstractTest
{
- protected $loader;
-
- public function testDefaultLoaderUsedIfNoneSet()
+ public function testUseDefaultLoaderUsedIfNoneSet()
{
$loader = $this->getMockLoader();
$loader
@@ -35,13 +35,197 @@ public function testDefaultLoaderUsedIfNoneSet()
)))
;
- $dataManager = new DataManager($config, 'default');
+ $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
+ $mimeTypeGuesser
+ ->expects($this->once())
+ ->method('guess')
+ ->will($this->returnValue('image/png'))
+ ;
+
+ $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config, 'default');
$dataManager->addLoader('default', $loader);
$dataManager->find('thumbnail', 'cats.jpeg');
}
- public function testFindWithoutLoader()
+ public function testUseLoaderRegisteredForFilterOnFind()
+ {
+ $loader = $this->getMockLoader();
+ $loader
+ ->expects($this->once())
+ ->method('find')
+ ->with('cats.jpeg')
+ ;
+
+ $config = $this->getMockFilterConfiguration();
+ $config
+ ->expects($this->once())
+ ->method('get')
+ ->with('thumbnail')
+ ->will($this->returnValue(array(
+ 'size' => array(180, 180),
+ 'mode' => 'outbound',
+ 'data_loader' => 'the_loader',
+ )))
+ ;
+
+ $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
+ $mimeTypeGuesser
+ ->expects($this->once())
+ ->method('guess')
+ ->will($this->returnValue('image/png'))
+ ;
+
+ $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config);
+ $dataManager->addLoader('the_loader', $loader);
+
+ $dataManager->find('thumbnail', 'cats.jpeg');
+ }
+
+ public function testThrowsIfMimeTypeWasNotGuessedOnFind()
+ {
+ $loader = $this->getMockLoader();
+ $loader
+ ->expects($this->once())
+ ->method('find')
+ ->with('cats.jpeg')
+ ;
+
+ $config = $this->getMockFilterConfiguration();
+ $config
+ ->expects($this->once())
+ ->method('get')
+ ->with('thumbnail')
+ ->will($this->returnValue(array(
+ 'size' => array(180, 180),
+ 'mode' => 'outbound',
+ 'data_loader' => 'the_loader',
+ )))
+ ;
+
+ $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
+ $mimeTypeGuesser
+ ->expects($this->once())
+ ->method('guess')
+ ->will($this->returnValue(null))
+ ;
+
+ $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config);
+ $dataManager->addLoader('the_loader', $loader);
+
+ $this->setExpectedException('LogicException', 'The mime type of image cats.jpeg was not guessed.');
+ $dataManager->find('thumbnail', 'cats.jpeg');
+ }
+
+ public function testThrowsIfMimeTypeNotImageOneOnFind()
+ {
+ $loader = $this->getMockLoader();
+ $loader
+ ->expects($this->once())
+ ->method('find')
+ ->with('cats.jpeg')
+ ->will($this->returnValue('content'))
+ ;
+
+ $config = $this->getMockFilterConfiguration();
+ $config
+ ->expects($this->once())
+ ->method('get')
+ ->with('thumbnail')
+ ->will($this->returnValue(array(
+ 'size' => array(180, 180),
+ 'mode' => 'outbound',
+ 'data_loader' => 'the_loader',
+ )))
+ ;
+
+ $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
+ $mimeTypeGuesser
+ ->expects($this->once())
+ ->method('guess')
+ ->will($this->returnValue('text/plain'))
+ ;
+
+ $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $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');
+ }
+
+ public function testThrowsIfLoaderReturnBinaryWithEmtptyMimeTypeOnFind()
+ {
+ $loader = $this->getMockLoader();
+ $loader
+ ->expects($this->once())
+ ->method('find')
+ ->with('cats.jpeg')
+ ->will($this->returnValue(new Binary('content', null)))
+ ;
+
+ $config = $this->getMockFilterConfiguration();
+ $config
+ ->expects($this->once())
+ ->method('get')
+ ->with('thumbnail')
+ ->will($this->returnValue(array(
+ 'size' => array(180, 180),
+ 'mode' => 'outbound',
+ 'data_loader' => 'the_loader',
+ )))
+ ;
+
+ $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
+ $mimeTypeGuesser
+ ->expects($this->never())
+ ->method('guess')
+ ;
+
+ $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config);
+ $dataManager->addLoader('the_loader', $loader);
+
+ $this->setExpectedException('LogicException', 'The mime type of image cats.jpeg was not guessed.');
+ $dataManager->find('thumbnail', 'cats.jpeg');
+ }
+
+ public function testThrowsIfLoaderReturnBinaryWithMimeTypeNotImageOneOnFind()
+ {
+ $binary = new Binary('content', 'text/plain');
+
+ $loader = $this->getMockLoader();
+ $loader
+ ->expects($this->once())
+ ->method('find')
+ ->with('cats.jpeg')
+ ->will($this->returnValue($binary))
+ ;
+
+ $config = $this->getMockFilterConfiguration();
+ $config
+ ->expects($this->once())
+ ->method('get')
+ ->with('thumbnail')
+ ->will($this->returnValue(array(
+ 'size' => array(180, 180),
+ 'mode' => 'outbound',
+ 'data_loader' => 'the_loader',
+ )))
+ ;
+
+ $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
+ $mimeTypeGuesser
+ ->expects($this->never())
+ ->method('guess')
+ ;
+
+ $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $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');
+ }
+
+ public function testThrowIfLoaderNotRegisteredForGivenFilterOnFind()
{
$config = $this->getMockFilterConfiguration();
$config
@@ -55,14 +239,125 @@ public function testFindWithoutLoader()
)))
;
- $dataManager = new DataManager($config);
+ $dataManager = new DataManager($this->getMockMimeTypeGuesser(), $this->getMockExtensionGuesser(), $config);
$this->setExpectedException('InvalidArgumentException', 'Could not find data loader for "thumbnail" filter type');
$dataManager->find('thumbnail', 'cats.jpeg');
}
+ public function testShouldReturnBinaryWithLoaderContentAndGuessedMimeTypeOnFind()
+ {
+ $expectedContent = 'theImageBinaryContent';
+ $expectedMimeType = 'image/png';
+
+ $loader = $this->getMockLoader();
+ $loader
+ ->expects($this->once())
+ ->method('find')
+ ->will($this->returnValue($expectedContent))
+ ;
+
+ $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
+ $mimeTypeGuesser
+ ->expects($this->once())
+ ->method('guess')
+ ->with($expectedContent)
+ ->will($this->returnValue($expectedMimeType))
+ ;
+
+ $config = $this->getMockFilterConfiguration();
+ $config
+ ->expects($this->once())
+ ->method('get')
+ ->with('thumbnail')
+ ->will($this->returnValue(array(
+ 'size' => array(180, 180),
+ 'mode' => 'outbound',
+ 'data_loader' => null,
+ )))
+ ;
+
+ $dataManager = new DataManager($mimeTypeGuesser, $this->getMockExtensionGuesser(), $config, 'default');
+ $dataManager->addLoader('default', $loader);
+
+ $binary = $dataManager->find('thumbnail', 'cats.jpeg');
+
+ $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $binary);
+ $this->assertEquals($expectedContent, $binary->getContent());
+ $this->assertEquals($expectedMimeType, $binary->getMimeType());
+ }
+
+ public function testShouldReturnBinaryWithLoaderContentAndGuessedFormatOnFind()
+ {
+ $content = 'theImageBinaryContent';
+ $mimeType = 'image/png';
+ $expectedFormat = 'png';
+
+ $loader = $this->getMockLoader();
+ $loader
+ ->expects($this->once())
+ ->method('find')
+ ->will($this->returnValue($content))
+ ;
+
+ $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
+ $mimeTypeGuesser
+ ->expects($this->once())
+ ->method('guess')
+ ->with($content)
+ ->will($this->returnValue($mimeType))
+ ;
+
+ $extensionGuesser = $this->getMockExtensionGuesser();
+ $extensionGuesser
+ ->expects($this->once())
+ ->method('guess')
+ ->with($mimeType)
+ ->will($this->returnValue($expectedFormat))
+ ;
+
+ $config = $this->getMockFilterConfiguration();
+ $config
+ ->expects($this->once())
+ ->method('get')
+ ->with('thumbnail')
+ ->will($this->returnValue(array(
+ 'size' => array(180, 180),
+ 'mode' => 'outbound',
+ 'data_loader' => null,
+ )))
+ ;
+
+ $dataManager = new DataManager($mimeTypeGuesser, $extensionGuesser, $config, 'default');
+ $dataManager->addLoader('default', $loader);
+
+ $binary = $dataManager->find('thumbnail', 'cats.jpeg');
+
+ $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $binary);
+ $this->assertEquals($expectedFormat, $binary->getFormat());
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject|LoaderInterface
+ */
protected function getMockLoader()
{
return $this->getMock('Liip\ImagineBundle\Imagine\Data\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');
+ }
}
View
123 Tests/Imagine/Data/Loader/FileSystemLoaderTest.php
@@ -4,27 +4,25 @@
use Liip\ImagineBundle\Imagine\Data\Loader\FileSystemLoader;
use Liip\ImagineBundle\Tests\AbstractTest;
+use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
+use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
/**
* @covers Liip\ImagineBundle\Imagine\Data\Loader\FileSystemLoader
*/
class FileSystemLoaderTest extends AbstractTest
{
- protected $imagine;
-
- protected function setUp()
- {
- parent::setUp();
-
- $this->imagine = $this->getMockImagine();
- }
-
/**
* @dataProvider invalidPathProvider
*/
public function testFindInvalidPath($path)
{
- $loader = new FileSystemLoader($this->imagine, array(), $this->fixturesDir.'/assets');
+ $loader = new FileSystemLoader(
+ MimeTypeGuesser::getInstance(),
+ ExtensionGuesser::getInstance(),
+ array(),
+ $this->fixturesDir.'/assets'
+ );
$this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
@@ -33,12 +31,12 @@ public function testFindInvalidPath($path)
public function testFindNotExisting()
{
- $this->imagine
- ->expects($this->never())
- ->method('open')
- ;
-
- $loader = new FileSystemLoader($this->imagine, array('jpeg'), $this->tempDir);
+ $loader = new FileSystemLoader(
+ MimeTypeGuesser::getInstance(),
+ ExtensionGuesser::getInstance(),
+ array('jpeg'),
+ $this->tempDir
+ );
$file = realpath($this->tempDir).'/invalid.jpeg';
$this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'Source image not found in "'.$file.'"');
@@ -48,7 +46,12 @@ public function testFindNotExisting()
public function testFindWithNoExtensionDoesNotThrowNotice()
{
- $loader = new FileSystemLoader($this->imagine, array(), $this->tempDir);
+ $loader = new FileSystemLoader(
+ MimeTypeGuesser::getInstance(),
+ ExtensionGuesser::getInstance(),
+ array(),
+ $this->tempDir
+ );
$this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
@@ -57,63 +60,75 @@ public function testFindWithNoExtensionDoesNotThrowNotice()
public function testFindRetrievesImage()
{
- $image = $this->getMockImage();
+ $expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg');
- $this->imagine
- ->expects($this->once())
- ->method('open')
- ->with(realpath($this->fixturesDir.'/assets/cats.jpeg'))
- ->will($this->returnValue($image))
- ;
+ $loader = new FileSystemLoader(
+ MimeTypeGuesser::getInstance(),
+ ExtensionGuesser::getInstance(),
+ array('jpeg'),
+ $this->fixturesDir.'/assets'
+ );
- $loader = new FileSystemLoader($this->imagine, array('jpeg'), $this->fixturesDir.'/assets');
- $this->assertSame($image, $loader->find('/cats.jpeg'));
+ $binary = $loader->find('/cats.jpeg');
+
+ $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $binary);
+ $this->assertEquals($expectedContent, $binary->getContent());
+ $this->assertEquals('image/jpeg', $binary->getMimeType());
}
public function testFindWithCyrillicFilename()
{
- $image = $this->getMockImage();
+ $expectedContent = file_get_contents($this->fixturesDir.'/assets/АГГЗ.jpeg');
+
+ $loader = new FileSystemLoader(
+ MimeTypeGuesser::getInstance(),
+ ExtensionGuesser::getInstance(),
+ array('jpeg'),
+ $this->fixturesDir.'/assets'
+ );
- $this->imagine
- ->expects($this->once())
- ->method('open')
- ->with(realpath($this->fixturesDir.'/assets/АГГЗ.jpeg'))
- ->will($this->returnValue($image))
- ;
+ $binary = $loader->find('/АГГЗ.jpeg');
- $loader = new FileSystemLoader($this->imagine, array('jpeg'), $this->fixturesDir.'/assets');
- $this->assertSame($image, $loader->find('/АГГЗ.jpeg'));
+ $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $binary);
+ $this->assertEquals($expectedContent, $binary->getContent());
+ $this->assertEquals('image/jpeg', $binary->getMimeType());
}
public function testFindGuessesFormat()
{
- $image = $this->getMockImage();
+ $expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg');
+
+ $loader = new FileSystemLoader(
+ MimeTypeGuesser::getInstance(),
+ ExtensionGuesser::getInstance(),
+ array('jpeg'),
+ $this->fixturesDir.'/assets'
+ );
- $this->imagine
- ->expects($this->once())
- ->method('open')
- ->with(realpath($this->fixturesDir.'/assets/cats.jpeg'))
- ->will($this->returnValue($image))
- ;
+ $binary = $loader->find('/cats.jpg');
- $loader = new FileSystemLoader($this->imagine, array('jpeg'), $this->fixturesDir.'/assets');
- $this->assertSame($image, $loader->find('/cats.jpg'));
+ $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $binary);
+ $this->assertEquals($expectedContent, $binary->getContent());
+ $this->assertEquals('image/jpeg', $binary->getMimeType());
}
public function testFindFileWithoutExtension()
{
- $image = $this->getMockImage();
-
$this->filesystem->copy($this->fixturesDir.'/assets/cats.jpeg', $this->tempDir.'/cats');
- $this->imagine
- ->expects($this->once())
- ->method('open')
- ->with(realpath($this->tempDir.'/cats'))
- ->will($this->returnValue($image))
- ;
+ $expectedContent = file_get_contents(realpath($this->tempDir.'/cats'));
+
+ $loader = new FileSystemLoader(
+ MimeTypeGuesser::getInstance(),
+ ExtensionGuesser::getInstance(),
+ array(),
+ $this->tempDir
+ );
+
+ $binary = $loader->find('/cats.jpeg');
- $loader = new FileSystemLoader($this->imagine, array(), $this->tempDir);
- $this->assertSame($image, $loader->find('/cats.jpeg'));
+ $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $binary);
+ $this->assertEquals($expectedContent, $binary->getContent());
+ $this->assertEquals('image/jpeg', $binary->getMimeType());
}
}
View
58 Tests/Imagine/Data/Loader/StreamLoaderTest.php
@@ -10,64 +10,44 @@
*/
class StreamLoaderTest extends AbstractTest
{
- protected $imagine;
-
- protected function setUp()
- {
- parent::setUp();
-
- $this->imagine = $this->getMockImagine();
- }
-
- public function testFindInvalidFile()
+ public function testThrowsIfInvalidPathGivenOnFind()
{
- $this->imagine
- ->expects($this->never())
- ->method('load')
- ;
-
- $loader = new StreamLoader($this->imagine, 'file://');
+ $loader = new StreamLoader('file://');
$this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
$loader->find($this->tempDir.'/invalid.jpeg');
}
- public function testFindLoadsFile()
+ public function testReturnImageContentOnFind()
{
- $image = $this->getMockImage();
+ $expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg');
- $this->imagine
- ->expects($this->once())
- ->method('load')
- ->with(file_get_contents($this->fixturesDir.'/assets/cats.jpeg'))
- ->will($this->returnValue($image))
- ;
+ $loader = new StreamLoader('file://');
- $loader = new StreamLoader($this->imagine, 'file://');
- $this->assertSame($image, $loader->find($this->fixturesDir.'/assets/cats.jpeg'));
+ $this->assertSame(
+ $expectedContent,
+ $loader->find($this->fixturesDir.'/assets/cats.jpeg')
+ );
}
- public function testFindWithContext()
+ public function testReturnImageContentWhenStreamContextProvidedOnFind()
{
- $image = $this->getMockImage();
-
- $this->imagine
- ->expects($this->once())
- ->method('load')
- ->with(file_get_contents($this->fixturesDir.'/assets/cats.jpeg'))
- ->will($this->returnValue($image))
- ;
+ $expectedContent = file_get_contents($this->fixturesDir.'/assets/cats.jpeg');
$context = stream_context_create();
- $loader = new StreamLoader($this->imagine, 'file://', $context);
- $this->assertSame($image, $loader->find($this->fixturesDir.'/assets/cats.jpeg'));
+ $loader = new StreamLoader('file://', $context);
+
+ $this->assertSame(
+ $expectedContent,
+ $loader->find($this->fixturesDir.'/assets/cats.jpeg')
+ );
}
- public function testConstructorInvalidContext()
+ public function testThrowsIfInvalidResourceGivenInConstructor()
{
$this->setExpectedException('InvalidArgumentException', 'The given context is no valid resource.');
- new StreamLoader($this->imagine, 'file://', true);
+ new StreamLoader('not valid resource', true);
}
}
View
35 Tests/Model/BinaryTest.php
@@ -0,0 +1,35 @@
+<?php
+namespace Liip\ImagineBundle\Tests\Model;
+
+use Liip\ImagineBundle\Model\Binary;
+
+class BinaryTest extends \PHPUnit_Framework_TestCase
+{
+ public function testImplementsBinaryInterface()
+ {
+ $rc = new \ReflectionClass('Liip\ImagineBundle\Model\Binary');
+
+ $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Binary\BinaryInterface'));
+ }
+
+ public function testAllowGetContentSetInConstructor()
+ {
+ $image = new Binary('theContent', 'image/png', 'png');
+
+ $this->assertEquals('theContent', $image->getContent());
+ }
+
+ public function testAllowGetMimeTypeSetInConstructor()
+ {
+ $image = new Binary('aContent', 'image/png', 'png');
+
+ $this->assertEquals('image/png', $image->getMimeType());
+ }
+
+ public function testAllowGetFormatSetInConstructor()
+ {
+ $image = new Binary('aContent', 'image/png', 'png');
+
+ $this->assertEquals('png', $image->getFormat());
+ }
+}
View
2  UPGRADE.md
@@ -9,4 +9,6 @@ Upgrade
* [CacheResolver] Now resolve method has to return the url of the image.
* [CacheResolver] New `isStored` method was added.
* [CacheResolver] The method `getBrowserPath` was removed.
+* [DataLoader] `LoaderInterface::find` now can return string or `BinaryInterface` instance.
+* [DataLoader] `DataManager::find` now can return `BinaryInterface` instance only.
* [Logger] Symfony `LoggerInterface` was replaced with PSR-3 one.
Please sign in to comment.
Something went wrong with that request. Please try again.