2017-09-19 23:55:24 +02:00
|
|
|
<?php
|
|
|
|
|
2017-10-31 14:23:23 +01:00
|
|
|
namespace Engelsystem\Test\Unit\Renderer;
|
2017-09-19 23:55:24 +02:00
|
|
|
|
|
|
|
use Engelsystem\Renderer\EngineInterface;
|
|
|
|
use Engelsystem\Renderer\Renderer;
|
2019-04-24 10:45:00 +02:00
|
|
|
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();
|
|
|
|
|
2019-04-24 10:45:00 +02:00
|
|
|
/** @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);
|
|
|
|
|
2019-04-24 10:45:00 +02:00
|
|
|
/** @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();
|
|
|
|
|
2019-04-24 10:45:00 +02:00
|
|
|
/** @var LoggerInterface|MockObject $loggerMock */
|
2017-09-19 23:55:24 +02:00
|
|
|
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
|
|
|
|
$loggerMock
|
|
|
|
->expects($this->once())
|
2020-05-10 16:01:30 +02:00
|
|
|
->method('critical');
|
2017-09-19 23:55:24 +02:00
|
|
|
|
|
|
|
$renderer->setLogger($loggerMock);
|
|
|
|
|
|
|
|
$data = $renderer->render('testing.template');
|
|
|
|
$this->assertEquals('', $data);
|
|
|
|
}
|
|
|
|
}
|