Skip to content

Commit

Permalink
Add failing test case for ThumbnailFilterLoader.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwilson committed Sep 8, 2016
1 parent 0cd8678 commit 1c5c7b2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

sudo: false
Expand Down
16 changes: 8 additions & 8 deletions Tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,51 +54,51 @@ protected function createFilterConfiguration()

protected function getMockCacheManager()
{
return $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array(), array(), '', false);
return $this->getMockBuilder('Liip\ImagineBundle\Imagine\Cache\CacheManager')->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|FilterConfiguration
*/
protected function createFilterConfigurationMock()
{
return $this->getMock('Liip\ImagineBundle\Imagine\Filter\FilterConfiguration');
return $this->getMockBuilder('Liip\ImagineBundle\Imagine\Filter\FilterConfiguration')->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|RouterInterface
*/
protected function createRouterMock()
{
return $this->getMock('Symfony\Component\Routing\RouterInterface');
return $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|ResolverInterface
*/
protected function createResolverMock()
{
return $this->getMock('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface');
return $this->getMockBuilder('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface')->getMock();
}

protected function createEventDispatcherMock()
{
return $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
return $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
}

protected function getMockImage()
{
return $this->getMock('Imagine\Image\ImageInterface');
return $this->getMockBuilder('Imagine\Image\ImageInterface')->getMock();
}

protected function getMockMetaData()
{
return $this->getMock('Imagine\Image\Metadata\MetadataBag');
return $this->getMockBuilder('Imagine\Image\Metadata\MetadataBag')->getMock();
}

protected function createImagineMock()
{
return $this->getMock('Imagine\Image\ImagineInterface');
return $this->getMockBuilder('Imagine\Image\ImagineInterface')->getMock();
}

protected function tearDown()
Expand Down
71 changes: 71 additions & 0 deletions Tests/Imagine/Filter/Loader/ThumbnailFilterLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Liip\ImagineBundle\Tests\Filter;

use Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader;
use Liip\ImagineBundle\Tests\AbstractTest;
use Imagine\Image\Palette\Grayscale;
use Imagine\Image\Box;

/**
* Test cases for ThumbnailFilterLoader class.
*
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader
*/
class ThumbnailFilterLoaderTest extends AbstractTest
{
/**
* @var int
*/
const DUMMY_IMAGE_WIDTH = 500;

/**
* @var int
*/
const DUMMY_IMAGE_HEIGHT = 600;

/**
* @param int $width
* @param int $height
* @param Box $expected
*
* @dataProvider heightWidthProvider
*/
public function testLoad($width, $height, $expected)
{
$loader = new ThumbnailFilterLoader();

$mockImageSize = new Box(
self::DUMMY_IMAGE_WIDTH,
self::DUMMY_IMAGE_HEIGHT
);
$image = $this->getMockImage();
$image->method('getSize')->willReturn($mockImageSize);
$image->method('copy')->willReturn($image);
$image->expects($this->once())
->method('thumbnail')
->with($expected)
->willReturn($image);

$options = [];
$options['size'] = [$width, $height];
$options['allow_upscale'] = true;

$result = $loader->load($image, $options);
}

/**
* @returns array Array containing width/height pairs and an expected size.
*/
public function heightWidthProvider()
{
return [
[200, 129, new Box(200, 129)],
[50, 50, new Box(50, 50)],
[1, 30, new Box(1, 30)],
[null, 60, new Box(50, 60)],
[50, null, new Box(50, 60)],
[1000, 1000, new Box(1000, 1000)]
];
}
}

0 comments on commit 1c5c7b2

Please sign in to comment.