summaryrefslogtreecommitdiff
path: root/tests/Unit/Renderer/RendererTest.php
blob: 0b306c196cb2b4eec695440cbaa2f19745ce7ac7 (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
61
62
63
64
65
66
<?php

namespace Engelsystem\Test\Unit\Renderer;

use Engelsystem\Renderer\EngineInterface;
use Engelsystem\Renderer\Renderer;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class RendererTest extends TestCase
{
    /**
     * @covers \Engelsystem\Renderer\Renderer::render
     * @covers \Engelsystem\Renderer\Renderer::addRenderer
     */
    public function testGet()
    {
        $renderer = new Renderer();

        /** @var EngineInterface|MockObject $nullRenderer */
        $nullRenderer = $this->getMockForAbstractClass(EngineInterface::class);

        $nullRenderer->expects($this->atLeastOnce())
            ->method('canRender')
            ->willReturn(false);
        $renderer->addRenderer($nullRenderer);

        /** @var EngineInterface|MockObject $mockRenderer */
        $mockRenderer = $this->getMockForAbstractClass(EngineInterface::class);

        $mockRenderer->expects($this->atLeastOnce())
            ->method('canRender')
            ->with('foo.template')
            ->willReturn(true);

        $mockRenderer->expects($this->atLeastOnce())
            ->method('get')
            ->with('foo.template', ['lorem' => 'ipsum'])
            ->willReturn('Rendered content');

        $renderer->addRenderer($mockRenderer);
        $data = $renderer->render('foo.template', ['lorem' => 'ipsum']);

        $this->assertEquals('Rendered content', $data);
    }

    /**
     * @covers \Engelsystem\Renderer\Renderer::render
     */
    public function testError()
    {
        $renderer = new Renderer();

        /** @var LoggerInterface|MockObject $loggerMock */
        $loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
        $loggerMock
            ->expects($this->once())
            ->method('error');

        $renderer->setLogger($loggerMock);

        $data = $renderer->render('testing.template');
        $this->assertEquals('', $data);
    }
}