Skip to content

Commit

Permalink
Merge pull request #787 from antoligy/list-deprecation
Browse files Browse the repository at this point in the history
List deprecation - closes #731
  • Loading branch information
lsmith77 authored Sep 19, 2016
2 parents c2562a2 + 91ee4c8 commit 15ecc04
Show file tree
Hide file tree
Showing 16 changed files with 423 additions and 23 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
3 changes: 2 additions & 1 deletion Imagine/Filter/Loader/BackgroundFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function load(ImageInterface $image, array $options = array())
$size = $image->getSize();

if (isset($options['size'])) {
list($width, $height) = $options['size'];
$width = isset($options['size'][0]) ? $options['size'][0] : null;
$height = isset($options['size'][1]) ? $options['size'][1] : null;

$position = isset($options['position']) ? $options['position'] : 'center';
switch ($position) {
Expand Down
7 changes: 5 additions & 2 deletions Imagine/Filter/Loader/CropFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ class CropFilterLoader implements LoaderInterface
*/
public function load(ImageInterface $image, array $options = array())
{
list($x, $y) = $options['start'];
list($width, $height) = $options['size'];
$x = isset($options['start'][0]) ? $options['start'][0] : null;
$y = isset($options['start'][1]) ? $options['start'][1] : null;

$width = isset($options['size'][0]) ? $options['size'][0] : null;
$height = isset($options['size'][1]) ? $options['size'][1] : null;

$filter = new Crop(new Point($x, $y), new Box($width, $height));
$image = $filter->apply($image);
Expand Down
4 changes: 3 additions & 1 deletion Imagine/Filter/Loader/PasteFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function __construct(ImagineInterface $imagine, $rootPath)
*/
public function load(ImageInterface $image, array $options = array())
{
list($x, $y) = $options['start'];
$x = isset($options['start'][0]) ? $options['start'][0] : null;
$y = isset($options['start'][1]) ? $options['start'][1] : null;

$destImage = $this->imagine->open($this->rootPath.'/'.$options['image']);

return $image->paste($destImage, new Point($x, $y));
Expand Down
2 changes: 1 addition & 1 deletion Imagine/Filter/Loader/RelativeResizeFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RelativeResizeFilterLoader implements LoaderInterface
*/
public function load(ImageInterface $image, array $options = array())
{
if (list($method, $parameter) = each($options)) {
foreach ($options as $method => $parameter) {
$filter = new RelativeResize($method, $parameter);

return $filter->apply($image);
Expand Down
3 changes: 2 additions & 1 deletion Imagine/Filter/Loader/ResizeFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class ResizeFilterLoader implements LoaderInterface
*/
public function load(ImageInterface $image, array $options = array())
{
list($width, $height) = $options['size'];
$width = isset($options['size'][0]) ? $options['size'][0] : null;
$height = isset($options['size'][1]) ? $options['size'][1] : null;

$filter = new Resize(new Box($width, $height));

Expand Down
29 changes: 23 additions & 6 deletions Imagine/Filter/Loader/ScaleFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@
*/
class ScaleFilterLoader implements LoaderInterface
{
public function __construct($dimentionKey = 'dim', $ratioKey = 'to', $absoluteRatio = true)
/**
* @var string
*/
protected $dimensionKey;

/**
* @var string
*/
protected $ratioKey;

/**
* @var bool
*/
protected $absoluteRatio;

public function __construct($dimensionKey = 'dim', $ratioKey = 'to', $absoluteRatio = true)
{
$this->dimentionKey = $dimentionKey;
$this->dimensionKey = $dimensionKey;
$this->ratioKey = $ratioKey;
$this->absoluteRatio = $absoluteRatio;
}
Expand All @@ -25,8 +40,8 @@ public function __construct($dimentionKey = 'dim', $ratioKey = 'to', $absoluteRa
*/
public function load(ImageInterface $image, array $options = array())
{
if (!isset($options[$this->dimentionKey]) && !isset($options[$this->ratioKey])) {
throw new \InvalidArgumentException("Missing $this->dimentionKey or $this->ratioKey option.");
if (!isset($options[$this->dimensionKey]) && !isset($options[$this->ratioKey])) {
throw new \InvalidArgumentException("Missing $this->dimensionKey or $this->ratioKey option.");
}

$size = $image->getSize();
Expand All @@ -35,8 +50,10 @@ public function load(ImageInterface $image, array $options = array())

if (isset($options[$this->ratioKey])) {
$ratio = $this->absoluteRatio ? $options[$this->ratioKey] : $this->calcAbsoluteRatio($options[$this->ratioKey]);
} elseif (isset($options[$this->dimentionKey])) {
list($width, $height) = $options[$this->dimentionKey];
} elseif (isset($options[$this->dimensionKey])) {
$size = $options[$this->dimensionKey];
$width = isset($size[0]) ? $size[0] : null;
$height = isset($size[1]) ? $size[1] : null;

$widthRatio = $width / $origWidth;
$heightRatio = $height / $origHeight;
Expand Down
3 changes: 2 additions & 1 deletion Imagine/Filter/Loader/ThumbnailFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function load(ImageInterface $image, array $options = array())
$filter = ImageInterface::FILTER_UNDEFINED;
}

list($width, $height) = $options['size'];
$width = isset($options['size'][0]) ? $options['size'][0] : null;
$height = isset($options['size'][1]) ? $options['size'][1] : null;

$size = $image->getSize();
$origWidth = $size->getWidth();
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
61 changes: 61 additions & 0 deletions Tests/Imagine/Filter/Loader/CropFilterLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Liip\ImagineBundle\Tests\Filter;

use Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader;
use Liip\ImagineBundle\Tests\AbstractTest;
use Imagine\Image\Box;
use Imagine\Image\Point;

/**
* Test cases for CropFilterLoader class.
*
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader
*
* @author Alex Wilson <[email protected]>
*/
class CropFilterLoaderTest extends AbstractTest
{
/**
* @param int[] $coordinates
* @param int[] $area
*
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader::load
*
* @dataProvider cropDataProvider
*/
public function testLoad($coordinates, $area)
{
$x = $coordinates[0];
$y = $coordinates[1];

$width = $area[0];
$height = $area[1];

$loader = new CropFilterLoader();

$image = $this->getMockImage();
$image->expects($this->once())
->method('crop')
->with(new Point($x, $y), new Box($width, $height))
->willReturn($image);

$options = array();
$options['start'] = $coordinates;
$options['size'] = $area;

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

/**
* @returns array Array containing coordinate and width/height pairs.
*/
public function cropDataProvider()
{
return array(
array(array(140, 130), array(200, 129)),
array(array(30, 60), array(50, 50)),
array(array(400, 500), array(1, 30)),
);
}
}
4 changes: 2 additions & 2 deletions Tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testItWorksSomeHow()
})
;

$loader->load($image, array('max' => array(100, 100)));
$loader->load($image, array('max' => array(100, 90)));

return array($initialSize, $resultSize);
}
Expand All @@ -56,6 +56,6 @@ public function testFitBoundingBox($sizes)
{
list($initialSize, $resultSize) = $sizes;
$this->assertLessThanOrEqual(100, $resultSize->getHeight());
$this->assertLessThanOrEqual(100, $resultSize->getWidth());
$this->assertLessThanOrEqual(90, $resultSize->getWidth());
}
}
76 changes: 76 additions & 0 deletions Tests/Imagine/Filter/Loader/PasteFilterLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Liip\ImagineBundle\Tests\Filter;

use Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader;
use Liip\ImagineBundle\Tests\AbstractTest;
use Imagine\Image\Box;
use Imagine\Image\Point;

/**
* Test cases for PasteFilterLoader class.
*
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader
*
* @author Alex Wilson <[email protected]>
*/
class PasteFilterLoaderTest extends AbstractTest
{
/**
* @var int
*/
const DUMMY_IMAGE_WIDTH = 500;

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

/**
* @param int $x
* @param int $y
* @param Point $expected
*
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader::load
*
* @dataProvider pasteProvider
*/
public function testLoad($x, $y, $expected)
{
$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('paste')
->with($image, $expected)
->willReturn($image);

$imagineMock = $this->createImagineMock();
$imagineMock
->method('open')
->willReturn($image);
$loader = new PasteFilterLoader($imagineMock, '');

$options = array();
$options['start'] = array($x, $y);
$options['image'] = '';

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

/**
* @returns array Array containing coordinates to paste.
*/
public function pasteProvider()
{
return array(
array(200, 129, new Point(200, 129)),
array(50, 50, new Point(50, 50)),
array(1, 30, new Point(1, 30)),
);
}
}
Empty file.
53 changes: 53 additions & 0 deletions Tests/Imagine/Filter/Loader/ResizeFilterLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Liip\ImagineBundle\Tests\Filter;

use Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader;
use Liip\ImagineBundle\Tests\AbstractTest;
use Imagine\Image\Box;

/**
* Test cases for ResizeFilterLoader class.
*
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader
*
* @author Alex Wilson <[email protected]>
*/
class ResizeFilterLoaderTest extends AbstractTest
{
/**
* @param int $width
* @param int $height
*
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader::load
*
* @dataProvider resizeDataProvider
*/
public function testLoad($width, $height)
{
$loader = new ResizeFilterLoader();

$image = $this->getMockImage();
$image->expects($this->once())
->method('resize')
->with(new Box($width, $height))
->willReturn($image);

$options = array();
$options['size'] = array($width, $height);

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

/**
* @returns array Array containing width/height pairs.
*/
public function resizeDataProvider()
{
return array(
array(140, 130),
array(30, 60),
array(400, 500),
);
}
}
Loading

0 comments on commit 15ecc04

Please sign in to comment.