engelsystem/tests/Unit/Renderer/RendererTest.php

69 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2017-09-19 23:55:24 +02:00
<?php
declare(strict_types=1);
namespace Engelsystem\Test\Unit\Renderer;
2017-09-19 23:55:24 +02:00
use Engelsystem\Renderer\EngineInterface;
use Engelsystem\Renderer\Renderer;
use PHPUnit\Framework\MockObject\MockObject;
2017-09-19 23:55:24 +02:00
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
class RendererTest extends TestCase
{
2020-01-02 15:08:08 +01:00
/**
* @covers \Engelsystem\Renderer\Renderer::render
* @covers \Engelsystem\Renderer\Renderer::addRenderer
*/
public function testGet(): void
2017-09-19 23:55:24 +02:00
{
$renderer = new Renderer();
/** @var EngineInterface|MockObject $nullRenderer */
2017-09-19 23:55:24 +02:00
$nullRenderer = $this->getMockForAbstractClass(EngineInterface::class);
$nullRenderer->expects($this->atLeastOnce())
->method('canRender')
->willReturn(false);
$renderer->addRenderer($nullRenderer);
/** @var EngineInterface|MockObject $mockRenderer */
2017-09-19 23:55:24 +02:00
$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);
}
2020-01-02 15:08:08 +01:00
/**
* @covers \Engelsystem\Renderer\Renderer::render
*/
public function testError(): void
2017-09-19 23:55:24 +02:00
{
$renderer = new Renderer();
/** @var LoggerInterface|MockObject $loggerMock */
2017-09-19 23:55:24 +02:00
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
$loggerMock
->expects($this->once())
->method('critical');
2017-09-19 23:55:24 +02:00
$renderer->setLogger($loggerMock);
$data = $renderer->render('testing.template');
$this->assertEquals('', $data);
}
}