-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a bunch of tests and covers annotations
- Loading branch information
1 parent
be933eb
commit 59fb67d
Showing
32 changed files
with
364 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Tests/DependencyInjection/Compiler/FiltersCompilerPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
Tests/DependencyInjection/Compiler/LoadersCompilerPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
|
Oops, something went wrong.