Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase test coverage report #417

Merged
merged 1 commit into from
Apr 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions Binary/Loader/AbstractDoctrineLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
44 changes: 0 additions & 44 deletions Binary/Loader/ExtendedFileSystemLoader.php

This file was deleted.

1 change: 0 additions & 1 deletion Binary/Loader/FileSystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Command/RemoveCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Command/ResolveCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 0 additions & 38 deletions Imagine/Data/Transformer/PdfTransformer.php

This file was deleted.

6 changes: 1 addition & 5 deletions ImagineEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
}
76 changes: 76 additions & 0 deletions Tests/Binary/Loader/AbstractDoctrineLoaderTest.php
Original file line number Diff line number Diff line change
@@ -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');
}
}

6 changes: 3 additions & 3 deletions Tests/Binary/Loader/FileSystemLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
55 changes: 55 additions & 0 deletions Tests/Binary/Loader/GridFSLoaderTest.php
Original file line number Diff line number Diff line change
@@ -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');
}
}

2 changes: 1 addition & 1 deletion Tests/Binary/Loader/StreamLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Liip\ImagineBundle\Tests\AbstractTest;

/**
* @covers Liip\ImagineBundle\Binary\Loader\StreamLoader
* @covers Liip\ImagineBundle\Binary\Loader\StreamLoader<extended>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I was not aware of it

*/
class StreamLoaderTest extends AbstractTest
{
Expand Down
3 changes: 3 additions & 0 deletions Tests/Binary/SimpleMimeTypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 33 additions & 0 deletions Tests/DependencyInjection/Compiler/FiltersCompilerPassTest.php
Original file line number Diff line number Diff line change
@@ -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());
}
}

33 changes: 33 additions & 0 deletions Tests/DependencyInjection/Compiler/LoadersCompilerPassTest.php
Original file line number Diff line number Diff line change
@@ -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());
}
}

Loading