This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php

124 lines
4.3 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
class DelegatingEngineTest extends \PHPUnit_Framework_TestCase
{
public function testSupportsRetrievesEngineFromTheContainer()
{
$container = $this->getContainerMock(array(
'engine.first' => $this->getEngineMock('template.php', false),
Merge branch '2.3' into 2.4 * 2.3: fixed CS [Process] fixed some volatile tests [HttpKernel] fixed a volatile test [HttpFoundation] fixed some volatile tests Use getPathname() instead of string casting to get BinaryFileReponse file path Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php src/Symfony/Component/ClassLoader/Tests/ApcUniversalClassLoaderTest.php src/Symfony/Component/Config/Definition/ReferenceDumper.php src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php src/Symfony/Component/Console/Application.php src/Symfony/Component/Console/Tests/ApplicationTest.php src/Symfony/Component/Filesystem/Exception/IOException.php src/Symfony/Component/Form/Extension/Templating/TemplatingExtension.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php src/Symfony/Component/HttpKernel/Tests/Profiler/Mock/RedisMock.php src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php src/Symfony/Component/PropertyAccess/PropertyAccessor.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php src/Symfony/Component/Serializer/Encoder/XmlEncoder.php src/Symfony/Component/Validator/Constraints/CollectionValidator.php src/Symfony/Component/Validator/Tests/ExecutionContextTest.php
2014-09-22 09:51:05 +01:00
'engine.second' => $this->getEngineMock('template.php', true),
));
$delegatingEngine = new DelegatingEngine($container, array('engine.first', 'engine.second'));
$this->assertTrue($delegatingEngine->supports('template.php'));
}
public function testGetExistingEngine()
{
$firstEngine = $this->getEngineMock('template.php', false);
$secondEngine = $this->getEngineMock('template.php', true);
$container = $this->getContainerMock(array(
'engine.first' => $firstEngine,
Merge branch '2.3' into 2.4 * 2.3: fixed CS [Process] fixed some volatile tests [HttpKernel] fixed a volatile test [HttpFoundation] fixed some volatile tests Use getPathname() instead of string casting to get BinaryFileReponse file path Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php src/Symfony/Component/ClassLoader/Tests/ApcUniversalClassLoaderTest.php src/Symfony/Component/Config/Definition/ReferenceDumper.php src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php src/Symfony/Component/Console/Application.php src/Symfony/Component/Console/Tests/ApplicationTest.php src/Symfony/Component/Filesystem/Exception/IOException.php src/Symfony/Component/Form/Extension/Templating/TemplatingExtension.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php src/Symfony/Component/HttpKernel/Tests/Profiler/Mock/RedisMock.php src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php src/Symfony/Component/PropertyAccess/PropertyAccessor.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php src/Symfony/Component/Serializer/Encoder/XmlEncoder.php src/Symfony/Component/Validator/Constraints/CollectionValidator.php src/Symfony/Component/Validator/Tests/ExecutionContextTest.php
2014-09-22 09:51:05 +01:00
'engine.second' => $secondEngine,
));
$delegatingEngine = new DelegatingEngine($container, array('engine.first', 'engine.second'));
$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);
$container = $this->getContainerMock(array(
'engine.first' => $firstEngine,
Merge branch '2.3' into 2.4 * 2.3: fixed CS [Process] fixed some volatile tests [HttpKernel] fixed a volatile test [HttpFoundation] fixed some volatile tests Use getPathname() instead of string casting to get BinaryFileReponse file path Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php src/Symfony/Component/ClassLoader/Tests/ApcUniversalClassLoaderTest.php src/Symfony/Component/Config/Definition/ReferenceDumper.php src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php src/Symfony/Component/Console/Application.php src/Symfony/Component/Console/Tests/ApplicationTest.php src/Symfony/Component/Filesystem/Exception/IOException.php src/Symfony/Component/Form/Extension/Templating/TemplatingExtension.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php src/Symfony/Component/HttpKernel/Tests/Profiler/Mock/RedisMock.php src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php src/Symfony/Component/PropertyAccess/PropertyAccessor.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php src/Symfony/Component/Serializer/Encoder/XmlEncoder.php src/Symfony/Component/Validator/Constraints/CollectionValidator.php src/Symfony/Component/Validator/Tests/ExecutionContextTest.php
2014-09-22 09:51:05 +01:00
'engine.second' => $secondEngine,
));
$delegatingEngine = new DelegatingEngine($container, array('engine.first', 'engine.second'));
$delegatingEngine->getEngine('template.php', array('foo' => 'bar'));
}
public function testRenderResponseWithFrameworkEngine()
{
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
$engine = $this->getFrameworkEngineMock('template.php', true);
$engine->expects($this->once())
->method('renderResponse')
->with('template.php', array('foo' => 'bar'))
->will($this->returnValue($response));
$container = $this->getContainerMock(array('engine' => $engine));
$delegatingEngine = new DelegatingEngine($container, array('engine'));
$this->assertSame($response, $delegatingEngine->renderResponse('template.php', array('foo' => 'bar')));
}
public function testRenderResponseWithTemplatingEngine()
{
$engine = $this->getEngineMock('template.php', true);
$container = $this->getContainerMock(array('engine' => $engine));
$delegatingEngine = new DelegatingEngine($container, array('engine'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $delegatingEngine->renderResponse('template.php', array('foo' => 'bar')));
}
private function getEngineMock($template, $supports)
{
$engine = $this->getMock('Symfony\Component\Templating\EngineInterface');
$engine->expects($this->once())
->method('supports')
->with($template)
->will($this->returnValue($supports));
return $engine;
}
private function getFrameworkEngineMock($template, $supports)
{
$engine = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
$engine->expects($this->once())
->method('supports')
->with($template)
->will($this->returnValue($supports));
return $engine;
}
private function getContainerMock($services)
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$i = 0;
foreach ($services as $id => $service) {
$container->expects($this->at($i++))
->method('get')
->with($id)
->will($this->returnValue($service));
}
return $container;
}
}