2018-08-26 02:54:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Renderer;
|
|
|
|
|
|
|
|
use Engelsystem\Renderer\TwigEngine;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-03-16 22:02:36 +01:00
|
|
|
use Twig\Environment as Twig;
|
|
|
|
use Twig\Loader\LoaderInterface as LoaderInterface;
|
2018-08-26 02:54:52 +02:00
|
|
|
|
|
|
|
class TwigEngineTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Renderer\TwigEngine::__construct
|
|
|
|
* @covers \Engelsystem\Renderer\TwigEngine::get
|
|
|
|
*/
|
|
|
|
public function testGet(): void
|
|
|
|
{
|
|
|
|
/** @var Twig|MockObject $twig */
|
|
|
|
$twig = $this->createMock(Twig::class);
|
|
|
|
|
|
|
|
$path = 'foo.twig';
|
|
|
|
$twig->expects($this->once())
|
|
|
|
->method('render')
|
2018-12-03 23:39:50 +01:00
|
|
|
->with($path, ['lorem' => 'ipsum', 'shared' => 'data'])
|
|
|
|
->willReturn('LoremIpsum data!');
|
2018-08-26 02:54:52 +02:00
|
|
|
|
|
|
|
$engine = new TwigEngine($twig);
|
2018-12-03 23:39:50 +01:00
|
|
|
$engine->share('shared', 'data');
|
|
|
|
|
|
|
|
$return = $engine->get($path, ['lorem' => 'ipsum']);
|
|
|
|
$this->assertEquals('LoremIpsum data!', $return);
|
2018-08-26 02:54:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Renderer\TwigEngine::canRender
|
|
|
|
*/
|
|
|
|
public function testCanRender(): void
|
|
|
|
{
|
|
|
|
/** @var Twig|MockObject $twig */
|
|
|
|
$twig = $this->createMock(Twig::class);
|
|
|
|
/** @var LoaderInterface|MockObject $loader */
|
|
|
|
$loader = $this->getMockForAbstractClass(LoaderInterface::class);
|
|
|
|
|
|
|
|
$path = 'foo.twig';
|
|
|
|
|
|
|
|
$twig->expects($this->once())
|
|
|
|
->method('getLoader')
|
|
|
|
->willReturn($loader);
|
|
|
|
$loader->expects($this->once())
|
|
|
|
->method('exists')
|
|
|
|
->with($path)
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$engine = new TwigEngine($twig);
|
|
|
|
$return = $engine->canRender($path);
|
|
|
|
$this->assertTrue($return);
|
|
|
|
}
|
|
|
|
}
|