blob: 9d0618f14774aedb50e5f40c2a372b2f6c0e8d38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<?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_LoaderInterface as LoaderInterface;
class TwigEngineTest extends TestCase
{
/**
* @covers \Engelsystem\Renderer\TwigEngine::__construct
* @covers \Engelsystem\Renderer\TwigEngine::get
*/
public function testGet()
{
/** @var Twig|MockObject $twig */
$twig = $this->createMock(Twig::class);
$path = 'foo.twig';
$data = ['lorem' => 'ipsum'];
$twig->expects($this->once())
->method('render')
->with($path, $data)
->willReturn('LoremIpsum!');
$engine = new TwigEngine($twig);
$return = $engine->get($path, $data);
$this->assertEquals('LoremIpsum!', $return);
}
/**
* @covers \Engelsystem\Renderer\TwigEngine::canRender
*/
public function testCanRender()
{
/** @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);
}
}
|