Contao\CoreBundle\Test\Image\ImageFactoryTest::testCreateWithImageSize PHP Méthode

testCreateWithImageSize() public méthode

Tests the create() method.
    public function testCreateWithImageSize()
    {
        $path = $this->getRootDir() . '/images/dummy.jpg';
        $imageMock = $this->getMockBuilder('Contao\\Image\\Image')->disableOriginalConstructor()->getMock();
        $resizer = $this->getMockBuilder('Contao\\Image\\Resizer')->disableOriginalConstructor()->getMock();
        $resizer->expects($this->once())->method('resize')->with($this->callback(function ($image) use($path) {
            /* @var Image $image */
            $this->assertEquals($path, $image->getPath());
            $this->assertEquals(new ImportantPart(new Point(50, 50), new Box(25, 25)), $image->getImportantPart());
            return true;
        }), $this->callback(function ($config) {
            /* @var ResizeConfiguration $config */
            $this->assertEquals(100, $config->getWidth());
            $this->assertEquals(200, $config->getHeight());
            $this->assertEquals(ResizeConfiguration::MODE_BOX, $config->getMode());
            $this->assertEquals(50, $config->getZoomLevel());
            return true;
        }), $this->callback(function ($options) {
            /* @var ResizeOptions $options */
            $this->assertEquals(['jpeg_quality' => 80, 'interlace' => ImageInterface::INTERLACE_PLANE], $options->getImagineOptions());
            $this->assertEquals($this->getRootDir() . '/target/path.jpg', $options->getTargetPath());
            return true;
        }))->willReturn($imageMock);
        $framework = $this->getMockBuilder('Contao\\CoreBundle\\Framework\\ContaoFramework')->disableOriginalConstructor()->getMock();
        $imageSizeModel = $this->getMock('Contao\\ImageSizeModel');
        $imageSizeModel->expects($this->any())->method('__get')->will($this->returnCallback(function ($key) {
            return ['width' => '100', 'height' => '200', 'resizeMode' => ResizeConfiguration::MODE_BOX, 'zoom' => '50'][$key];
        }));
        $imageSizeAdapter = $this->getMockBuilder('Contao\\CoreBundle\\Framework\\Adapter')->disableOriginalConstructor()->getMock();
        $imageSizeAdapter->expects($this->any())->method('__call')->willReturn($imageSizeModel);
        $filesModel = $this->getMock('Contao\\FilesModel');
        $filesModel->expects($this->any())->method('__get')->will($this->returnCallback(function ($key) {
            return ['importantPartX' => '50', 'importantPartY' => '50', 'importantPartWidth' => '25', 'importantPartHeight' => '25'][$key];
        }));
        $filesAdapter = $this->getMockBuilder('Contao\\CoreBundle\\Framework\\Adapter')->disableOriginalConstructor()->getMock();
        $filesAdapter->expects($this->any())->method('__call')->willReturn($filesModel);
        $framework->expects($this->any())->method('getAdapter')->will($this->returnCallback(function ($key) use($imageSizeAdapter, $filesAdapter) {
            return ['Contao\\ImageSizeModel' => $imageSizeAdapter, 'Contao\\FilesModel' => $filesAdapter][$key];
        }));
        $imageFactory = $this->createImageFactory($resizer, null, null, null, $framework);
        $image = $imageFactory->create($path, 1, $this->getRootDir() . '/target/path.jpg');
        $this->assertSame($imageMock, $image);
    }