engelsystem/tests/Unit/Renderer/RendererTest.php

67 lines
1.9 KiB
PHP
Raw Normal View History

2017-09-19 23:55:24 +02:00
<?php
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
*/
2017-09-19 23:55:24 +02:00
public function testGet()
{
$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
*/
2017-09-19 23:55:24 +02:00
public function testError()
{
$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('error');
$renderer->setLogger($loggerMock);
$data = $renderer->render('testing.template');
$this->assertEquals('', $data);
}
}