engelsystem/tests/Unit/Renderer/TwigEngineTest.php

61 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Engelsystem\Test\Unit\Renderer;
use Engelsystem\Renderer\TwigEngine;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Twig\Environment as Twig;
use Twig\Loader\LoaderInterface as LoaderInterface;
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!');
$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);
}
/**
* @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);
}
}