[Templating] Made DelegatingEngine::getEngine() public.

This commit is contained in:
Jakub Zalas 2013-06-14 13:44:33 +01:00
parent 0a72a995ba
commit 3f84cd398a
2 changed files with 24 additions and 1 deletions

View File

@ -114,7 +114,7 @@ class DelegatingEngine implements EngineInterface, StreamingEngineInterface
*
* @api
*/
protected function getEngine($name)
public function getEngine($name)
{
foreach ($this->engines as $engine) {
if ($engine->supports($name)) {

View File

@ -104,6 +104,29 @@ class DelegatingEngineTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($delegatingEngine->supports('template.php'));
}
public function testGetExistingEngine()
{
$firstEngine = $this->getEngineMock('template.php', false);
$secondEngine = $this->getEngineMock('template.php', true);
$delegatingEngine = new DelegatingEngine(array($firstEngine, $secondEngine));
$this->assertSame($secondEngine, $delegatingEngine->getEngine('template.php', array('foo' => 'bar')));
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage No engine is able to work with the template "template.php"
*/
public function testGetInvalidEngine()
{
$firstEngine = $this->getEngineMock('template.php', false);
$secondEngine = $this->getEngineMock('template.php', false);
$delegatingEngine = new DelegatingEngine(array($firstEngine, $secondEngine));
$delegatingEngine->getEngine('template.php', array('foo' => 'bar'));
}
private function getEngineMock($template, $supports)
{
$engine = $this->getMock('Symfony\Component\Templating\EngineInterface');