made Symfony compatible with both Twig 1.x and 2.x

This commit is contained in:
Fabien Potencier 2015-08-13 09:59:41 +02:00
parent d6d93dd50a
commit a5c7a85b78
25 changed files with 47 additions and 42 deletions

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=5.3.3", "php": ">=5.3.3",
"doctrine/common": "~2.3", "doctrine/common": "~2.3",
"twig/twig": "~1.12,>=1.12.3", "twig/twig": "~1.20|~2.0",
"psr/log": "~1.0" "psr/log": "~1.0"
}, },
"replace": { "replace": {

View File

@ -16,7 +16,7 @@ namespace Symfony\Bridge\Twig\Node;
*/ */
class FormThemeNode extends \Twig_Node class FormThemeNode extends \Twig_Node
{ {
public function __construct(\Twig_NodeInterface $form, \Twig_NodeInterface $resources, $lineno, $tag = null) public function __construct(\Twig_Node $form, \Twig_Node $resources, $lineno, $tag = null)
{ {
parent::__construct(array('form' => $form, 'resources' => $resources), array(), $lineno, $tag); parent::__construct(array('form' => $form, 'resources' => $resources), array(), $lineno, $tag);
} }

View File

@ -16,7 +16,7 @@ namespace Symfony\Bridge\Twig\Node;
*/ */
class TransNode extends \Twig_Node class TransNode extends \Twig_Node
{ {
public function __construct(\Twig_NodeInterface $body, \Twig_NodeInterface $domain = null, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, \Twig_Node_Expression $locale = null, $lineno = 0, $tag = null) public function __construct(\Twig_Node $body, \Twig_Node $domain = null, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, \Twig_Node_Expression $locale = null, $lineno = 0, $tag = null)
{ {
parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars, 'locale' => $locale), array(), $lineno, $tag); parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars, 'locale' => $locale), array(), $lineno, $tag);
} }
@ -83,7 +83,7 @@ class TransNode extends \Twig_Node
$compiler->raw(");\n"); $compiler->raw(");\n");
} }
protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false) protected function compileString(\Twig_Node $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false)
{ {
if ($body instanceof \Twig_Node_Expression_Constant) { if ($body instanceof \Twig_Node_Expression_Constant) {
$msg = $body->getAttribute('value'); $msg = $body->getAttribute('value');

View File

@ -19,7 +19,7 @@ use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class TranslationDefaultDomainNodeVisitor implements \Twig_NodeVisitorInterface class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor
{ {
/** /**
* @var Scope * @var Scope
@ -37,7 +37,7 @@ class TranslationDefaultDomainNodeVisitor implements \Twig_NodeVisitorInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env) protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
{ {
if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) { if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
$this->scope = $this->scope->enter(); $this->scope = $this->scope->enter();
@ -89,7 +89,7 @@ class TranslationDefaultDomainNodeVisitor implements \Twig_NodeVisitorInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
{ {
if ($node instanceof TransDefaultDomainNode) { if ($node instanceof TransDefaultDomainNode) {
return false; return false;

View File

@ -18,7 +18,7 @@ use Symfony\Bridge\Twig\Node\TransNode;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class TranslationNodeVisitor implements \Twig_NodeVisitorInterface class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
{ {
const UNDEFINED_DOMAIN = '_undefined'; const UNDEFINED_DOMAIN = '_undefined';
@ -45,7 +45,7 @@ class TranslationNodeVisitor implements \Twig_NodeVisitorInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env) protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
{ {
if (!$this->enabled) { if (!$this->enabled) {
return $node; return $node;
@ -85,7 +85,7 @@ class TranslationNodeVisitor implements \Twig_NodeVisitorInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
{ {
return $node; return $node;
} }

View File

@ -195,7 +195,7 @@
{# Labels #} {# Labels #}
{%- block form_label -%} {%- block form_label -%}
{% if label is not sameas(false) %} {% if label is not same as(false) %}
{%- if not compound -%} {%- if not compound -%}
{% set label_attr = label_attr|merge({'for': id}) %} {% set label_attr = label_attr|merge({'for': id}) %}
{%- endif -%} {%- endif -%}

View File

@ -21,7 +21,7 @@ class RoutingExtensionTest extends TestCase
*/ */
public function testEscaping($template, $mustBeEscaped) public function testEscaping($template, $mustBeEscaped)
{ {
$twig = new \Twig_Environment(null, array('debug' => true, 'cache' => false, 'autoescape' => true, 'optimizations' => 0)); $twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface'))); $twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
$nodes = $twig->parse($twig->tokenize($template)); $nodes = $twig->parse($twig->tokenize($template));

View File

@ -42,7 +42,7 @@ class FormThemeTest extends TestCase
$node = new FormThemeNode($form, $resources, 0); $node = new FormThemeNode($form, $resources, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
$this->assertEquals( $this->assertEquals(
sprintf( sprintf(

View File

@ -24,7 +24,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 0); $node = new SearchAndRenderBlockNode('form_widget', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
$this->assertEquals( $this->assertEquals(
sprintf( sprintf(
@ -47,7 +47,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 0); $node = new SearchAndRenderBlockNode('form_widget', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
$this->assertEquals( $this->assertEquals(
sprintf( sprintf(
@ -67,7 +67,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
$this->assertEquals( $this->assertEquals(
sprintf( sprintf(
@ -87,7 +87,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
// "label" => null must not be included in the output! // "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null. // Otherwise the default label is overwritten with null.
@ -109,7 +109,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
// "label" => null must not be included in the output! // "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null. // Otherwise the default label is overwritten with null.
@ -130,7 +130,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
$this->assertEquals( $this->assertEquals(
sprintf( sprintf(
@ -154,7 +154,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
// "label" => null must not be included in the output! // "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null. // Otherwise the default label is overwritten with null.
@ -183,7 +183,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
$this->assertEquals( $this->assertEquals(
sprintf( sprintf(
@ -211,7 +211,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
// "label" => null must not be included in the output! // "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null. // Otherwise the default label is overwritten with null.
@ -248,7 +248,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new \Twig_Compiler(new \Twig_Environment()); $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMock('Twig_LoaderInterface')));
// "label" => null must not be included in the output! // "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null. // Otherwise the default label is overwritten with null.

View File

@ -24,7 +24,7 @@ class TransNodeTest extends \PHPUnit_Framework_TestCase
$vars = new \Twig_Node_Expression_Name('foo', 0); $vars = new \Twig_Node_Expression_Name('foo', 0);
$node = new TransNode($body, null, null, $vars); $node = new TransNode($body, null, null, $vars);
$env = new \Twig_Environment(null, array('strict_variables' => true)); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('strict_variables' => true));
$compiler = new \Twig_Compiler($env); $compiler = new \Twig_Compiler($env);
$this->assertEquals( $this->assertEquals(
@ -47,6 +47,10 @@ class TransNodeTest extends \PHPUnit_Framework_TestCase
protected function getVariableGetterWithStrictCheck($name) protected function getVariableGetterWithStrictCheck($name)
{ {
if (version_compare(\Twig_Environment::VERSION, '2.0.0-DEV', '>=')) {
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : $this->notFound("%s", 0))', $name, $name, $name, $name);
}
if (PHP_VERSION_ID >= 50400) { if (PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name); return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
} }

View File

@ -23,7 +23,7 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase
/** @dataProvider getDefaultDomainAssignmentTestData */ /** @dataProvider getDefaultDomainAssignmentTestData */
public function testDefaultDomainAssignment(\Twig_Node $node) public function testDefaultDomainAssignment(\Twig_Node $node)
{ {
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$visitor = new TranslationDefaultDomainNodeVisitor(); $visitor = new TranslationDefaultDomainNodeVisitor();
// visit trans_default_domain tag // visit trans_default_domain tag
@ -49,7 +49,7 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase
/** @dataProvider getDefaultDomainAssignmentTestData */ /** @dataProvider getDefaultDomainAssignmentTestData */
public function testNewModuleWithoutDefaultDomainTag(\Twig_Node $node) public function testNewModuleWithoutDefaultDomainTag(\Twig_Node $node)
{ {
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$visitor = new TranslationDefaultDomainNodeVisitor(); $visitor = new TranslationDefaultDomainNodeVisitor();
// visit trans_default_domain tag // visit trans_default_domain tag

View File

@ -19,7 +19,7 @@ class TranslationNodeVisitorTest extends TestCase
/** @dataProvider getMessagesExtractionTestData */ /** @dataProvider getMessagesExtractionTestData */
public function testMessagesExtraction(\Twig_Node $node, array $expectedMessages) public function testMessagesExtraction(\Twig_Node $node, array $expectedMessages)
{ {
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$visitor = new TranslationNodeVisitor(); $visitor = new TranslationNodeVisitor();
$visitor->enable(); $visitor->enable();
$visitor->enterNode($node, $env); $visitor->enterNode($node, $env);

View File

@ -22,7 +22,7 @@ class FormThemeTokenParserTest extends TestCase
*/ */
public function testCompile($source, $expected) public function testCompile($source, $expected)
{ {
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$env->addTokenParser(new FormThemeTokenParser()); $env->addTokenParser(new FormThemeTokenParser());
$stream = $env->tokenize($source); $stream = $env->tokenize($source);
$parser = new \Twig_Parser($env); $parser = new \Twig_Parser($env);

View File

@ -23,7 +23,7 @@ class TwigExtractorTest extends TestCase
*/ */
public function testExtract($template, $messages) public function testExtract($template, $messages)
{ {
$loader = new \Twig_Loader_Array(array()); $loader = $this->getMock('Twig_LoaderInterface');
$twig = new \Twig_Environment($loader, array( $twig = new \Twig_Environment($loader, array(
'strict_variables' => true, 'strict_variables' => true,
'debug' => true, 'debug' => true,
@ -78,7 +78,7 @@ class TwigExtractorTest extends TestCase
*/ */
public function testExtractSyntaxError() public function testExtractSyntaxError()
{ {
$twig = new \Twig_Environment(new \Twig_Loader_Array(array())); $twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface'))); $twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
$extractor = new TwigExtractor($twig); $extractor = new TwigExtractor($twig);

View File

@ -25,7 +25,7 @@ class FormThemeTokenParser extends \Twig_TokenParser
* *
* @param \Twig_Token $token A Twig_Token instance * @param \Twig_Token $token A Twig_Token instance
* *
* @return \Twig_NodeInterface A Twig_NodeInterface instance * @return \Twig_Node A Twig_Node instance
*/ */
public function parse(\Twig_Token $token) public function parse(\Twig_Token $token)
{ {

View File

@ -25,7 +25,7 @@ class TransChoiceTokenParser extends TransTokenParser
* *
* @param \Twig_Token $token A Twig_Token instance * @param \Twig_Token $token A Twig_Token instance
* *
* @return \Twig_NodeInterface A Twig_NodeInterface instance * @return \Twig_Node A Twig_Node instance
* *
* @throws \Twig_Error_Syntax * @throws \Twig_Error_Syntax
*/ */

View File

@ -25,7 +25,7 @@ class TransDefaultDomainTokenParser extends \Twig_TokenParser
* *
* @param \Twig_Token $token A Twig_Token instance * @param \Twig_Token $token A Twig_Token instance
* *
* @return \Twig_NodeInterface A Twig_NodeInterface instance * @return \Twig_Node A Twig_Node instance
*/ */
public function parse(\Twig_Token $token) public function parse(\Twig_Token $token)
{ {

View File

@ -25,7 +25,7 @@ class TransTokenParser extends \Twig_TokenParser
* *
* @param \Twig_Token $token A Twig_Token instance * @param \Twig_Token $token A Twig_Token instance
* *
* @return \Twig_NodeInterface A Twig_NodeInterface instance * @return \Twig_Node A Twig_Node instance
* *
* @throws \Twig_Error_Syntax * @throws \Twig_Error_Syntax
*/ */

View File

@ -17,7 +17,7 @@
], ],
"require": { "require": {
"php": ">=5.3.3", "php": ">=5.3.3",
"twig/twig": "~1.12,>=1.12.3" "twig/twig": "~1.20|~2.0"
}, },
"require-dev": { "require-dev": {
"symfony/phpunit-bridge": "~2.7", "symfony/phpunit-bridge": "~2.7",

View File

@ -22,7 +22,7 @@ class ContainerAwareHIncludeFragmentRendererTest extends TestCase
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container->expects($this->once()) $container->expects($this->once())
->method('get') ->method('get')
->will($this->returnValue($this->getMock('\Twig_Environment'))) ->will($this->returnValue($this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock()))
; ;
$renderer = new ContainerAwareHIncludeFragmentRenderer($container); $renderer = new ContainerAwareHIncludeFragmentRenderer($container);
$renderer->render('/', Request::create('/')); $renderer->render('/', Request::create('/'));

View File

@ -36,7 +36,7 @@
"symfony/process": "~2.0,>=2.0.5", "symfony/process": "~2.0,>=2.0.5",
"symfony/validator": "~2.2", "symfony/validator": "~2.2",
"symfony/yaml": "~2.0,>=2.0.5", "symfony/yaml": "~2.0,>=2.0.5",
"twig/twig": "~1.12" "twig/twig": "~1.20|~2.0"
}, },
"autoload": { "autoload": {
"psr-0": { "Symfony\\Bundle\\SecurityBundle\\": "" } "psr-0": { "Symfony\\Bundle\\SecurityBundle\\": "" }

View File

@ -30,7 +30,7 @@ class LegacyRenderTokenParserTest extends TestCase
*/ */
public function testCompile($source, $expected) public function testCompile($source, $expected)
{ {
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$env->addTokenParser(new RenderTokenParser()); $env->addTokenParser(new RenderTokenParser());
$stream = $env->tokenize($source); $stream = $env->tokenize($source);
$parser = new \Twig_Parser($env); $parser = new \Twig_Parser($env);

View File

@ -23,7 +23,7 @@ class ProfilerControllerTest extends \PHPUnit_Framework_TestCase
public function testEmptyToken($token) public function testEmptyToken($token)
{ {
$urlGenerator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface'); $urlGenerator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
$twig = $this->getMock('Twig_Environment'); $twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
$profiler = $this $profiler = $this
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -47,7 +47,7 @@ class ProfilerControllerTest extends \PHPUnit_Framework_TestCase
public function testReturns404onTokenNotFound() public function testReturns404onTokenNotFound()
{ {
$urlGenerator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface'); $urlGenerator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
$twig = $this->getMock('Twig_Environment'); $twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
$profiler = $this $profiler = $this
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
->disableOriginalConstructor() ->disableOriginalConstructor()

View File

@ -55,7 +55,8 @@ class WebProfilerExtensionTest extends TestCase
$this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper')); $this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper'));
$this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper')) $this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))
->addArgument(new Reference('router')); ->addArgument(new Reference('router'));
$this->container->register('twig', 'Twig_Environment'); $this->container->register('twig_loader', 'Twig_Loader_Array')->addArgument(array());
$this->container->register('twig', 'Twig_Environment')->addArgument(new Reference('twig_loader'));
$this->container->setParameter('kernel.bundles', array()); $this->container->setParameter('kernel.bundles', array());
$this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.cache_dir', __DIR__);
$this->container->setParameter('kernel.debug', false); $this->container->setParameter('kernel.debug', false);

View File

@ -138,7 +138,7 @@ class TemplateManagerTest extends TestCase
protected function mockTwigEnvironment() protected function mockTwigEnvironment()
{ {
$this->twigEnvironment = $this->getMockBuilder('Twig_Environment')->getMock(); $this->twigEnvironment = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
$this->twigEnvironment->expects($this->any()) $this->twigEnvironment->expects($this->any())
->method('loadTemplate') ->method('loadTemplate')