mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-24 05:38:06 +03:00
Added tests for Image classes
This commit is contained in:
parent
fac519699a
commit
34174b2fbe
3 changed files with 86 additions and 1 deletions
|
@ -27,7 +27,7 @@ class ImageFactory implements FactoryInterface
|
|||
$config = $container->get('config')['phpwkhtmltopdf'];
|
||||
$image = new Image(isset($config['images']) ? $config['images'] : null);
|
||||
|
||||
if (isset($options['url'])) {
|
||||
if (isset($options) && isset($options['url'])) {
|
||||
$image->setPage($options['url']);
|
||||
}
|
||||
|
||||
|
|
29
module/Common/test/Image/ImageBuilderFactoryTest.php
Normal file
29
module/Common/test/Image/ImageBuilderFactoryTest.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
namespace ShlinkioTest\Shlink\Common\Image;
|
||||
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Shlinkio\Shlink\Common\Image\ImageBuilder;
|
||||
use Shlinkio\Shlink\Common\Image\ImageBuilderFactory;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
class ImageBuilderFactoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ImageBuilderFactory
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->factory = new ImageBuilderFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function serviceIsCreated()
|
||||
{
|
||||
$instance = $this->factory->__invoke(new ServiceManager(), '');
|
||||
$this->assertInstanceOf(ImageBuilder::class, $instance);
|
||||
}
|
||||
}
|
56
module/Common/test/Image/ImageFactoryTest.php
Normal file
56
module/Common/test/Image/ImageFactoryTest.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
namespace ShlinkioTest\Shlink\Common\Image;
|
||||
|
||||
use mikehaertl\wkhtmlto\Image;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Shlinkio\Shlink\Common\Image\ImageFactory;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
class ImageFactoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ImageFactory
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->factory = new ImageFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function noPageIsSetWhenOptionsAreNotProvided()
|
||||
{
|
||||
/** @var Image $image */
|
||||
$image = $this->factory->__invoke(new ServiceManager(['services' => [
|
||||
'config' => ['phpwkhtmltopdf' => []],
|
||||
]]), '');
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
|
||||
$ref = new \ReflectionObject($image);
|
||||
$page = $ref->getProperty('_page');
|
||||
$page->setAccessible(true);
|
||||
$this->assertNull($page->getValue($image));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function aPageIsSetWhenOptionsIncludeTheUrl()
|
||||
{
|
||||
$expectedPage = 'foo/bar.html';
|
||||
|
||||
/** @var Image $image */
|
||||
$image = $this->factory->__invoke(new ServiceManager(['services' => [
|
||||
'config' => ['phpwkhtmltopdf' => []],
|
||||
]]), '', ['url' => $expectedPage]);
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
|
||||
$ref = new \ReflectionObject($image);
|
||||
$page = $ref->getProperty('_page');
|
||||
$page->setAccessible(true);
|
||||
$this->assertEquals($expectedPage, $page->getValue($image));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue