|
@@ -8,24 +8,28 @@ use App\Tests\Unit\TestToolsTrait;
|
|
|
use Liip\ImagineBundle\Imagine\Data\DataManager;
|
|
use Liip\ImagineBundle\Imagine\Data\DataManager;
|
|
|
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
|
|
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
|
|
|
use Liip\ImagineBundle\Model\Binary;
|
|
use Liip\ImagineBundle\Model\Binary;
|
|
|
|
|
+use PHPUnit\Framework\MockObject\MockObject;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
+use Psr\Log\LoggerInterface;
|
|
|
|
|
|
|
|
class ImageUtilsTest extends TestCase
|
|
class ImageUtilsTest extends TestCase
|
|
|
{
|
|
{
|
|
|
use TestToolsTrait;
|
|
use TestToolsTrait;
|
|
|
|
|
|
|
|
- private DataManager $dataManager;
|
|
|
|
|
- private FilterManager $filterManager;
|
|
|
|
|
|
|
+ private MockObject | DataManager $dataManager;
|
|
|
|
|
+ private MockObject | FilterManager $filterManager;
|
|
|
|
|
+ private MockObject | LoggerInterface $logger;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
public function setUp(): void
|
|
|
{
|
|
{
|
|
|
$this->dataManager = $this->getMockBuilder(DataManager::class)->disableOriginalConstructor()->getMock();
|
|
$this->dataManager = $this->getMockBuilder(DataManager::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->filterManager = $this->getMockBuilder(FilterManager::class)->disableOriginalConstructor()->getMock();
|
|
$this->filterManager = $this->getMockBuilder(FilterManager::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getImageUtilsMockFor(string $methodName) {
|
|
public function getImageUtilsMockFor(string $methodName) {
|
|
|
- return $this->getMockBuilder(TestableImageUtils::class)
|
|
|
|
|
- ->setConstructorArgs([$this->dataManager, $this->filterManager])
|
|
|
|
|
|
|
+ return $this->getMockBuilder(ImageUtils::class)
|
|
|
|
|
+ ->setConstructorArgs([$this->dataManager, $this->filterManager, $this->logger])
|
|
|
->setMethodsExcept([$methodName])
|
|
->setMethodsExcept([$methodName])
|
|
|
->getMock();
|
|
->getMock();
|
|
|
}
|
|
}
|
|
@@ -60,7 +64,7 @@ class ImageUtilsTest extends TestCase
|
|
|
{
|
|
{
|
|
|
$file = new File();
|
|
$file = new File();
|
|
|
$file->setPath('example.jpg');
|
|
$file->setPath('example.jpg');
|
|
|
- $file->setConfig('');
|
|
|
|
|
|
|
+ $file->setConfig(null);
|
|
|
|
|
|
|
|
$imageUtils = $this->getImageUtilsMockFor('cropImage');
|
|
$imageUtils = $this->getImageUtilsMockFor('cropImage');
|
|
|
|
|
|
|
@@ -110,6 +114,38 @@ class ImageUtilsTest extends TestCase
|
|
|
->with($binary, ImageUtils::FILTER_CROP, $config)
|
|
->with($binary, ImageUtils::FILTER_CROP, $config)
|
|
|
->willReturn($binary);
|
|
->willReturn($binary);
|
|
|
|
|
|
|
|
|
|
+ $this->logger->expects($this->never())->method('error');
|
|
|
|
|
+
|
|
|
|
|
+ $result = $imageUtils->cropImage($file);
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertEquals('mocked_binary_data', $result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see ImageUtils::cropImage()
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testCropImageWithErrorConfig()
|
|
|
|
|
+ {
|
|
|
|
|
+ $file = new File();
|
|
|
|
|
+ $file->setPath('example.jpg');
|
|
|
|
|
+ $file->setConfig('{"hei": 100, "x": 10, "y": 10}');
|
|
|
|
|
+
|
|
|
|
|
+ $imageUtils = $this->getImageUtilsMockFor('cropImage');
|
|
|
|
|
+
|
|
|
|
|
+ $binary = $this->createMock(Binary::class);
|
|
|
|
|
+ $binary->method('getContent')->willReturn('mocked_binary_data');
|
|
|
|
|
+
|
|
|
|
|
+ $this->dataManager->expects($this->once())
|
|
|
|
|
+ ->method('find')
|
|
|
|
|
+ ->with(ImageUtils::FILTER_CROP, $file->getPath())
|
|
|
|
|
+ ->willReturn($binary);
|
|
|
|
|
+
|
|
|
|
|
+ $this->logger->expects($this->exactly(2))
|
|
|
|
|
+ ->method('error')
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
$result = $imageUtils->cropImage($file);
|
|
$result = $imageUtils->cropImage($file);
|
|
|
|
|
|
|
|
$this->assertEquals('mocked_binary_data', $result);
|
|
$this->assertEquals('mocked_binary_data', $result);
|