fixed Twig deprecations

This commit is contained in:
Fabien Potencier 2015-08-23 09:30:32 +02:00
parent 99a1fcc3e2
commit 7b64354058
11 changed files with 21 additions and 19 deletions

View File

@ -18,7 +18,7 @@ class DumpNode extends \Twig_Node
{ {
private $varPrefix; private $varPrefix;
public function __construct($varPrefix, \Twig_NodeInterface $values = null, $lineno, $tag = null) public function __construct($varPrefix, \Twig_Node $values = null, $lineno, $tag = null)
{ {
parent::__construct(array('values' => $values), array(), $lineno, $tag); parent::__construct(array('values' => $values), array(), $lineno, $tag);
$this->varPrefix = $varPrefix; $this->varPrefix = $varPrefix;

View File

@ -18,7 +18,7 @@ namespace Symfony\Bridge\Twig\Node;
*/ */
class StopwatchNode extends \Twig_Node class StopwatchNode extends \Twig_Node
{ {
public function __construct(\Twig_NodeInterface $name, $body, \Twig_Node_Expression_AssignName $var, $lineno = 0, $tag = null) public function __construct(\Twig_Node $name, $body, \Twig_Node_Expression_AssignName $var, $lineno = 0, $tag = null)
{ {
parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag); parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag);
} }

View File

@ -23,7 +23,7 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase
public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped) public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped)
{ {
$extension = new DumpExtension(new VarCloner()); $extension = new DumpExtension(new VarCloner());
$twig = new \Twig_Environment(new \Twig_Loader_String(), array( $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array(
'debug' => $debug, 'debug' => $debug,
'cache' => false, 'cache' => false,
'optimizations' => 0, 'optimizations' => 0,
@ -35,7 +35,7 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase
$prevDumper = VarDumper::setHandler(function ($var) use (&$dumped) {$dumped = $var;}); $prevDumper = VarDumper::setHandler(function ($var) use (&$dumped) {$dumped = $var;});
try { try {
$this->assertEquals($expectedOutput, $twig->render($template)); $this->assertEquals($expectedOutput, $twig->render('template'));
} catch (\Exception $exception) { } catch (\Exception $exception) {
} }
@ -63,7 +63,7 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase
public function testDump($context, $args, $expectedOutput, $debug = true) public function testDump($context, $args, $expectedOutput, $debug = true)
{ {
$extension = new DumpExtension(new VarCloner()); $extension = new DumpExtension(new VarCloner());
$twig = new \Twig_Environment(new \Twig_Loader_String(), array( $twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array(
'debug' => $debug, 'debug' => $debug,
'cache' => false, 'cache' => false,
'optimizations' => 0, 'optimizations' => 0,

View File

@ -21,10 +21,10 @@ class ExpressionExtensionTest extends \PHPUnit_Framework_TestCase
public function testExpressionCreation() public function testExpressionCreation()
{ {
$template = "{{ expression('1 == 1') }}"; $template = "{{ expression('1 == 1') }}";
$twig = new \Twig_Environment(new \Twig_Loader_String(), array('debug' => true, 'cache' => false, 'autoescape' => true, 'optimizations' => 0)); $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
$twig->addExtension(new ExpressionExtension()); $twig->addExtension(new ExpressionExtension());
$output = $twig->render($template); $output = $twig->render('template');
$this->assertEquals('1 == 1', $output); $this->assertEquals('1 == 1', $output);
} }
} }

View File

@ -13,7 +13,7 @@ namespace Symfony\Bridge\Twig\Tests\Extension\Fixtures;
class StubFilesystemLoader extends \Twig_Loader_Filesystem class StubFilesystemLoader extends \Twig_Loader_Filesystem
{ {
protected function findTemplate($name) protected function findTemplate($name, $throw = true)
{ {
// strip away bundle name // strip away bundle name
$parts = explode(':', $name); $parts = explode(':', $name);

View File

@ -28,11 +28,11 @@ class StopwatchExtensionTest extends \PHPUnit_Framework_TestCase
*/ */
public function testTiming($template, $events) public function testTiming($template, $events)
{ {
$twig = new \Twig_Environment(new \Twig_Loader_String(), array('debug' => true, 'cache' => false, 'autoescape' => true, 'optimizations' => 0)); $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
$twig->addExtension(new StopwatchExtension($this->getStopwatch($events))); $twig->addExtension(new StopwatchExtension($this->getStopwatch($events)));
try { try {
$nodes = $twig->render($template); $nodes = $twig->render('template');
} catch (\Twig_Error_Runtime $e) { } catch (\Twig_Error_Runtime $e) {
throw $e->getPrevious(); throw $e->getPrevious();
} }

View File

@ -19,7 +19,7 @@ class DumpNodeTest extends \PHPUnit_Framework_TestCase
{ {
$node = new DumpNode('bar', null, 7); $node = new DumpNode('bar', null, 7);
$env = new \Twig_Environment(); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
$compiler = new \Twig_Compiler($env); $compiler = new \Twig_Compiler($env);
$expected = <<<'EOTXT' $expected = <<<'EOTXT'
@ -43,7 +43,7 @@ EOTXT;
{ {
$node = new DumpNode('bar', null, 7); $node = new DumpNode('bar', null, 7);
$env = new \Twig_Environment(); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
$compiler = new \Twig_Compiler($env); $compiler = new \Twig_Compiler($env);
$expected = <<<'EOTXT' $expected = <<<'EOTXT'
@ -70,7 +70,7 @@ EOTXT;
)); ));
$node = new DumpNode('bar', $vars, 7); $node = new DumpNode('bar', $vars, 7);
$env = new \Twig_Environment(); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
$compiler = new \Twig_Compiler($env); $compiler = new \Twig_Compiler($env);
$expected = <<<'EOTXT' $expected = <<<'EOTXT'
@ -93,7 +93,7 @@ EOTXT;
)); ));
$node = new DumpNode('bar', $vars, 7); $node = new DumpNode('bar', $vars, 7);
$env = new \Twig_Environment(); $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
$compiler = new \Twig_Compiler($env); $compiler = new \Twig_Compiler($env);
$expected = <<<'EOTXT' $expected = <<<'EOTXT'

View File

@ -63,7 +63,7 @@ class ExceptionController
$code = $exception->getStatusCode(); $code = $exception->getStatusCode();
return new Response($this->twig->render( return new Response($this->twig->render(
$this->findTemplate($request, $request->getRequestFormat(), $code, $showException), (string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException),
array( array(
'status_code' => $code, 'status_code' => $code,
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
@ -125,9 +125,11 @@ class ExceptionController
return new TemplateReference('TwigBundle', 'Exception', $showException ? 'exception_full' : $name, 'html', 'twig'); return new TemplateReference('TwigBundle', 'Exception', $showException ? 'exception_full' : $name, 'html', 'twig');
} }
// to be removed when the minimum required version of Twig is >= 2.0 // to be removed when the minimum required version of Twig is >= 3.0
protected function templateExists($template) protected function templateExists($template)
{ {
$template = (string) $template;
$loader = $this->twig->getLoader(); $loader = $this->twig->getLoader();
if ($loader instanceof \Twig_ExistsLoaderInterface) { if ($loader instanceof \Twig_ExistsLoaderInterface) {
return $loader->exists($template); return $loader->exists($template);

View File

@ -63,7 +63,7 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
* *
* @throws \Twig_Error_Loader if the template could not be found * @throws \Twig_Error_Loader if the template could not be found
*/ */
protected function findTemplate($template) protected function findTemplate($template, $throw = true)
{ {
$logicalName = (string) $template; $logicalName = (string) $template;

View File

@ -27,7 +27,7 @@ class RenderTokenParser 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

@ -77,7 +77,7 @@ class ProfilerControllerTest extends \PHPUnit_Framework_TestCase
public function testSearchResult() public function testSearchResult()
{ {
$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()