shlink/module/Common/test/Image/ImageFactoryTest.php

54 lines
1.5 KiB
PHP
Raw Normal View History

2016-08-18 17:37:50 +03:00
<?php
2017-10-12 11:13:20 +03:00
declare(strict_types=1);
2016-08-18 17:37:50 +03:00
namespace ShlinkioTest\Shlink\Common\Image;
use mikehaertl\wkhtmlto\Image;
2017-03-24 22:34:18 +03:00
use PHPUnit\Framework\TestCase;
use ReflectionObject;
2016-08-18 17:37:50 +03:00
use Shlinkio\Shlink\Common\Image\ImageFactory;
use Zend\ServiceManager\ServiceManager;
class ImageFactoryTest extends TestCase
{
/** @var ImageFactory */
private $factory;
2016-08-18 17:37:50 +03:00
2019-02-16 12:53:45 +03:00
public function setUp(): void
2016-08-18 17:37:50 +03:00
{
$this->factory = new ImageFactory();
}
2019-02-17 22:28:34 +03:00
/** @test */
2016-08-18 17:37:50 +03:00
public function noPageIsSetWhenOptionsAreNotProvided()
{
/** @var Image $image */
$image = $this->factory->__invoke(new ServiceManager(['services' => [
'config' => ['wkhtmltopdf' => []],
2016-08-18 17:37:50 +03:00
]]), '');
$this->assertInstanceOf(Image::class, $image);
$ref = new ReflectionObject($image);
2016-08-18 17:37:50 +03:00
$page = $ref->getProperty('_page');
$page->setAccessible(true);
$this->assertNull($page->getValue($image));
}
2019-02-17 22:28:34 +03:00
/** @test */
2016-08-18 17:37:50 +03:00
public function aPageIsSetWhenOptionsIncludeTheUrl()
{
$expectedPage = 'foo/bar.html';
/** @var Image $image */
$image = $this->factory->__invoke(new ServiceManager(['services' => [
'config' => ['wkhtmltopdf' => []],
2016-08-18 17:37:50 +03:00
]]), '', ['url' => $expectedPage]);
$this->assertInstanceOf(Image::class, $image);
$ref = new ReflectionObject($image);
2016-08-18 17:37:50 +03:00
$page = $ref->getProperty('_page');
$page->setAccessible(true);
$this->assertEquals($expectedPage, $page->getValue($image));
}
}