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

[1.0][tests] increase code coverage by tests. #290

Merged
merged 1 commit into from
Jan 3, 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
19 changes: 19 additions & 0 deletions Tests/Functional/Controller/ImagineControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace Liip\ImagineBundle\Tests\Functional\Controller;

use Liip\ImagineBundle\Tests\Functional\WebTestCase;

/**
* @covers Liip\ImagineBundle\Controller\ImagineController
*/
class ImagineControllerTest extends WebTestCase
{
public function testCouldBeGetFromContainer()
{
$this->createClient();

$controller = self::$kernel->getContainer()->get('liip_imagine.controller');

$this->assertInstanceOf('Liip\ImagineBundle\Controller\ImagineController', $controller);
}
}
52 changes: 52 additions & 0 deletions Tests/Routing/ImagineLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace Liip\ImagineBundle\Tests\Routing;

use Liip\ImagineBundle\Routing\ImagineLoader;

/**
* @covers Liip\ImagineBundle\Routing\ImagineLoader
*/
class ImagineLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testSubClassOfLoader()
{
$rc = new \ReflectionClass('Liip\ImagineBundle\Routing\ImagineLoader');

$this->assertTrue($rc->isSubclassOf('Symfony\Component\Config\Loader\Loader'));
}

public function testReturnTrueIfResourceTypeImagineOnSupports()
{
$loader = new ImagineLoader('anAction', '', array());

$this->assertTrue($loader->supports('aResource', 'imagine'));
}

public function testReturnFalseIfResourceTypeNotImagineOnSupports()
{
$loader = new ImagineLoader('anAction', '', array());

$this->assertFalse($loader->supports('aResource', 'notImagine'));
}

public function testReturnCollectionWithOneRouterIfOneFilterPassedOnLoad()
{
$loader = new ImagineLoader('liip_imagine.controller:filterAction', '/media/cache', array(
'thumbnail' => array('filter_config_here')
));

$result = $loader->load('aResource', 'aType');

$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $result);
$this->assertCount(1, $result);

$route = $result->get('_imagine_thumbnail');
$this->assertEquals(
array(
'_controller' => 'liip_imagine.controller:filterAction',
'filter' => 'thumbnail',
),
$route->getDefaults()
);
}
}
58 changes: 58 additions & 0 deletions Tests/Templating/Helper/ImagineHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Liip\ImagineBundle\Tests\Templating\Helper;

use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Templating\Helper\ImagineHelper;

/**
* @covers Liip\ImagineBundle\Templating\Helper\ImagineHelper
*/
class ImagineHelperTest extends \PHPUnit_Framework_TestCase
{
public function testSubClassOfHelper()
{
$rc = new \ReflectionClass('Liip\ImagineBundle\Templating\Helper\ImagineHelper');

$this->assertTrue($rc->isSubclassOf('Symfony\Component\Templating\Helper\Helper'));
}

public function testCouldBeConstructedWithCacheManagerAsArgument()
{
new ImagineHelper($this->createCacheManagerMock());
}

public function testAllowGetName()
{
$helper = new ImagineHelper($this->createCacheManagerMock());

$this->assertEquals('liip_imagine', $helper->getName());
}

public function testProxyCallToCacheManagerOnFilter()
{
$expectedPath = 'thePathToTheImage';
$expectedFilter = 'thumbnail';
$expectedCachePath = 'thePathToTheCachedImage';

$cacheManager = $this->createCacheManagerMock();
$cacheManager
->expects($this->once())
->method('getBrowserPath')
->with($expectedPath, $expectedFilter)
->will($this->returnValue($expectedCachePath))
;

$helper = new ImagineHelper($cacheManager);

$this->assertEquals($expectedCachePath, $helper->filter($expectedPath, $expectedFilter));
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|CacheManager
*/
protected function createCacheManagerMock()
{
return $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array(), array(), '', false);
}
}
69 changes: 69 additions & 0 deletions Tests/Templating/ImagineExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Liip\ImagineBundle\Tests\Templating\Helper;

use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Templating\ImagineExtension;

/**
* @covers Liip\ImagineBundle\Templating\ImagineExtension
*/
class ImagineExtensionTest extends \PHPUnit_Framework_TestCase
{
public function testSubClassOfHelper()
{
$rc = new \ReflectionClass('Liip\ImagineBundle\Templating\ImagineExtension');

$this->assertTrue($rc->isSubclassOf('Twig_Extension'));
}

public function testCouldBeConstructedWithCacheManagerAsArgument()
{
new ImagineExtension($this->createCacheManagerMock());
}

public function testAllowGetName()
{
$extension = new ImagineExtension($this->createCacheManagerMock());

$this->assertEquals('liip_imagine', $extension->getName());
}

public function testProxyCallToCacheManagerOnFilter()
{
$expectedPath = 'thePathToTheImage';
$expectedFilter = 'thumbnail';
$expectedCachePath = 'thePathToTheCachedImage';

$cacheManager = $this->createCacheManagerMock();
$cacheManager
->expects($this->once())
->method('getBrowserPath')
->with($expectedPath, $expectedFilter)
->will($this->returnValue($expectedCachePath))
;

$extension = new ImagineExtension($cacheManager);

$this->assertEquals($expectedCachePath, $extension->filter($expectedPath, $expectedFilter));
}

public function testAddsFilterMethodToFiltersList()
{
$extension = new ImagineExtension($this->createCacheManagerMock());

$filters = $extension->getFilters();

$this->assertInternalType('array', $filters);
$this->assertCount(1, $filters);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|CacheManager
*/
protected function createCacheManagerMock()
{
return $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array(), array(), '', false);
}
}

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"require-dev": {
"symfony/browser-kit": "~2.3",
"symfony/yaml": "~2.3",
"twig/twig": "~1.0",
"doctrine/cache": "~1.1",
"aws/aws-sdk-php": "~2.4",
"amazonwebservices/aws-sdk-for-php": "~1.0"
Expand Down