summaryrefslogtreecommitdiff
path: root/tests/Unit/Renderer/TwigEngineTest.php
blob: 5e5e59d95bb4fcab0dd67edc30e11d64e109f8b8 (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';
        $twig->expects($this->once())
            ->method('render')
            ->with($path, ['lorem' => 'ipsum', 'shared' => 'data'])
            ->willReturn('LoremIpsum data!');

        $engine = new TwigEngine($twig);
        $engine->share('shared', 'data');

        $return = $engine->get($path, ['lorem' => 'ipsum']);
        $this->assertEquals('LoremIpsum data!', $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);
    }
}