Example...
<?php
namespace AppBundle\Tests\Service\Imagine;
use AppBundle\Service\Imagine\FocusPointHelper;
class FocusPointHelperTest extends \PHPUnit_Framework_TestCase
{
/** @var FocusPointHelper */
protected $helper;
protected function setUp()
{
$this->helper = new FocusPointHelper();
}
/**
* @return array
*/
public function providerFocusBoxSize()
{
return [
[
100,
0,
'1:1',
3644,
2397,
2397,
2397,
],
];
}
/**
* @dataProvider providerFocusBoxSize
*
* @param int $focusX
* @param int $focusY
* @param string $ratio
* @param int $imageWidth
* @param int $imageHeight
* @param int $expectedWidth
* @param int $expectedHeight
*/
public function testFocusBoxSize($focusX, $focusY, $ratio, $imageWidth, $imageHeight, $expectedWidth, $expectedHeight)
{
$expected = [
$expectedWidth,
$expectedHeight,
];
$this->assertEquals($expected, $this->helper->getFocusWidthAndHeight($imageWidth, $imageHeight, $ratio));
}
/**
* @return array
*/
public function providerFocusSourcePoint()
{
return [
[
100,
0,
'1:1',
3644,
2397,
1247,
0,
],
];
}
/**
* @depends testFocusBoxSize
* @dataProvider providerFocusSourcePoint
*
* @param int $focusX
* @param int $focusY
* @param string $ratio
* @param int $imageWidth
* @param int $imageHeight
* @param int $expectedX
* @param int $expectedY
*/
public function testFocusSourcePoint($focusX, $focusY, $ratio, $imageWidth, $imageHeight, $expectedX, $expectedY)
{
$expected = [
$expectedX,
$expectedY,
];
list($focusWidth, $focusHeight) = $this->helper->getFocusWidthAndHeight($imageWidth, $imageHeight, $ratio);
$this->assertEquals(
$expected,
$this->helper->calculateSourcePosition(
$imageWidth,
$imageHeight,
$focusWidth,
$focusHeight,
$focusX,
$focusY,
$ratio
)
);
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage Ratio have to be in the format of e.g. "1:1" or "16:9"
*/
public function testRatioException()
{
$this->helper->getFocusWidthAndHeight(100, 100, '11');
}
}