2018-08-26 02:54:52 +02:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-08-26 02:54:52 +02:00
|
|
|
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
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testGet(): void
|
2018-08-26 02:54:52 +02:00
|
|
|
{
|
|
|
|
/** @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
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testCanRender(): void
|
2018-08-26 02:54:52 +02:00
|
|
|
{
|
|
|
|
/** @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);
|
|
|
|
}
|
|
|
|
}
|