Merge branch '2.3' into 2.7

* 2.3:
  made Symfony compatible with both Twig 1.x and 2.x
This commit is contained in:
Fabien Potencier 2015-08-22 09:41:51 +02:00
commit e25aca7072
25 changed files with 47 additions and 41 deletions

View File

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

View File

@ -16,7 +16,7 @@ namespace Symfony\Bridge\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);
}

View File

@ -16,7 +16,7 @@ namespace Symfony\Bridge\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);
}
@ -83,7 +83,7 @@ class TransNode extends \Twig_Node
$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) {
$msg = $body->getAttribute('value');

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ class RoutingExtensionTest extends \PHPUnit_Framework_TestCase
*/
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')));
$nodes = $twig->parse($twig->tokenize($template));

View File

@ -41,7 +41,7 @@ class FormThemeTest extends \PHPUnit_Framework_TestCase
$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(
sprintf(

View File

@ -23,7 +23,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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(
sprintf(
@ -46,7 +46,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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(
sprintf(
@ -66,7 +66,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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(
sprintf(
@ -86,7 +86,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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!
// Otherwise the default label is overwritten with null.
@ -108,7 +108,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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!
// Otherwise the default label is overwritten with null.
@ -129,7 +129,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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(
sprintf(
@ -153,7 +153,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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!
// Otherwise the default label is overwritten with null.
@ -182,7 +182,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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(
sprintf(
@ -210,7 +210,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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!
// Otherwise the default label is overwritten with null.
@ -247,7 +247,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
$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!
// 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);
$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);
$this->assertEquals(
@ -47,6 +47,10 @@ class TransNodeTest extends \PHPUnit_Framework_TestCase
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) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
}

View File

@ -22,7 +22,7 @@ class TranslationDefaultDomainNodeVisitorTest extends \PHPUnit_Framework_TestCas
/** @dataProvider getDefaultDomainAssignmentTestData */
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();
// visit trans_default_domain tag
@ -48,7 +48,7 @@ class TranslationDefaultDomainNodeVisitorTest extends \PHPUnit_Framework_TestCas
/** @dataProvider getDefaultDomainAssignmentTestData */
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();
// visit trans_default_domain tag

View File

@ -18,7 +18,7 @@ class TranslationNodeVisitorTest extends \PHPUnit_Framework_TestCase
/** @dataProvider getMessagesExtractionTestData */
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->enable();
$visitor->enterNode($node, $env);

View File

@ -21,7 +21,7 @@ class FormThemeTokenParserTest extends \PHPUnit_Framework_TestCase
*/
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());
$stream = $env->tokenize($source);
$parser = new \Twig_Parser($env);

View File

@ -22,7 +22,7 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase
*/
public function testExtract($template, $messages)
{
$loader = new \Twig_Loader_Array(array());
$loader = $this->getMock('Twig_LoaderInterface');
$twig = new \Twig_Environment($loader, array(
'strict_variables' => true,
'debug' => true,
@ -78,7 +78,7 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase
*/
public function testExtractSyntaxError($resources)
{
$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')));
$extractor = new TwigExtractor($twig);

View File

@ -25,7 +25,7 @@ class FormThemeTokenParser extends \Twig_TokenParser
*
* @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)
{

View File

@ -25,7 +25,7 @@ class TransChoiceTokenParser extends TransTokenParser
*
* @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
*/

View File

@ -25,7 +25,7 @@ class TransDefaultDomainTokenParser extends \Twig_TokenParser
*
* @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)
{

View File

@ -25,7 +25,7 @@ class TransTokenParser extends \Twig_TokenParser
*
* @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
*/

View File

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

View File

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

View File

@ -38,7 +38,7 @@
"symfony/yaml": "~2.0,>=2.0.5",
"symfony/expression-language": "~2.6",
"doctrine/doctrine-bundle": "~1.2",
"twig/twig": "~1.12",
"twig/twig": "~1.20|~2.0",
"ircmaxell/password-compat": "~1.0"
},
"autoload": {

View File

@ -25,7 +25,7 @@ class LegacyRenderTokenParserTest extends TestCase
*/
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());
$stream = $env->tokenize($source);
$parser = new \Twig_Parser($env);

View File

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

View File

@ -53,6 +53,8 @@ class WebProfilerExtensionTest extends TestCase
$this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
$this->container->register('router', $this->getMockClass('Symfony\\Component\\Routing\\RouterInterface'));
$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.cache_dir', __DIR__);
$this->container->setParameter('kernel.debug', false);

View File

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