dataManager = $this->getMockBuilder(DataManager::class)->disableOriginalConstructor()->getMock(); $this->filterManager = $this->getMockBuilder(FilterManager::class)->disableOriginalConstructor()->getMock(); } public function getImageUtilsMockFor(string $methodName) { return $this->getMockBuilder(TestableImageUtils::class) ->setConstructorArgs([$this->dataManager, $this->filterManager]) ->setMethodsExcept([$methodName]) ->getMock(); } /** * @see ImageUtils::getCroppingConfig() * @return void * @throws \ReflectionException */ public function testGetCroppingConfig(): void { $imageUtils = $this->getImageUtilsMockFor('getCroppingConfig'); $config = '{"width": 100, "height": 100, "x": 10, "y": 10}'; $result =[ 'filters' => [ 'crop' => [ 'size' => [100, 100], 'start' => [10, 10] ] ] ]; $this->assertEquals($result, $this->invokeMethod($imageUtils, 'getCroppingConfig', [$config])); } /** * @see ImageUtils::cropImage() * @return void */ public function testCropImageWithoutConfig() { $file = new File(); $file->setPath('example.jpg'); $file->setConfig(''); $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); $result = $imageUtils->cropImage($file); $this->assertEquals('mocked_binary_data', $result); } /** * @see ImageUtils::cropImage() * @return void */ public function testCropImageWithConfig() { $file = new File(); $file->setPath('example.jpg'); $file->setConfig('{"width": 100, "height": 100, "x": 10, "y": 10}'); $config = [ 'filters' => [ 'crop' => [ 'size' => [100, 100], 'start' => [10, 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->filterManager->expects($this->once()) ->method('applyFilter') ->with($binary, ImageUtils::FILTER_CROP, $config) ->willReturn($binary); $result = $imageUtils->cropImage($file); $this->assertEquals('mocked_binary_data', $result); } }