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;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-10-31 14:23:23 +01:00
|
|
|
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
2017-09-19 23:55:24 +02:00
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
|
|
class RendererTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testGet()
|
|
|
|
{
|
|
|
|
$renderer = new Renderer();
|
|
|
|
|
2017-10-31 14:23:23 +01:00
|
|
|
/** @var MockObject|EngineInterface $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);
|
|
|
|
|
2017-10-31 14:23:23 +01:00
|
|
|
/** @var MockObject|EngineInterface $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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testError()
|
|
|
|
{
|
|
|
|
$renderer = new Renderer();
|
|
|
|
|
2017-10-31 14:23:23 +01:00
|
|
|
/** @var MockObject|LoggerInterface $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);
|
|
|
|
}
|
|
|
|
}
|