*/
-class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
+class Twig_NodeVisitor_Sandbox extends \Twig\NodeVisitor\AbstractNodeVisitor
{
protected $inAModule = false;
protected $tags;
protected $filters;
protected $functions;
- protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
+ protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env)
{
- if ($node instanceof Twig_Node_Module) {
+ if ($node instanceof \Twig\Node\ModuleNode) {
$this->inAModule = true;
$this->tags = [];
$this->filters = [];
@@ -39,35 +39,35 @@ protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
}
// look for filters
- if ($node instanceof Twig_Node_Expression_Filter && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) {
+ if ($node instanceof \Twig\Node\Expression\FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) {
$this->filters[$node->getNode('filter')->getAttribute('value')] = $node;
}
// look for functions
- if ($node instanceof Twig_Node_Expression_Function && !isset($this->functions[$node->getAttribute('name')])) {
+ if ($node instanceof \Twig\Node\Expression\FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) {
$this->functions[$node->getAttribute('name')] = $node;
}
// the .. operator is equivalent to the range() function
- if ($node instanceof Twig_Node_Expression_Binary_Range && !isset($this->functions['range'])) {
+ if ($node instanceof \Twig\Node\Expression\Binary\RangeBinary && !isset($this->functions['range'])) {
$this->functions['range'] = $node;
}
// wrap print to check __toString() calls
- if ($node instanceof Twig_Node_Print) {
- return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag());
+ if ($node instanceof \Twig\Node\PrintNode) {
+ return new \Twig\Node\SandboxedPrintNode($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag());
}
}
return $node;
}
- protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
+ protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env)
{
- if ($node instanceof Twig_Node_Module) {
+ if ($node instanceof \Twig\Node\ModuleNode) {
$this->inAModule = false;
- $node->setNode('display_start', new Twig_Node([new Twig_Node_CheckSecurity($this->filters, $this->tags, $this->functions), $node->getNode('display_start')]));
+ $node->setNode('display_start', new \Twig\Node\Node([new \Twig\Node\CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')]));
}
return $node;
diff --git a/lib/Twig/NodeVisitorInterface.php b/lib/Twig/NodeVisitorInterface.php
index 1270a37243..00f8afaf65 100644
--- a/lib/Twig/NodeVisitorInterface.php
+++ b/lib/Twig/NodeVisitorInterface.php
@@ -21,14 +21,14 @@ interface Twig_NodeVisitorInterface
*
* @return Twig_NodeInterface The modified node
*/
- public function enterNode(Twig_NodeInterface $node, Twig_Environment $env);
+ public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env);
/**
* Called after child nodes are visited.
*
* @return Twig_NodeInterface|false The modified node or false if the node must be removed
*/
- public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env);
+ public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env);
/**
* Returns the priority for this visitor.
diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php
index 4aabcab04e..1eaf49fcea 100644
--- a/lib/Twig/Parser.php
+++ b/lib/Twig/Parser.php
@@ -33,7 +33,7 @@ class Twig_Parser implements Twig_ParserInterface
protected $embeddedTemplates = [];
private $varNameSalt = 0;
- public function __construct(Twig_Environment $env)
+ public function __construct(\Twig\Environment $env)
{
$this->env = $env;
}
@@ -63,7 +63,7 @@ public function getFilename()
return $this->stream->getSourceContext()->getName();
}
- public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false)
+ public function parse(\Twig\TokenStream $stream, $test = null, $dropNeedle = false)
{
// push all variables into the stack to keep the current state of the parser
// using get_object_vars() instead of foreach would lead to https://bugs.php.net/71336
@@ -88,7 +88,7 @@ public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = fals
}
if (null === $this->expressionParser) {
- $this->expressionParser = new Twig_ExpressionParser($this, $this->env);
+ $this->expressionParser = new \Twig\ExpressionParser($this, $this->env);
}
$this->stream = $stream;
@@ -105,9 +105,9 @@ public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = fals
$body = $this->subparse($test, $dropNeedle);
if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) {
- $body = new Twig_Node();
+ $body = new \Twig\Node\Node();
}
- } catch (Twig_Error_Syntax $e) {
+ } catch (\Twig\Error\SyntaxError $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($this->stream->getSourceContext());
}
@@ -119,9 +119,9 @@ public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = fals
throw $e;
}
- $node = new Twig_Node_Module(new Twig_Node_Body([$body]), $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), new Twig_Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext());
+ $node = new \Twig\Node\ModuleNode(new \Twig\Node\BodyNode([$body]), $this->parent, new \Twig\Node\Node($this->blocks), new \Twig\Node\Node($this->macros), new \Twig\Node\Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext());
- $traverser = new Twig_NodeTraverser($this->env, $this->visitors);
+ $traverser = new \Twig\NodeTraverser($this->env, $this->visitors);
$node = $traverser->traverse($node);
@@ -139,24 +139,24 @@ public function subparse($test, $dropNeedle = false)
$rv = [];
while (!$this->stream->isEOF()) {
switch ($this->getCurrentToken()->getType()) {
- case Twig_Token::TEXT_TYPE:
+ case \Twig\Token::TEXT_TYPE:
$token = $this->stream->next();
- $rv[] = new Twig_Node_Text($token->getValue(), $token->getLine());
+ $rv[] = new \Twig\Node\TextNode($token->getValue(), $token->getLine());
break;
- case Twig_Token::VAR_START_TYPE:
+ case \Twig\Token::VAR_START_TYPE:
$token = $this->stream->next();
$expr = $this->expressionParser->parseExpression();
- $this->stream->expect(Twig_Token::VAR_END_TYPE);
- $rv[] = new Twig_Node_Print($expr, $token->getLine());
+ $this->stream->expect(\Twig\Token::VAR_END_TYPE);
+ $rv[] = new \Twig\Node\PrintNode($expr, $token->getLine());
break;
- case Twig_Token::BLOCK_START_TYPE:
+ case \Twig\Token::BLOCK_START_TYPE:
$this->stream->next();
$token = $this->getCurrentToken();
- if (Twig_Token::NAME_TYPE !== $token->getType()) {
- throw new Twig_Error_Syntax('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext());
+ if (\Twig\Token::NAME_TYPE !== $token->getType()) {
+ throw new \Twig\Error\SyntaxError('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext());
}
if (null !== $test && \call_user_func($test, $token)) {
@@ -168,19 +168,19 @@ public function subparse($test, $dropNeedle = false)
return $rv[0];
}
- return new Twig_Node($rv, [], $lineno);
+ return new \Twig\Node\Node($rv, [], $lineno);
}
$subparser = $this->handlers->getTokenParser($token->getValue());
if (null === $subparser) {
if (null !== $test) {
- $e = new Twig_Error_Syntax(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext());
+ $e = new \Twig\Error\SyntaxError(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext());
- if (\is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) {
+ if (\is_array($test) && isset($test[0]) && $test[0] instanceof \Twig\TokenParser\TokenParserInterface) {
$e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno));
}
} else {
- $e = new Twig_Error_Syntax(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext());
+ $e = new \Twig\Error\SyntaxError(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext());
$e->addSuggestions($token->getValue(), array_keys($this->env->getTags()));
}
@@ -196,7 +196,7 @@ public function subparse($test, $dropNeedle = false)
break;
default:
- throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext());
}
}
@@ -204,7 +204,7 @@ public function subparse($test, $dropNeedle = false)
return $rv[0];
}
- return new Twig_Node($rv, [], $lineno);
+ return new \Twig\Node\Node($rv, [], $lineno);
}
/**
@@ -220,7 +220,7 @@ public function addHandler($name, $class)
/**
* @deprecated since 1.27 (to be removed in 2.0)
*/
- public function addNodeVisitor(Twig_NodeVisitorInterface $visitor)
+ public function addNodeVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED);
@@ -257,9 +257,9 @@ public function getBlock($name)
return $this->blocks[$name];
}
- public function setBlock($name, Twig_Node_Block $value)
+ public function setBlock($name, \Twig\Node\BlockNode $value)
{
- $this->blocks[$name] = new Twig_Node_Body([$value], [], $value->getTemplateLine());
+ $this->blocks[$name] = new \Twig\Node\BodyNode([$value], [], $value->getTemplateLine());
}
public function hasMacro($name)
@@ -267,10 +267,10 @@ public function hasMacro($name)
return isset($this->macros[$name]);
}
- public function setMacro($name, Twig_Node_Macro $node)
+ public function setMacro($name, \Twig\Node\MacroNode $node)
{
if ($this->isReservedMacroName($name)) {
- throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext());
}
$this->macros[$name] = $node;
@@ -303,14 +303,14 @@ public function hasTraits()
return \count($this->traits) > 0;
}
- public function embedTemplate(Twig_Node_Module $template)
+ public function embedTemplate(\Twig\Node\ModuleNode $template)
{
$template->setIndex(mt_rand());
$this->embeddedTemplates[] = $template;
}
- public function addImportedSymbol($type, $alias, $name = null, Twig_Node_Expression $node = null)
+ public function addImportedSymbol($type, $alias, $name = null, \Twig\Node\Expression\AbstractExpression $node = null)
{
$this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node];
}
@@ -340,7 +340,7 @@ public function popLocalScope()
}
/**
- * @return Twig_ExpressionParser
+ * @return \Twig\ExpressionParser
*/
public function getExpressionParser()
{
@@ -358,7 +358,7 @@ public function setParent($parent)
}
/**
- * @return Twig_TokenStream
+ * @return \Twig\TokenStream
*/
public function getStream()
{
@@ -366,7 +366,7 @@ public function getStream()
}
/**
- * @return Twig_Token
+ * @return \Twig\Token
*/
public function getCurrentToken()
{
@@ -377,9 +377,9 @@ protected function filterBodyNodes(Twig_NodeInterface $node)
{
// check that the body does not contain non-empty output nodes
if (
- ($node instanceof Twig_Node_Text && !ctype_space($node->getAttribute('data')))
+ ($node instanceof \Twig\Node\TextNode && !ctype_space($node->getAttribute('data')))
||
- (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface)
+ (!$node instanceof \Twig\Node\TextNode && !$node instanceof \Twig\Node\BlockReferenceNode && $node instanceof \Twig\Node\NodeOutputInterface)
) {
if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) {
$t = substr($node->getAttribute('data'), 3);
@@ -389,15 +389,15 @@ protected function filterBodyNodes(Twig_NodeInterface $node)
}
}
- throw new Twig_Error_Syntax('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext());
}
// bypass nodes that will "capture" the output
- if ($node instanceof Twig_NodeCaptureInterface) {
+ if ($node instanceof \Twig\Node\NodeCaptureInterface) {
return $node;
}
- if ($node instanceof Twig_NodeOutputInterface) {
+ if ($node instanceof \Twig\Node\NodeOutputInterface) {
return;
}
diff --git a/lib/Twig/ParserInterface.php b/lib/Twig/ParserInterface.php
index 85c6e67b20..d628d65215 100644
--- a/lib/Twig/ParserInterface.php
+++ b/lib/Twig/ParserInterface.php
@@ -21,9 +21,9 @@ interface Twig_ParserInterface
/**
* Converts a token stream to a node tree.
*
- * @return Twig_Node_Module
+ * @return \Twig\Node\ModuleNode
*
- * @throws Twig_Error_Syntax When the token stream is syntactically or semantically wrong
+ * @throws \Twig\Error\SyntaxError When the token stream is syntactically or semantically wrong
*/
- public function parse(Twig_TokenStream $stream);
+ public function parse(\Twig\TokenStream $stream);
}
diff --git a/lib/Twig/Profiler/Dumper/Base.php b/lib/Twig/Profiler/Dumper/Base.php
index 8aeeeb7730..9ce1243230 100644
--- a/lib/Twig/Profiler/Dumper/Base.php
+++ b/lib/Twig/Profiler/Dumper/Base.php
@@ -16,18 +16,18 @@ abstract class Twig_Profiler_Dumper_Base
{
private $root;
- public function dump(Twig_Profiler_Profile $profile)
+ public function dump(\Twig\Profiler\Profile $profile)
{
return $this->dumpProfile($profile);
}
- abstract protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix);
+ abstract protected function formatTemplate(\Twig\Profiler\Profile $profile, $prefix);
- abstract protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix);
+ abstract protected function formatNonTemplate(\Twig\Profiler\Profile $profile, $prefix);
- abstract protected function formatTime(Twig_Profiler_Profile $profile, $percent);
+ abstract protected function formatTime(\Twig\Profiler\Profile $profile, $percent);
- private function dumpProfile(Twig_Profiler_Profile $profile, $prefix = '', $sibling = false)
+ private function dumpProfile(\Twig\Profiler\Profile $profile, $prefix = '', $sibling = false)
{
if ($profile->isRoot()) {
$this->root = $profile->getDuration();
diff --git a/lib/Twig/Profiler/Dumper/Blackfire.php b/lib/Twig/Profiler/Dumper/Blackfire.php
index 4ebb0d0ff2..827a20b6dc 100644
--- a/lib/Twig/Profiler/Dumper/Blackfire.php
+++ b/lib/Twig/Profiler/Dumper/Blackfire.php
@@ -16,7 +16,7 @@
*/
class Twig_Profiler_Dumper_Blackfire
{
- public function dump(Twig_Profiler_Profile $profile)
+ public function dump(\Twig\Profiler\Profile $profile)
{
$data = [];
$this->dumpProfile('main()', $profile, $data);
@@ -38,7 +38,7 @@ public function dump(Twig_Profiler_Profile $profile)
return $str;
}
- private function dumpChildren($parent, Twig_Profiler_Profile $profile, &$data)
+ private function dumpChildren($parent, \Twig\Profiler\Profile $profile, &$data)
{
foreach ($profile as $p) {
if ($p->isTemplate()) {
@@ -51,7 +51,7 @@ private function dumpChildren($parent, Twig_Profiler_Profile $profile, &$data)
}
}
- private function dumpProfile($edge, Twig_Profiler_Profile $profile, &$data)
+ private function dumpProfile($edge, \Twig\Profiler\Profile $profile, &$data)
{
if (isset($data[$edge])) {
++$data[$edge]['ct'];
diff --git a/lib/Twig/Profiler/Dumper/Html.php b/lib/Twig/Profiler/Dumper/Html.php
index 974b521687..b9ddd586b7 100644
--- a/lib/Twig/Profiler/Dumper/Html.php
+++ b/lib/Twig/Profiler/Dumper/Html.php
@@ -14,7 +14,7 @@
*
* @final
*/
-class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Base
+class Twig_Profiler_Dumper_Html extends \Twig\Profiler\Dumper\BaseDumper
{
private static $colors = [
'block' => '#dfd',
@@ -23,22 +23,22 @@ class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Base
'big' => '#d44',
];
- public function dump(Twig_Profiler_Profile $profile)
+ public function dump(\Twig\Profiler\Profile $profile)
{
return ''.parent::dump($profile).'
';
}
- protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix)
+ protected function formatTemplate(\Twig\Profiler\Profile $profile, $prefix)
{
return sprintf('%s└ %s', $prefix, self::$colors['template'], $profile->getTemplate());
}
- protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix)
+ protected function formatNonTemplate(\Twig\Profiler\Profile $profile, $prefix)
{
return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName());
}
- protected function formatTime(Twig_Profiler_Profile $profile, $percent)
+ protected function formatTime(\Twig\Profiler\Profile $profile, $percent)
{
return sprintf('%.2fms/%.0f%%', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent);
}
diff --git a/lib/Twig/Profiler/Dumper/Text.php b/lib/Twig/Profiler/Dumper/Text.php
index 69d2c4bf34..abc961b784 100644
--- a/lib/Twig/Profiler/Dumper/Text.php
+++ b/lib/Twig/Profiler/Dumper/Text.php
@@ -14,19 +14,19 @@
*
* @final
*/
-class Twig_Profiler_Dumper_Text extends Twig_Profiler_Dumper_Base
+class Twig_Profiler_Dumper_Text extends \Twig\Profiler\Dumper\BaseDumper
{
- protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix)
+ protected function formatTemplate(\Twig\Profiler\Profile $profile, $prefix)
{
return sprintf('%s└ %s', $prefix, $profile->getTemplate());
}
- protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix)
+ protected function formatNonTemplate(\Twig\Profiler\Profile $profile, $prefix)
{
return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName());
}
- protected function formatTime(Twig_Profiler_Profile $profile, $percent)
+ protected function formatTime(\Twig\Profiler\Profile $profile, $percent)
{
return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent);
}
diff --git a/lib/Twig/Profiler/Node/EnterProfile.php b/lib/Twig/Profiler/Node/EnterProfile.php
index b29ec9b7fa..3144c03c7f 100644
--- a/lib/Twig/Profiler/Node/EnterProfile.php
+++ b/lib/Twig/Profiler/Node/EnterProfile.php
@@ -14,20 +14,20 @@
*
* @author Fabien Potencier
*/
-class Twig_Profiler_Node_EnterProfile extends Twig_Node
+class Twig_Profiler_Node_EnterProfile extends \Twig\Node\Node
{
public function __construct($extensionName, $type, $name, $varName)
{
parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]);
}
- public function compile(Twig_Compiler $compiler)
+ public function compile(\Twig\Compiler $compiler)
{
$compiler
->write(sprintf('$%s = $this->env->getExtension(', $this->getAttribute('var_name')))
->repr($this->getAttribute('extension_name'))
->raw(");\n")
- ->write(sprintf('$%s->enter($%s = new Twig_Profiler_Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof'))
+ ->write(sprintf('$%s->enter($%s = new \Twig\Profiler\Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof'))
->repr($this->getAttribute('type'))
->raw(', ')
->repr($this->getAttribute('name'))
diff --git a/lib/Twig/Profiler/Node/LeaveProfile.php b/lib/Twig/Profiler/Node/LeaveProfile.php
index bcb912dd8b..cfc0d25975 100644
--- a/lib/Twig/Profiler/Node/LeaveProfile.php
+++ b/lib/Twig/Profiler/Node/LeaveProfile.php
@@ -14,14 +14,14 @@
*
* @author Fabien Potencier
*/
-class Twig_Profiler_Node_LeaveProfile extends Twig_Node
+class Twig_Profiler_Node_LeaveProfile extends \Twig\Node\Node
{
public function __construct($varName)
{
parent::__construct([], ['var_name' => $varName]);
}
- public function compile(Twig_Compiler $compiler)
+ public function compile(\Twig\Compiler $compiler)
{
$compiler
->write("\n")
diff --git a/lib/Twig/Profiler/NodeVisitor/Profiler.php b/lib/Twig/Profiler/NodeVisitor/Profiler.php
index 6cf5bb0e5a..40d46532d4 100644
--- a/lib/Twig/Profiler/NodeVisitor/Profiler.php
+++ b/lib/Twig/Profiler/NodeVisitor/Profiler.php
@@ -14,7 +14,7 @@
*
* @final
*/
-class Twig_Profiler_NodeVisitor_Profiler extends Twig_BaseNodeVisitor
+class Twig_Profiler_NodeVisitor_Profiler extends \Twig\NodeVisitor\AbstractNodeVisitor
{
private $extensionName;
@@ -23,30 +23,30 @@ public function __construct($extensionName)
$this->extensionName = $extensionName;
}
- protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
+ protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env)
{
return $node;
}
- protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
+ protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env)
{
- if ($node instanceof Twig_Node_Module) {
+ if ($node instanceof \Twig\Node\ModuleNode) {
$varName = $this->getVarName();
- $node->setNode('display_start', new Twig_Node([new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')]));
- $node->setNode('display_end', new Twig_Node([new Twig_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end')]));
- } elseif ($node instanceof Twig_Node_Block) {
+ $node->setNode('display_start', new \Twig\Node\Node([new \Twig\Profiler\Node\EnterProfileNode($this->extensionName, \Twig\Profiler\Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')]));
+ $node->setNode('display_end', new \Twig\Node\Node([new \Twig\Profiler\Node\LeaveProfileNode($varName), $node->getNode('display_end')]));
+ } elseif ($node instanceof \Twig\Node\BlockNode) {
$varName = $this->getVarName();
- $node->setNode('body', new Twig_Node_Body([
- new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName),
+ $node->setNode('body', new \Twig\Node\BodyNode([
+ new \Twig\Profiler\Node\EnterProfileNode($this->extensionName, \Twig\Profiler\Profile::BLOCK, $node->getAttribute('name'), $varName),
$node->getNode('body'),
- new Twig_Profiler_Node_LeaveProfile($varName),
+ new \Twig\Profiler\Node\LeaveProfileNode($varName),
]));
- } elseif ($node instanceof Twig_Node_Macro) {
+ } elseif ($node instanceof \Twig\Node\MacroNode) {
$varName = $this->getVarName();
- $node->setNode('body', new Twig_Node_Body([
- new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::MACRO, $node->getAttribute('name'), $varName),
+ $node->setNode('body', new \Twig\Node\BodyNode([
+ new \Twig\Profiler\Node\EnterProfileNode($this->extensionName, \Twig\Profiler\Profile::MACRO, $node->getAttribute('name'), $varName),
$node->getNode('body'),
- new Twig_Profiler_Node_LeaveProfile($varName),
+ new \Twig\Profiler\Node\LeaveProfileNode($varName),
]));
}
diff --git a/lib/Twig/Sandbox/SecurityError.php b/lib/Twig/Sandbox/SecurityError.php
index b6707e3861..bb18c8f03a 100644
--- a/lib/Twig/Sandbox/SecurityError.php
+++ b/lib/Twig/Sandbox/SecurityError.php
@@ -14,7 +14,7 @@
*
* @author Fabien Potencier
*/
-class Twig_Sandbox_SecurityError extends Twig_Error
+class Twig_Sandbox_SecurityError extends \Twig\Error\Error
{
}
diff --git a/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php b/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php
index 6ee3c66eea..4d254d36aa 100644
--- a/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php
+++ b/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php
@@ -14,7 +14,7 @@
*
* @author Martin Hasoň
*/
-class Twig_Sandbox_SecurityNotAllowedFilterError extends Twig_Sandbox_SecurityError
+class Twig_Sandbox_SecurityNotAllowedFilterError extends \Twig\Sandbox\SecurityError
{
private $filterName;
diff --git a/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php b/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php
index 63159d15a7..8624cca53d 100644
--- a/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php
+++ b/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php
@@ -14,7 +14,7 @@
*
* @author Martin Hasoň
*/
-class Twig_Sandbox_SecurityNotAllowedFunctionError extends Twig_Sandbox_SecurityError
+class Twig_Sandbox_SecurityNotAllowedFunctionError extends \Twig\Sandbox\SecurityError
{
private $functionName;
diff --git a/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php b/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php
index 277522213a..3d49be38ae 100644
--- a/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php
+++ b/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php
@@ -14,7 +14,7 @@
*
* @author Kit Burton-Senior
*/
-class Twig_Sandbox_SecurityNotAllowedMethodError extends Twig_Sandbox_SecurityError
+class Twig_Sandbox_SecurityNotAllowedMethodError extends \Twig\Sandbox\SecurityError
{
private $className;
private $methodName;
diff --git a/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php b/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php
index c9477e8e20..ae304833b6 100644
--- a/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php
+++ b/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php
@@ -14,7 +14,7 @@
*
* @author Kit Burton-Senior
*/
-class Twig_Sandbox_SecurityNotAllowedPropertyError extends Twig_Sandbox_SecurityError
+class Twig_Sandbox_SecurityNotAllowedPropertyError extends \Twig\Sandbox\SecurityError
{
private $className;
private $propertyName;
diff --git a/lib/Twig/Sandbox/SecurityNotAllowedTagError.php b/lib/Twig/Sandbox/SecurityNotAllowedTagError.php
index 2fd1406285..c5bc54da3c 100644
--- a/lib/Twig/Sandbox/SecurityNotAllowedTagError.php
+++ b/lib/Twig/Sandbox/SecurityNotAllowedTagError.php
@@ -14,7 +14,7 @@
*
* @author Martin Hasoň
*/
-class Twig_Sandbox_SecurityNotAllowedTagError extends Twig_Sandbox_SecurityError
+class Twig_Sandbox_SecurityNotAllowedTagError extends \Twig\Sandbox\SecurityError
{
private $tagName;
diff --git a/lib/Twig/Sandbox/SecurityPolicy.php b/lib/Twig/Sandbox/SecurityPolicy.php
index cd24635da7..8b9465bb59 100644
--- a/lib/Twig/Sandbox/SecurityPolicy.php
+++ b/lib/Twig/Sandbox/SecurityPolicy.php
@@ -16,7 +16,7 @@
*
* @author Fabien Potencier
*/
-class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterface
+class Twig_Sandbox_SecurityPolicy implements \Twig\Sandbox\SecurityPolicyInterface
{
protected $allowedTags;
protected $allowedFilters;
@@ -65,26 +65,26 @@ public function checkSecurity($tags, $filters, $functions)
{
foreach ($tags as $tag) {
if (!\in_array($tag, $this->allowedTags)) {
- throw new Twig_Sandbox_SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag);
+ throw new \Twig\Sandbox\SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag);
}
}
foreach ($filters as $filter) {
if (!\in_array($filter, $this->allowedFilters)) {
- throw new Twig_Sandbox_SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter);
+ throw new \Twig\Sandbox\SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter);
}
}
foreach ($functions as $function) {
if (!\in_array($function, $this->allowedFunctions)) {
- throw new Twig_Sandbox_SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function);
+ throw new \Twig\Sandbox\SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function);
}
}
}
public function checkMethodAllowed($obj, $method)
{
- if ($obj instanceof Twig_TemplateInterface || $obj instanceof Twig_Markup) {
+ if ($obj instanceof Twig_TemplateInterface || $obj instanceof \Twig\Markup) {
return true;
}
@@ -100,7 +100,7 @@ public function checkMethodAllowed($obj, $method)
if (!$allowed) {
$class = \get_class($obj);
- throw new Twig_Sandbox_SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method);
+ throw new \Twig\Sandbox\SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method);
}
}
@@ -117,7 +117,7 @@ public function checkPropertyAllowed($obj, $property)
if (!$allowed) {
$class = \get_class($obj);
- throw new Twig_Sandbox_SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property);
+ throw new \Twig\Sandbox\SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property);
}
}
}
diff --git a/lib/Twig/SimpleFilter.php b/lib/Twig/SimpleFilter.php
index a7787d77f3..f94f9469e6 100644
--- a/lib/Twig/SimpleFilter.php
+++ b/lib/Twig/SimpleFilter.php
@@ -35,7 +35,7 @@ public function __construct($name, $callable, array $options = [])
'is_safe_callback' => null,
'pre_escape' => null,
'preserves_safety' => null,
- 'node_class' => 'Twig_Node_Expression_Filter',
+ 'node_class' => '\Twig\Node\Expression\FilterExpression',
'deprecated' => false,
'alternative' => null,
], $options);
@@ -76,7 +76,7 @@ public function needsContext()
return $this->options['needs_context'];
}
- public function getSafe(Twig_Node $filterArgs)
+ public function getSafe(\Twig\Node\Node $filterArgs)
{
if (null !== $this->options['is_safe']) {
return $this->options['is_safe'];
diff --git a/lib/Twig/SimpleFunction.php b/lib/Twig/SimpleFunction.php
index 35699e0615..5920026090 100644
--- a/lib/Twig/SimpleFunction.php
+++ b/lib/Twig/SimpleFunction.php
@@ -33,7 +33,7 @@ public function __construct($name, $callable, array $options = [])
'is_variadic' => false,
'is_safe' => null,
'is_safe_callback' => null,
- 'node_class' => 'Twig_Node_Expression_Function',
+ 'node_class' => '\Twig\Node\Expression\FunctionExpression',
'deprecated' => false,
'alternative' => null,
], $options);
@@ -74,7 +74,7 @@ public function needsContext()
return $this->options['needs_context'];
}
- public function getSafe(Twig_Node $functionArgs)
+ public function getSafe(\Twig\Node\Node $functionArgs)
{
if (null !== $this->options['is_safe']) {
return $this->options['is_safe'];
diff --git a/lib/Twig/SimpleTest.php b/lib/Twig/SimpleTest.php
index 393fad1e0c..2da43b6218 100644
--- a/lib/Twig/SimpleTest.php
+++ b/lib/Twig/SimpleTest.php
@@ -30,7 +30,7 @@ public function __construct($name, $callable, array $options = [])
$this->callable = $callable;
$this->options = array_merge([
'is_variadic' => false,
- 'node_class' => 'Twig_Node_Expression_Test',
+ 'node_class' => '\Twig\Node\Expression\TestExpression',
'deprecated' => false,
'alternative' => null,
], $options);
diff --git a/lib/Twig/SourceContextLoaderInterface.php b/lib/Twig/SourceContextLoaderInterface.php
index a6e8c42550..c0b2b156e8 100644
--- a/lib/Twig/SourceContextLoaderInterface.php
+++ b/lib/Twig/SourceContextLoaderInterface.php
@@ -23,9 +23,9 @@ interface Twig_SourceContextLoaderInterface
*
* @param string $name The template logical name
*
- * @return Twig_Source
+ * @return \Twig\Source
*
- * @throws Twig_Error_Loader When $name is not found
+ * @throws \Twig\Error\LoaderError When $name is not found
*/
public function getSourceContext($name);
}
diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php
index 1968767477..810536a107 100644
--- a/lib/Twig/Template.php
+++ b/lib/Twig/Template.php
@@ -34,7 +34,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
protected $blocks = [];
protected $traits = [];
- public function __construct(Twig_Environment $env)
+ public function __construct(\Twig\Environment $env)
{
$this->env = $env;
}
@@ -83,11 +83,11 @@ public function getSource()
/**
* Returns information about the original template source code.
*
- * @return Twig_Source
+ * @return \Twig\Source
*/
public function getSourceContext()
{
- return new Twig_Source('', $this->getTemplateName());
+ return new \Twig\Source('', $this->getTemplateName());
}
/**
@@ -108,7 +108,7 @@ public function getEnvironment()
*
* @param array $context
*
- * @return Twig_TemplateInterface|Twig_TemplateWrapper|false The parent template or false if there is no parent
+ * @return Twig_TemplateInterface|\Twig\TemplateWrapper|false The parent template or false if there is no parent
*
* @internal
*/
@@ -125,14 +125,14 @@ public function getParent(array $context)
return false;
}
- if ($parent instanceof self || $parent instanceof Twig_TemplateWrapper) {
+ if ($parent instanceof self || $parent instanceof \Twig\TemplateWrapper) {
return $this->parents[$parent->getSourceContext()->getName()] = $parent;
}
if (!isset($this->parents[$parent])) {
$this->parents[$parent] = $this->loadTemplate($parent);
}
- } catch (Twig_Error_Loader $e) {
+ } catch (\Twig\Error\LoaderError $e) {
$e->setSourceContext(null);
$e->guess();
@@ -173,7 +173,7 @@ public function displayParentBlock($name, array $context, array $blocks = [])
} elseif (false !== $parent = $this->getParent($context)) {
$parent->displayBlock($name, $context, $blocks, false);
} else {
- throw new Twig_Error_Runtime(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext());
+ throw new \Twig\Error\RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext());
}
}
@@ -213,7 +213,7 @@ public function displayBlock($name, array $context, array $blocks = [], $useBloc
if (null !== $template) {
try {
$template->$block($context, $blocks);
- } catch (Twig_Error $e) {
+ } catch (\Twig\Error\Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($template->getSourceContext());
}
@@ -227,7 +227,7 @@ public function displayBlock($name, array $context, array $blocks = [], $useBloc
throw $e;
} catch (\Exception $e) {
- throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e);
+ throw new \Twig\Error\RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e);
}
} elseif (false !== $parent = $this->getParent($context)) {
$parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false);
@@ -355,14 +355,14 @@ protected function loadTemplate($template, $templateName = null, $line = null, $
return $this->env->resolveTemplate($template);
}
- if ($template instanceof self || $template instanceof Twig_TemplateWrapper) {
+ if ($template instanceof self || $template instanceof \Twig\TemplateWrapper) {
return $template;
}
return $this->env->loadTemplate($template, $index);
- } catch (Twig_Error $e) {
+ } catch (\Twig\Error\Error $e) {
if (!$e->getSourceContext()) {
- $e->setSourceContext($templateName ? new Twig_Source('', $templateName) : $this->getSourceContext());
+ $e->setSourceContext($templateName ? new \Twig\Source('', $templateName) : $this->getSourceContext());
}
if ($e->getTemplateLine()) {
@@ -426,7 +426,7 @@ protected function displayWithErrorHandling(array $context, array $blocks = [])
{
try {
$this->doDisplay($context, $blocks);
- } catch (Twig_Error $e) {
+ } catch (\Twig\Error\Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($this->getSourceContext());
}
@@ -440,7 +440,7 @@ protected function displayWithErrorHandling(array $context, array $blocks = [])
throw $e;
} catch (\Exception $e) {
- throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
+ throw new \Twig\Error\RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
}
}
@@ -469,7 +469,7 @@ abstract protected function doDisplay(array $context, array $blocks = []);
*
* @return mixed The content of the context variable
*
- * @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode
+ * @throws \Twig\Error\RuntimeError if the variable does not exist and Twig is running in strict mode
*
* @internal
*/
@@ -480,7 +480,7 @@ final protected function getContext($context, $item, $ignoreStrictCheck = false)
return;
}
- throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext());
+ throw new \Twig\Error\RuntimeError(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext());
}
return $context[$item];
@@ -498,7 +498,7 @@ final protected function getContext($context, $item, $ignoreStrictCheck = false)
*
* @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true
*
- * @throws Twig_Error_Runtime if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false
+ * @throws \Twig\Error\RuntimeError if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false
*
* @internal
*/
@@ -549,7 +549,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s
$message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, \gettype($object), $object);
}
- throw new Twig_Error_Runtime($message, -1, $this->getSourceContext());
+ throw new \Twig\Error\RuntimeError($message, -1, $this->getSourceContext());
}
}
@@ -570,7 +570,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s
$message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, \gettype($object), $object);
}
- throw new Twig_Error_Runtime($message, -1, $this->getSourceContext());
+ throw new \Twig\Error\RuntimeError($message, -1, $this->getSourceContext());
}
// object property
@@ -580,8 +580,8 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s
return true;
}
- if ($this->env->hasExtension('Twig_Extension_Sandbox')) {
- $this->env->getExtension('Twig_Extension_Sandbox')->checkPropertyAllowed($object, $item);
+ if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) {
+ $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkPropertyAllowed($object, $item);
}
return $object->$item;
@@ -655,15 +655,15 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s
return;
}
- throw new Twig_Error_Runtime(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext());
+ throw new \Twig\Error\RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext());
}
if ($isDefinedTest) {
return true;
}
- if ($this->env->hasExtension('Twig_Extension_Sandbox')) {
- $this->env->getExtension('Twig_Extension_Sandbox')->checkMethodAllowed($object, $method);
+ if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) {
+ $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkMethodAllowed($object, $method);
}
// Some objects throw exceptions when they have __call, and the method we try
@@ -694,7 +694,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s
}
@trigger_error($message, E_USER_DEPRECATED);
- return '' === $ret ? '' : new Twig_Markup($ret, $this->env->getCharset());
+ return '' === $ret ? '' : new \Twig\Markup($ret, $this->env->getCharset());
}
return $ret;
diff --git a/lib/Twig/TemplateInterface.php b/lib/Twig/TemplateInterface.php
index 4ab9c57014..3cbfe226f1 100644
--- a/lib/Twig/TemplateInterface.php
+++ b/lib/Twig/TemplateInterface.php
@@ -42,7 +42,7 @@ public function display(array $context, array $blocks = []);
/**
* Returns the bound environment for this template.
*
- * @return Twig_Environment
+ * @return \Twig\Environment
*/
public function getEnvironment();
}
diff --git a/lib/Twig/TemplateWrapper.php b/lib/Twig/TemplateWrapper.php
index 07ed715a30..3805fc6888 100644
--- a/lib/Twig/TemplateWrapper.php
+++ b/lib/Twig/TemplateWrapper.php
@@ -21,11 +21,11 @@ final class Twig_TemplateWrapper
/**
* This method is for internal use only and should never be called
- * directly (use Twig_Environment::load() instead).
+ * directly (use \Twig\Environment::load() instead).
*
* @internal
*/
- public function __construct(Twig_Environment $env, Twig_Template $template)
+ public function __construct(\Twig\Environment $env, \Twig\Template $template)
{
$this->env = $env;
$this->template = $template;
@@ -126,7 +126,7 @@ public function displayBlock($name, $context = [])
}
/**
- * @return Twig_Source
+ * @return \Twig\Source
*/
public function getSourceContext()
{
diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php
index a1b6efecf2..3a083734bf 100644
--- a/lib/Twig/Test/IntegrationTestCase.php
+++ b/lib/Twig/Test/IntegrationTestCase.php
@@ -25,7 +25,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase
abstract protected function getFixturesDir();
/**
- * @return Twig_RuntimeLoaderInterface[]
+ * @return \Twig\RuntimeLoader\RuntimeLoaderInterface[]
*/
protected function getRuntimeLoaders()
{
@@ -33,7 +33,7 @@ protected function getRuntimeLoaders()
}
/**
- * @return Twig_ExtensionInterface[]
+ * @return \Twig\Extension\ExtensionInterface[]
*/
protected function getExtensions()
{
@@ -41,7 +41,7 @@ protected function getExtensions()
}
/**
- * @return Twig_SimpleFilter[]
+ * @return \Twig\TwigFilter[]
*/
protected function getTwigFilters()
{
@@ -49,7 +49,7 @@ protected function getTwigFilters()
}
/**
- * @return Twig_SimpleFunction[]
+ * @return \Twig\TwigFunction[]
*/
protected function getTwigFunctions()
{
@@ -57,7 +57,7 @@ protected function getTwigFunctions()
}
/**
- * @return Twig_SimpleTest[]
+ * @return \Twig\TwigTest[]
*/
protected function getTwigTests()
{
@@ -142,14 +142,14 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e
}
}
- $loader = new Twig_Loader_Array($templates);
+ $loader = new \Twig\Loader\ArrayLoader($templates);
foreach ($outputs as $i => $match) {
$config = array_merge([
'cache' => false,
'strict_variables' => true,
], $match[2] ? eval($match[2].';') : []);
- $twig = new Twig_Environment($loader, $config);
+ $twig = new \Twig\Environment($loader, $config);
$twig->addGlobal('global', 'global');
foreach ($this->getRuntimeLoaders() as $runtimeLoader) {
$twig->addRuntimeLoader($runtimeLoader);
@@ -187,7 +187,7 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e
return;
}
- throw new Twig_Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e);
+ throw new \Twig\Error\Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e);
}
try {
@@ -199,7 +199,7 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e
return;
}
- $e = new Twig_Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e);
+ $e = new \Twig\Error\Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e);
$output = trim(sprintf('%s: %s', \get_class($e), $e->getMessage()));
}
@@ -218,8 +218,8 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e
foreach (array_keys($templates) as $name) {
echo "Template: $name\n";
$loader = $twig->getLoader();
- if (!$loader instanceof Twig_SourceContextLoaderInterface) {
- $source = new Twig_Source($loader->getSource($name), $name);
+ if (!$loader instanceof \Twig\Loader\SourceContextLoaderInterface) {
+ $source = new \Twig\Source($loader->getSource($name), $name);
} else {
$source = $loader->getSourceContext($name);
}
diff --git a/lib/Twig/Test/Method.php b/lib/Twig/Test/Method.php
index 25d5dfc71f..e4124f223c 100644
--- a/lib/Twig/Test/Method.php
+++ b/lib/Twig/Test/Method.php
@@ -23,7 +23,7 @@ class Twig_Test_Method extends Twig_Test
protected $extension;
protected $method;
- public function __construct(Twig_ExtensionInterface $extension, $method, array $options = [])
+ public function __construct(\Twig\Extension\ExtensionInterface $extension, $method, array $options = [])
{
$options['callable'] = [$extension, $method];
diff --git a/lib/Twig/Test/NodeTestCase.php b/lib/Twig/Test/NodeTestCase.php
index 083b3f2ead..ea0f8bb3f5 100644
--- a/lib/Twig/Test/NodeTestCase.php
+++ b/lib/Twig/Test/NodeTestCase.php
@@ -23,7 +23,7 @@ public function testCompile($node, $source, $environment = null, $isPattern = fa
$this->assertNodeCompilation($source, $node, $environment, $isPattern);
}
- public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null, $isPattern = false)
+ public function assertNodeCompilation($source, \Twig\Node\Node $node, \Twig\Environment $environment = null, $isPattern = false)
{
$compiler = $this->getCompiler($environment);
$compiler->compile($node);
@@ -35,14 +35,14 @@ public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment
}
}
- protected function getCompiler(Twig_Environment $environment = null)
+ protected function getCompiler(\Twig\Environment $environment = null)
{
- return new Twig_Compiler(null === $environment ? $this->getEnvironment() : $environment);
+ return new \Twig\Compiler(null === $environment ? $this->getEnvironment() : $environment);
}
protected function getEnvironment()
{
- return new Twig_Environment(new Twig_Loader_Array([]));
+ return new \Twig\Environment(new \Twig\Loader\ArrayLoader([]));
}
protected function getVariableGetter($name, $line = false)
diff --git a/lib/Twig/Token.php b/lib/Twig/Token.php
index 4faef4f56c..4bcd76b91e 100644
--- a/lib/Twig/Token.php
+++ b/lib/Twig/Token.php
@@ -159,7 +159,7 @@ public static function typeToString($type, $short = false)
throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type));
}
- return $short ? $name : 'Twig_Token::'.$name;
+ return $short ? $name : '\Twig\Token::'.$name;
}
/**
diff --git a/lib/Twig/TokenParser.php b/lib/Twig/TokenParser.php
index 1b4de14da5..e8fa01a25b 100644
--- a/lib/Twig/TokenParser.php
+++ b/lib/Twig/TokenParser.php
@@ -14,7 +14,7 @@
*
* @author Fabien Potencier
*/
-abstract class Twig_TokenParser implements Twig_TokenParserInterface
+abstract class Twig_TokenParser implements \Twig\TokenParser\TokenParserInterface
{
/**
* @var Twig_Parser
@@ -24,7 +24,7 @@ abstract class Twig_TokenParser implements Twig_TokenParserInterface
/**
* Sets the parser associated with this token parser.
*/
- public function setParser(Twig_Parser $parser)
+ public function setParser(\Twig\Parser $parser)
{
$this->parser = $parser;
}
diff --git a/lib/Twig/TokenParser/AutoEscape.php b/lib/Twig/TokenParser/AutoEscape.php
index 7ea6ba5178..42f62d981b 100644
--- a/lib/Twig/TokenParser/AutoEscape.php
+++ b/lib/Twig/TokenParser/AutoEscape.php
@@ -27,19 +27,19 @@
*
* @final
*/
-class Twig_TokenParser_AutoEscape extends Twig_TokenParser
+class Twig_TokenParser_AutoEscape extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
- if ($stream->test(Twig_Token::BLOCK_END_TYPE)) {
+ if ($stream->test(\Twig\Token::BLOCK_END_TYPE)) {
$value = 'html';
} else {
$expr = $this->parser->getExpressionParser()->parseExpression();
- if (!$expr instanceof Twig_Node_Expression_Constant) {
- throw new Twig_Error_Syntax('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
+ if (!$expr instanceof \Twig\Node\Expression\ConstantExpression) {
+ throw new \Twig\Error\SyntaxError('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
$value = $expr->getAttribute('value');
@@ -49,25 +49,25 @@ public function parse(Twig_Token $token)
$value = 'html';
}
- if ($compat && $stream->test(Twig_Token::NAME_TYPE)) {
+ if ($compat && $stream->test(\Twig\Token::NAME_TYPE)) {
@trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED);
if (false === $value) {
- throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
$value = $stream->next()->getValue();
}
}
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag());
+ return new \Twig\Node\AutoEscapeNode($value, $body, $lineno, $this->getTag());
}
- public function decideBlockEnd(Twig_Token $token)
+ public function decideBlockEnd(\Twig\Token $token)
{
return $token->test('endautoescape');
}
diff --git a/lib/Twig/TokenParser/Block.php b/lib/Twig/TokenParser/Block.php
index ef5433cc11..c45289c5ba 100644
--- a/lib/Twig/TokenParser/Block.php
+++ b/lib/Twig/TokenParser/Block.php
@@ -20,44 +20,44 @@
*
* @final
*/
-class Twig_TokenParser_Block extends Twig_TokenParser
+class Twig_TokenParser_Block extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
- $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
+ $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue();
if ($this->parser->hasBlock($name)) {
- throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
- $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node([]), $lineno));
+ $this->parser->setBlock($name, $block = new \Twig\Node\BlockNode($name, new \Twig\Node\Node([]), $lineno));
$this->parser->pushLocalScope();
$this->parser->pushBlockStack($name);
- if ($stream->nextIf(Twig_Token::BLOCK_END_TYPE)) {
+ if ($stream->nextIf(\Twig\Token::BLOCK_END_TYPE)) {
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
- if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
+ if ($token = $stream->nextIf(\Twig\Token::NAME_TYPE)) {
$value = $token->getValue();
if ($value != $name) {
- throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
}
} else {
- $body = new Twig_Node([
- new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno),
+ $body = new \Twig\Node\Node([
+ new \Twig\Node\PrintNode($this->parser->getExpressionParser()->parseExpression(), $lineno),
]);
}
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$block->setNode('body', $body);
$this->parser->popBlockStack();
$this->parser->popLocalScope();
- return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
+ return new \Twig\Node\BlockReferenceNode($name, $lineno, $this->getTag());
}
- public function decideBlockEnd(Twig_Token $token)
+ public function decideBlockEnd(\Twig\Token $token)
{
return $token->test('endblock');
}
diff --git a/lib/Twig/TokenParser/Deprecated.php b/lib/Twig/TokenParser/Deprecated.php
index 064fec7011..05ea042516 100644
--- a/lib/Twig/TokenParser/Deprecated.php
+++ b/lib/Twig/TokenParser/Deprecated.php
@@ -19,15 +19,15 @@
*
* @final
*/
-class Twig_TokenParser_Deprecated extends Twig_TokenParser
+class Twig_TokenParser_Deprecated extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$expr = $this->parser->getExpressionParser()->parseExpression();
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node_Deprecated($expr, $token->getLine(), $this->getTag());
+ return new \Twig\Node\DeprecatedNode($expr, $token->getLine(), $this->getTag());
}
public function getTag()
diff --git a/lib/Twig/TokenParser/Do.php b/lib/Twig/TokenParser/Do.php
index 8ce088089e..7d788668a5 100644
--- a/lib/Twig/TokenParser/Do.php
+++ b/lib/Twig/TokenParser/Do.php
@@ -14,15 +14,15 @@
*
* @final
*/
-class Twig_TokenParser_Do extends Twig_TokenParser
+class Twig_TokenParser_Do extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$expr = $this->parser->getExpressionParser()->parseExpression();
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node_Do($expr, $token->getLine(), $this->getTag());
+ return new \Twig\Node\DoNode($expr, $token->getLine(), $this->getTag());
}
public function getTag()
diff --git a/lib/Twig/TokenParser/Embed.php b/lib/Twig/TokenParser/Embed.php
index 62ad917096..7003f180ed 100644
--- a/lib/Twig/TokenParser/Embed.php
+++ b/lib/Twig/TokenParser/Embed.php
@@ -14,9 +14,9 @@
*
* @final
*/
-class Twig_TokenParser_Embed extends Twig_TokenParser_Include
+class Twig_TokenParser_Embed extends \Twig\TokenParser\IncludeTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$stream = $this->parser->getStream();
@@ -24,19 +24,19 @@ public function parse(Twig_Token $token)
list($variables, $only, $ignoreMissing) = $this->parseArguments();
- $parentToken = $fakeParentToken = new Twig_Token(Twig_Token::STRING_TYPE, '__parent__', $token->getLine());
- if ($parent instanceof Twig_Node_Expression_Constant) {
- $parentToken = new Twig_Token(Twig_Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine());
- } elseif ($parent instanceof Twig_Node_Expression_Name) {
- $parentToken = new Twig_Token(Twig_Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine());
+ $parentToken = $fakeParentToken = new \Twig\Token(\Twig\Token::STRING_TYPE, '__parent__', $token->getLine());
+ if ($parent instanceof \Twig\Node\Expression\ConstantExpression) {
+ $parentToken = new \Twig\Token(\Twig\Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine());
+ } elseif ($parent instanceof \Twig\Node\Expression\NameExpression) {
+ $parentToken = new \Twig\Token(\Twig\Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine());
}
// inject a fake parent to make the parent() function work
$stream->injectTokens([
- new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $token->getLine()),
- new Twig_Token(Twig_Token::NAME_TYPE, 'extends', $token->getLine()),
+ new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', $token->getLine()),
+ new \Twig\Token(\Twig\Token::NAME_TYPE, 'extends', $token->getLine()),
$parentToken,
- new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', $token->getLine()),
+ new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', $token->getLine()),
]);
$module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true);
@@ -48,12 +48,12 @@ public function parse(Twig_Token $token)
$this->parser->embedTemplate($module);
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node_Embed($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
+ return new \Twig\Node\EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
}
- public function decideBlockEnd(Twig_Token $token)
+ public function decideBlockEnd(\Twig\Token $token)
{
return $token->test('endembed');
}
diff --git a/lib/Twig/TokenParser/Extends.php b/lib/Twig/TokenParser/Extends.php
index 0271598305..cb1c5fda35 100644
--- a/lib/Twig/TokenParser/Extends.php
+++ b/lib/Twig/TokenParser/Extends.php
@@ -17,22 +17,22 @@
*
* @final
*/
-class Twig_TokenParser_Extends extends Twig_TokenParser
+class Twig_TokenParser_Extends extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$stream = $this->parser->getStream();
if (!$this->parser->isMainScope()) {
- throw new Twig_Error_Syntax('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext());
}
if (null !== $this->parser->getParent()) {
- throw new Twig_Error_Syntax('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext());
}
$this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
}
public function getTag()
diff --git a/lib/Twig/TokenParser/Filter.php b/lib/Twig/TokenParser/Filter.php
index aa7aa9824e..ebb6cd99c2 100644
--- a/lib/Twig/TokenParser/Filter.php
+++ b/lib/Twig/TokenParser/Filter.php
@@ -18,26 +18,26 @@
*
* @final
*/
-class Twig_TokenParser_Filter extends Twig_TokenParser
+class Twig_TokenParser_Filter extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$name = $this->parser->getVarName();
- $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), null, $token->getLine(), $this->getTag());
+ $ref = new \Twig\Node\Expression\BlockReferenceExpression(new \Twig\Node\Expression\ConstantExpression($name, $token->getLine()), null, $token->getLine(), $this->getTag());
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
- $block = new Twig_Node_Block($name, $body, $token->getLine());
+ $block = new \Twig\Node\BlockNode($name, $body, $token->getLine());
$this->parser->setBlock($name, $block);
- return new Twig_Node_Print($filter, $token->getLine(), $this->getTag());
+ return new \Twig\Node\PrintNode($filter, $token->getLine(), $this->getTag());
}
- public function decideBlockEnd(Twig_Token $token)
+ public function decideBlockEnd(\Twig\Token $token)
{
return $token->test('endfilter');
}
diff --git a/lib/Twig/TokenParser/Flush.php b/lib/Twig/TokenParser/Flush.php
index 51832c77e1..67db2d87af 100644
--- a/lib/Twig/TokenParser/Flush.php
+++ b/lib/Twig/TokenParser/Flush.php
@@ -16,13 +16,13 @@
*
* @final
*/
-class Twig_TokenParser_Flush extends Twig_TokenParser
+class Twig_TokenParser_Flush extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node_Flush($token->getLine(), $this->getTag());
+ return new \Twig\Node\FlushNode($token->getLine(), $this->getTag());
}
public function getTag()
diff --git a/lib/Twig/TokenParser/For.php b/lib/Twig/TokenParser/For.php
index bbbe24c462..6518a2519f 100644
--- a/lib/Twig/TokenParser/For.php
+++ b/lib/Twig/TokenParser/For.php
@@ -21,40 +21,40 @@
*
* @final
*/
-class Twig_TokenParser_For extends Twig_TokenParser
+class Twig_TokenParser_For extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
- $stream->expect(Twig_Token::OPERATOR_TYPE, 'in');
+ $stream->expect(\Twig\Token::OPERATOR_TYPE, 'in');
$seq = $this->parser->getExpressionParser()->parseExpression();
$ifexpr = null;
- if ($stream->nextIf(Twig_Token::NAME_TYPE, 'if')) {
+ if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'if')) {
$ifexpr = $this->parser->getExpressionParser()->parseExpression();
}
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideForFork']);
if ('else' == $stream->next()->getValue()) {
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$else = $this->parser->subparse([$this, 'decideForEnd'], true);
} else {
$else = null;
}
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
if (\count($targets) > 1) {
$keyTarget = $targets->getNode(0);
- $keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine());
+ $keyTarget = new \Twig\Node\Expression\AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine());
$valueTarget = $targets->getNode(1);
- $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
+ $valueTarget = new \Twig\Node\Expression\AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
} else {
- $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno);
+ $keyTarget = new \Twig\Node\Expression\AssignNameExpression('_key', $lineno);
$valueTarget = $targets->getNode(0);
- $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
+ $valueTarget = new \Twig\Node\Expression\AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
}
if ($ifexpr) {
@@ -62,24 +62,24 @@ public function parse(Twig_Token $token)
$this->checkLoopUsageBody($stream, $body);
}
- return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag());
+ return new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag());
}
- public function decideForFork(Twig_Token $token)
+ public function decideForFork(\Twig\Token $token)
{
return $token->test(['else', 'endfor']);
}
- public function decideForEnd(Twig_Token $token)
+ public function decideForEnd(\Twig\Token $token)
{
return $token->test('endfor');
}
// the loop variable cannot be used in the condition
- protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node)
+ protected function checkLoopUsageCondition(\Twig\TokenStream $stream, Twig_NodeInterface $node)
{
- if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
- throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext());
+ if ($node instanceof \Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \Twig\Node\Expression\NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) {
+ throw new \Twig\Error\SyntaxError('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext());
}
foreach ($node as $n) {
@@ -93,17 +93,17 @@ protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeIn
// check usage of non-defined loop-items
// it does not catch all problems (for instance when a for is included into another or when the variable is used in an include)
- protected function checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node)
+ protected function checkLoopUsageBody(\Twig\TokenStream $stream, Twig_NodeInterface $node)
{
- if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
+ if ($node instanceof \Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \Twig\Node\Expression\NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) {
$attribute = $node->getNode('attribute');
- if ($attribute instanceof Twig_Node_Expression_Constant && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) {
- throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext());
+ if ($attribute instanceof \Twig\Node\Expression\ConstantExpression && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) {
+ throw new \Twig\Error\SyntaxError(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext());
}
}
// should check for parent.loop.XXX usage
- if ($node instanceof Twig_Node_For) {
+ if ($node instanceof \Twig\Node\ForNode) {
return;
}
diff --git a/lib/Twig/TokenParser/From.php b/lib/Twig/TokenParser/From.php
index 689cfa55be..50f7b5d4ce 100644
--- a/lib/Twig/TokenParser/From.php
+++ b/lib/Twig/TokenParser/From.php
@@ -16,9 +16,9 @@
*
* @final
*/
-class Twig_TokenParser_From extends Twig_TokenParser
+class Twig_TokenParser_From extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$macro = $this->parser->getExpressionParser()->parseExpression();
$stream = $this->parser->getStream();
@@ -26,27 +26,27 @@ public function parse(Twig_Token $token)
$targets = [];
do {
- $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
+ $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue();
$alias = $name;
if ($stream->nextIf('as')) {
- $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
+ $alias = $stream->expect(\Twig\Token::NAME_TYPE)->getValue();
}
$targets[$name] = $alias;
- if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
+ if (!$stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) {
break;
}
} while (true);
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
- $node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag());
+ $node = new \Twig\Node\ImportNode($macro, new \Twig\Node\Expression\AssignNameExpression($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag());
foreach ($targets as $name => $alias) {
if ($this->parser->isReservedMacroName($name)) {
- throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
}
$this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var'));
diff --git a/lib/Twig/TokenParser/If.php b/lib/Twig/TokenParser/If.php
index 89f974bd7c..a26d0839e4 100644
--- a/lib/Twig/TokenParser/If.php
+++ b/lib/Twig/TokenParser/If.php
@@ -23,14 +23,14 @@
*
* @final
*/
-class Twig_TokenParser_If extends Twig_TokenParser
+class Twig_TokenParser_If extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$lineno = $token->getLine();
$expr = $this->parser->getExpressionParser()->parseExpression();
$stream = $this->parser->getStream();
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideIfFork']);
$tests = [$expr, $body];
$else = null;
@@ -39,13 +39,13 @@ public function parse(Twig_Token $token)
while (!$end) {
switch ($stream->next()->getValue()) {
case 'else':
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$else = $this->parser->subparse([$this, 'decideIfEnd']);
break;
case 'elseif':
$expr = $this->parser->getExpressionParser()->parseExpression();
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideIfFork']);
$tests[] = $expr;
$tests[] = $body;
@@ -56,21 +56,21 @@ public function parse(Twig_Token $token)
break;
default:
- throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
}
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag());
+ return new \Twig\Node\IfNode(new \Twig\Node\Node($tests), $else, $lineno, $this->getTag());
}
- public function decideIfFork(Twig_Token $token)
+ public function decideIfFork(\Twig\Token $token)
{
return $token->test(['elseif', 'else', 'endif']);
}
- public function decideIfEnd(Twig_Token $token)
+ public function decideIfEnd(\Twig\Token $token)
{
return $token->test(['endif']);
}
diff --git a/lib/Twig/TokenParser/Import.php b/lib/Twig/TokenParser/Import.php
index caebd80d80..3b5dd9ae49 100644
--- a/lib/Twig/TokenParser/Import.php
+++ b/lib/Twig/TokenParser/Import.php
@@ -16,18 +16,18 @@
*
* @final
*/
-class Twig_TokenParser_Import extends Twig_TokenParser
+class Twig_TokenParser_Import extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$macro = $this->parser->getExpressionParser()->parseExpression();
$this->parser->getStream()->expect('as');
- $var = new Twig_Node_Expression_AssignName($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(), $token->getLine());
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $var = new \Twig\Node\Expression\AssignNameExpression($this->parser->getStream()->expect(\Twig\Token::NAME_TYPE)->getValue(), $token->getLine());
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
$this->parser->addImportedSymbol('template', $var->getAttribute('name'));
- return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag());
+ return new \Twig\Node\ImportNode($macro, $var, $token->getLine(), $this->getTag());
}
public function getTag()
diff --git a/lib/Twig/TokenParser/Include.php b/lib/Twig/TokenParser/Include.php
index f53f2a1643..a673a06639 100644
--- a/lib/Twig/TokenParser/Include.php
+++ b/lib/Twig/TokenParser/Include.php
@@ -17,15 +17,15 @@
* Body
* {% include 'footer.html' %}
*/
-class Twig_TokenParser_Include extends Twig_TokenParser
+class Twig_TokenParser_Include extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$expr = $this->parser->getExpressionParser()->parseExpression();
list($variables, $only, $ignoreMissing) = $this->parseArguments();
- return new Twig_Node_Include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
+ return new \Twig\Node\IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
}
protected function parseArguments()
@@ -33,23 +33,23 @@ protected function parseArguments()
$stream = $this->parser->getStream();
$ignoreMissing = false;
- if ($stream->nextIf(Twig_Token::NAME_TYPE, 'ignore')) {
- $stream->expect(Twig_Token::NAME_TYPE, 'missing');
+ if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'ignore')) {
+ $stream->expect(\Twig\Token::NAME_TYPE, 'missing');
$ignoreMissing = true;
}
$variables = null;
- if ($stream->nextIf(Twig_Token::NAME_TYPE, 'with')) {
+ if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'with')) {
$variables = $this->parser->getExpressionParser()->parseExpression();
}
$only = false;
- if ($stream->nextIf(Twig_Token::NAME_TYPE, 'only')) {
+ if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'only')) {
$only = true;
}
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
return [$variables, $only, $ignoreMissing];
}
diff --git a/lib/Twig/TokenParser/Macro.php b/lib/Twig/TokenParser/Macro.php
index 738731e6ce..e0462c76f4 100644
--- a/lib/Twig/TokenParser/Macro.php
+++ b/lib/Twig/TokenParser/Macro.php
@@ -18,33 +18,33 @@
*
* @final
*/
-class Twig_TokenParser_Macro extends Twig_TokenParser
+class Twig_TokenParser_Macro extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
- $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
+ $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue();
$arguments = $this->parser->getExpressionParser()->parseArguments(true, true);
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$this->parser->pushLocalScope();
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
- if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
+ if ($token = $stream->nextIf(\Twig\Token::NAME_TYPE)) {
$value = $token->getValue();
if ($value != $name) {
- throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
}
$this->parser->popLocalScope();
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
- $this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body([$body]), $arguments, $lineno, $this->getTag()));
+ $this->parser->setMacro($name, new \Twig\Node\MacroNode($name, new \Twig\Node\BodyNode([$body]), $arguments, $lineno, $this->getTag()));
}
- public function decideBlockEnd(Twig_Token $token)
+ public function decideBlockEnd(\Twig\Token $token)
{
return $token->test('endmacro');
}
diff --git a/lib/Twig/TokenParser/Sandbox.php b/lib/Twig/TokenParser/Sandbox.php
index fa2045743f..9adfb0938d 100644
--- a/lib/Twig/TokenParser/Sandbox.php
+++ b/lib/Twig/TokenParser/Sandbox.php
@@ -20,32 +20,32 @@
*
* @final
*/
-class Twig_TokenParser_Sandbox extends Twig_TokenParser
+class Twig_TokenParser_Sandbox extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$stream = $this->parser->getStream();
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
// in a sandbox tag, only include tags are allowed
- if (!$body instanceof Twig_Node_Include) {
+ if (!$body instanceof \Twig\Node\IncludeNode) {
foreach ($body as $node) {
- if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) {
+ if ($node instanceof \Twig\Node\TextNode && ctype_space($node->getAttribute('data'))) {
continue;
}
- if (!$node instanceof Twig_Node_Include) {
- throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext());
+ if (!$node instanceof \Twig\Node\IncludeNode) {
+ throw new \Twig\Error\SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext());
}
}
}
- return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag());
+ return new \Twig\Node\SandboxNode($body, $token->getLine(), $this->getTag());
}
- public function decideBlockEnd(Twig_Token $token)
+ public function decideBlockEnd(\Twig\Token $token)
{
return $token->test('endsandbox');
}
diff --git a/lib/Twig/TokenParser/Set.php b/lib/Twig/TokenParser/Set.php
index e60ee6c899..55a45f83f3 100644
--- a/lib/Twig/TokenParser/Set.php
+++ b/lib/Twig/TokenParser/Set.php
@@ -21,40 +21,40 @@
*
* @final
*/
-class Twig_TokenParser_Set extends Twig_TokenParser
+class Twig_TokenParser_Set extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$names = $this->parser->getExpressionParser()->parseAssignmentExpression();
$capture = false;
- if ($stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) {
+ if ($stream->nextIf(\Twig\Token::OPERATOR_TYPE, '=')) {
$values = $this->parser->getExpressionParser()->parseMultitargetExpression();
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
if (\count($names) !== \count($values)) {
- throw new Twig_Error_Syntax('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
} else {
$capture = true;
if (\count($names) > 1) {
- throw new Twig_Error_Syntax('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
+ throw new \Twig\Error\SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$values = $this->parser->subparse([$this, 'decideBlockEnd'], true);
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
}
- return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag());
+ return new \Twig\Node\SetNode($capture, $names, $values, $lineno, $this->getTag());
}
- public function decideBlockEnd(Twig_Token $token)
+ public function decideBlockEnd(\Twig\Token $token)
{
return $token->test('endset');
}
diff --git a/lib/Twig/TokenParser/Spaceless.php b/lib/Twig/TokenParser/Spaceless.php
index 6a3f33ffc7..3b303ea5a3 100644
--- a/lib/Twig/TokenParser/Spaceless.php
+++ b/lib/Twig/TokenParser/Spaceless.php
@@ -21,20 +21,20 @@
*
* @final
*/
-class Twig_TokenParser_Spaceless extends Twig_TokenParser
+class Twig_TokenParser_Spaceless extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$lineno = $token->getLine();
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true);
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node_Spaceless($body, $lineno, $this->getTag());
+ return new \Twig\Node\SpacelessNode($body, $lineno, $this->getTag());
}
- public function decideSpacelessEnd(Twig_Token $token)
+ public function decideSpacelessEnd(\Twig\Token $token)
{
return $token->test('endspaceless');
}
diff --git a/lib/Twig/TokenParser/Use.php b/lib/Twig/TokenParser/Use.php
index 7e293001e4..1a515e836f 100644
--- a/lib/Twig/TokenParser/Use.php
+++ b/lib/Twig/TokenParser/Use.php
@@ -23,40 +23,40 @@
*
* @final
*/
-class Twig_TokenParser_Use extends Twig_TokenParser
+class Twig_TokenParser_Use extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$template = $this->parser->getExpressionParser()->parseExpression();
$stream = $this->parser->getStream();
- if (!$template instanceof Twig_Node_Expression_Constant) {
- throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
+ if (!$template instanceof \Twig\Node\Expression\ConstantExpression) {
+ throw new \Twig\Error\SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
$targets = [];
if ($stream->nextIf('with')) {
do {
- $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
+ $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue();
$alias = $name;
if ($stream->nextIf('as')) {
- $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
+ $alias = $stream->expect(\Twig\Token::NAME_TYPE)->getValue();
}
- $targets[$name] = new Twig_Node_Expression_Constant($alias, -1);
+ $targets[$name] = new \Twig\Node\Expression\ConstantExpression($alias, -1);
- if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
+ if (!$stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) {
break;
}
} while (true);
}
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
- $this->parser->addTrait(new Twig_Node(['template' => $template, 'targets' => new Twig_Node($targets)]));
+ $this->parser->addTrait(new \Twig\Node\Node(['template' => $template, 'targets' => new \Twig\Node\Node($targets)]));
- return new Twig_Node();
+ return new \Twig\Node\Node();
}
public function getTag()
diff --git a/lib/Twig/TokenParser/With.php b/lib/Twig/TokenParser/With.php
index 34a0812207..66e55ace53 100644
--- a/lib/Twig/TokenParser/With.php
+++ b/lib/Twig/TokenParser/With.php
@@ -16,29 +16,29 @@
*
* @final
*/
-class Twig_TokenParser_With extends Twig_TokenParser
+class Twig_TokenParser_With extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
$stream = $this->parser->getStream();
$variables = null;
$only = false;
- if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) {
+ if (!$stream->test(\Twig\Token::BLOCK_END_TYPE)) {
$variables = $this->parser->getExpressionParser()->parseExpression();
- $only = $stream->nextIf(Twig_Token::NAME_TYPE, 'only');
+ $only = $stream->nextIf(\Twig\Token::NAME_TYPE, 'only');
}
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideWithEnd'], true);
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node_With($body, $variables, $only, $token->getLine(), $this->getTag());
+ return new \Twig\Node\WithNode($body, $variables, $only, $token->getLine(), $this->getTag());
}
- public function decideWithEnd(Twig_Token $token)
+ public function decideWithEnd(\Twig\Token $token)
{
return $token->test('endwith');
}
diff --git a/lib/Twig/TokenParserBroker.php b/lib/Twig/TokenParserBroker.php
index e7f787969b..3e1871f48b 100644
--- a/lib/Twig/TokenParserBroker.php
+++ b/lib/Twig/TokenParserBroker.php
@@ -35,7 +35,7 @@ public function __construct($parsers = [], $brokers = [], $triggerDeprecationErr
}
foreach ($parsers as $parser) {
- if (!$parser instanceof Twig_TokenParserInterface) {
+ if (!$parser instanceof \Twig\TokenParser\TokenParserInterface) {
throw new \LogicException('$parsers must a an array of Twig_TokenParserInterface.');
}
$this->parsers[$parser->getTag()] = $parser;
@@ -48,12 +48,12 @@ public function __construct($parsers = [], $brokers = [], $triggerDeprecationErr
}
}
- public function addTokenParser(Twig_TokenParserInterface $parser)
+ public function addTokenParser(\Twig\TokenParser\TokenParserInterface $parser)
{
$this->parsers[$parser->getTag()] = $parser;
}
- public function removeTokenParser(Twig_TokenParserInterface $parser)
+ public function removeTokenParser(\Twig\TokenParser\TokenParserInterface $parser)
{
$name = $parser->getTag();
if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) {
@@ -80,7 +80,7 @@ public function removeTokenParserBroker(self $broker)
*
* @param string $tag A tag name
*
- * @return Twig_TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found
+ * @return \Twig\TokenParser\TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found
*/
public function getTokenParser($tag)
{
diff --git a/lib/Twig/TokenParserBrokerInterface.php b/lib/Twig/TokenParserBrokerInterface.php
index c239c2ec82..7a5d563eca 100644
--- a/lib/Twig/TokenParserBrokerInterface.php
+++ b/lib/Twig/TokenParserBrokerInterface.php
@@ -26,12 +26,12 @@ interface Twig_TokenParserBrokerInterface
*
* @param string $tag A tag name
*
- * @return Twig_TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found
+ * @return \Twig\TokenParser\TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found
*/
public function getTokenParser($tag);
/**
- * Calls Twig_TokenParserInterface::setParser on all parsers the implementation knows of.
+ * Calls \Twig\TokenParser\TokenParserInterface::setParser on all parsers the implementation knows of.
*/
public function setParser(Twig_ParserInterface $parser);
diff --git a/lib/Twig/TokenParserInterface.php b/lib/Twig/TokenParserInterface.php
index 14acc8084b..2090ae187e 100644
--- a/lib/Twig/TokenParserInterface.php
+++ b/lib/Twig/TokenParserInterface.php
@@ -19,16 +19,16 @@ interface Twig_TokenParserInterface
/**
* Sets the parser associated with this token parser.
*/
- public function setParser(Twig_Parser $parser);
+ public function setParser(\Twig\Parser $parser);
/**
* Parses a token and returns a node.
*
* @return Twig_NodeInterface
*
- * @throws Twig_Error_Syntax
+ * @throws \Twig\Error\SyntaxError
*/
- public function parse(Twig_Token $token);
+ public function parse(\Twig\Token $token);
/**
* Gets the tag name associated with this token parser.
diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php
index 73374908b8..89b1fb711e 100644
--- a/lib/Twig/TokenStream.php
+++ b/lib/Twig/TokenStream.php
@@ -32,11 +32,11 @@ class Twig_TokenStream
*/
public function __construct(array $tokens, $name = null, $source = null)
{
- if (!$name instanceof Twig_Source) {
+ if (!$name instanceof \Twig\Source) {
if (null !== $name || null !== $source) {
@trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
}
- $this->source = new Twig_Source($source, $name);
+ $this->source = new \Twig\Source($source, $name);
} else {
$this->source = $name;
}
@@ -60,12 +60,12 @@ public function injectTokens(array $tokens)
/**
* Sets the pointer to the next token and returns the old one.
*
- * @return Twig_Token
+ * @return \Twig\Token
*/
public function next()
{
if (!isset($this->tokens[++$this->current])) {
- throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source);
+ throw new \Twig\Error\SyntaxError('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source);
}
return $this->tokens[$this->current - 1];
@@ -74,7 +74,7 @@ public function next()
/**
* Tests a token, sets the pointer to the next one and returns it or throws a syntax error.
*
- * @return Twig_Token|null The next token if the condition is true, null otherwise
+ * @return \Twig\Token|null The next token if the condition is true, null otherwise
*/
public function nextIf($primary, $secondary = null)
{
@@ -86,17 +86,17 @@ public function nextIf($primary, $secondary = null)
/**
* Tests a token and returns it or throws a syntax error.
*
- * @return Twig_Token
+ * @return \Twig\Token
*/
public function expect($type, $value = null, $message = null)
{
$token = $this->tokens[$this->current];
if (!$token->test($type, $value)) {
$line = $token->getLine();
- throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).',
+ throw new \Twig\Error\SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).',
$message ? $message.'. ' : '',
- Twig_Token::typeToEnglish($token->getType()), $token->getValue(),
- Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''),
+ \Twig\Token::typeToEnglish($token->getType()), $token->getValue(),
+ \Twig\Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''),
$line,
$this->source
);
@@ -111,12 +111,12 @@ public function expect($type, $value = null, $message = null)
*
* @param int $number
*
- * @return Twig_Token
+ * @return \Twig\Token
*/
public function look($number = 1)
{
if (!isset($this->tokens[$this->current + $number])) {
- throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source);
+ throw new \Twig\Error\SyntaxError('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source);
}
return $this->tokens[$this->current + $number];
@@ -139,11 +139,11 @@ public function test($primary, $secondary = null)
*/
public function isEOF()
{
- return Twig_Token::EOF_TYPE === $this->tokens[$this->current]->getType();
+ return \Twig\Token::EOF_TYPE === $this->tokens[$this->current]->getType();
}
/**
- * @return Twig_Token
+ * @return \Twig\Token
*/
public function getCurrent()
{
@@ -183,7 +183,7 @@ public function getSource()
/**
* Gets the source associated with this stream.
*
- * @return Twig_Source
+ * @return \Twig\Source
*
* @internal
*/
diff --git a/lib/Twig/Util/DeprecationCollector.php b/lib/Twig/Util/DeprecationCollector.php
index 6f3da609af..f4c2bd25e2 100644
--- a/lib/Twig/Util/DeprecationCollector.php
+++ b/lib/Twig/Util/DeprecationCollector.php
@@ -19,7 +19,7 @@ class Twig_Util_DeprecationCollector
private $twig;
private $deprecations;
- public function __construct(Twig_Environment $twig)
+ public function __construct(\Twig\Environment $twig)
{
$this->twig = $twig;
}
@@ -40,7 +40,7 @@ public function collectDir($dir, $ext = '.twig')
), '{'.preg_quote($ext).'$}'
);
- return $this->collect(new Twig_Util_TemplateDirIterator($iterator));
+ return $this->collect(new \Twig\Util\TemplateDirIterator($iterator));
}
/**
@@ -58,8 +58,8 @@ public function collect(\Traversable $iterator)
foreach ($iterator as $name => $contents) {
try {
- $this->twig->parse($this->twig->tokenize(new Twig_Source($contents, $name)));
- } catch (Twig_Error_Syntax $e) {
+ $this->twig->parse($this->twig->tokenize(new \Twig\Source($contents, $name)));
+ } catch (\Twig\Error\SyntaxError $e) {
// ignore templates containing syntax errors
}
}
diff --git a/test/Twig/Tests/Cache/FilesystemTest.php b/test/Twig/Tests/Cache/FilesystemTest.php
index 806143eeb2..9657a1adb9 100644
--- a/test/Twig/Tests/Cache/FilesystemTest.php
+++ b/test/Twig/Tests/Cache/FilesystemTest.php
@@ -22,7 +22,7 @@ protected function setUp()
$nonce = hash('sha256', uniqid(mt_rand(), true));
$this->classname = '__Twig_Tests_Cache_FilesystemTest_Template_'.$nonce;
$this->directory = sys_get_temp_dir().'/twig-test';
- $this->cache = new Twig_Cache_Filesystem($this->directory);
+ $this->cache = new \Twig\Cache\FilesystemCache($this->directory);
}
protected function tearDown()
@@ -166,7 +166,7 @@ public function testGetTimestampMissingFile()
*/
public function testGenerateKey($expected, $input)
{
- $cache = new Twig_Cache_Filesystem($input);
+ $cache = new \Twig\Cache\FilesystemCache($input);
$this->assertRegExp($expected, $cache->generateKey('_test_', \get_class($this)));
}
diff --git a/test/Twig/Tests/CompilerTest.php b/test/Twig/Tests/CompilerTest.php
index 62f2c36c8c..f02a0ce06a 100644
--- a/test/Twig/Tests/CompilerTest.php
+++ b/test/Twig/Tests/CompilerTest.php
@@ -13,7 +13,7 @@ class Twig_Tests_CompilerTest extends \PHPUnit\Framework\TestCase
{
public function testReprNumericValueWithLocale()
{
- $compiler = new Twig_Compiler(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new \Twig\Compiler(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
$locale = setlocale(LC_NUMERIC, 0);
if (false === $locale) {
diff --git a/test/Twig/Tests/ContainerRuntimeLoaderTest.php b/test/Twig/Tests/ContainerRuntimeLoaderTest.php
index 73f1ba6bba..3eefcfb9af 100644
--- a/test/Twig/Tests/ContainerRuntimeLoaderTest.php
+++ b/test/Twig/Tests/ContainerRuntimeLoaderTest.php
@@ -20,7 +20,7 @@ public function testLoad()
$container->expects($this->once())->method('has')->with('stdClass')->willReturn(true);
$container->expects($this->once())->method('get')->with('stdClass')->willReturn(new \stdClass());
- $loader = new Twig_ContainerRuntimeLoader($container);
+ $loader = new \Twig\RuntimeLoader\ContainerRuntimeLoader($container);
$this->assertInstanceOf('stdClass', $loader->load('stdClass'));
}
@@ -34,7 +34,7 @@ public function testLoadUnknownRuntimeReturnsNull()
$container->expects($this->once())->method('has')->with('Foo');
$container->expects($this->never())->method('get');
- $loader = new Twig_ContainerRuntimeLoader($container);
+ $loader = new \Twig\RuntimeLoader\ContainerRuntimeLoader($container);
$this->assertNull($loader->load('Foo'));
}
}
diff --git a/test/Twig/Tests/CustomExtensionTest.php b/test/Twig/Tests/CustomExtensionTest.php
index 6dd959dd84..40dc3fe9ec 100644
--- a/test/Twig/Tests/CustomExtensionTest.php
+++ b/test/Twig/Tests/CustomExtensionTest.php
@@ -15,7 +15,7 @@ class CustomExtensionTest extends \PHPUnit\Framework\TestCase
* @requires PHP 5.3
* @dataProvider provideInvalidExtensions
*/
- public function testGetInvalidOperators(Twig_ExtensionInterface $extension, $expectedExceptionMessage)
+ public function testGetInvalidOperators(\Twig\Extension\ExtensionInterface $extension, $expectedExceptionMessage)
{
if (method_exists($this, 'expectException')) {
$this->expectException('InvalidArgumentException');
@@ -24,7 +24,7 @@ public function testGetInvalidOperators(Twig_ExtensionInterface $extension, $exp
$this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
}
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$env->addExtension($extension);
$env->getUnaryOperators();
}
@@ -38,7 +38,7 @@ public function provideInvalidExtensions()
}
}
-class InvalidOperatorExtension implements Twig_ExtensionInterface
+class InvalidOperatorExtension implements \Twig\Extension\ExtensionInterface
{
private $operators;
@@ -47,7 +47,7 @@ public function __construct($operators)
$this->operators = $operators;
}
- public function initRuntime(Twig_Environment $environment)
+ public function initRuntime(\Twig\Environment $environment)
{
}
diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php
index 8c177755b4..78f2268383 100644
--- a/test/Twig/Tests/EnvironmentTest.php
+++ b/test/Twig/Tests/EnvironmentTest.php
@@ -20,7 +20,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase
*/
public function testLegacyTokenizeSignature()
{
- $env = new Twig_Environment();
+ $env = new \Twig\Environment();
$stream = $env->tokenize('{{ foo }}', 'foo');
$this->assertEquals('{{ foo }}', $stream->getSource());
$this->assertEquals('foo', $stream->getFilename());
@@ -31,8 +31,8 @@ public function testLegacyTokenizeSignature()
*/
public function testLegacyCompileSourceSignature()
{
- $loader = new Twig_Loader_Array(['foo' => '{{ foo }}']);
- $env = new Twig_Environment($loader);
+ $loader = new \Twig\Loader\ArrayLoader(['foo' => '{{ foo }}']);
+ $env = new \Twig\Environment($loader);
$this->assertContains('getTemplateName', $env->compileSource('{{ foo }}', 'foo'));
}
@@ -43,18 +43,18 @@ public function testLegacyCompileSourceSignature()
*/
public function testRenderNoLoader()
{
- $env = new Twig_Environment();
+ $env = new \Twig\Environment();
$env->render('test');
}
public function testAutoescapeOption()
{
- $loader = new Twig_Loader_Array([
+ $loader = new \Twig\Loader\ArrayLoader([
'html' => '{{ foo }} {{ foo }}',
'js' => '{{ bar }} {{ bar }}',
]);
- $twig = new Twig_Environment($loader, [
+ $twig = new \Twig\Environment($loader, [
'debug' => true,
'cache' => false,
'autoescape' => [$this, 'escapingStrategyCallback'],
@@ -73,12 +73,12 @@ public function testGlobals()
{
// to be removed in 2.0
$loader = $this->getMockBuilder('Twig_EnvironmentTestLoaderInterface')->getMock();
- //$loader = $this->getMockBuilder(['Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'])->getMock();
- $loader->expects($this->any())->method('getSourceContext')->will($this->returnValue(new Twig_Source('', '')));
+ //$loader = $this->getMockBuilder(['\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface'])->getMock();
+ $loader->expects($this->any())->method('getSourceContext')->will($this->returnValue(new \Twig\Source('', '')));
// globals can be added after calling getGlobals
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->addGlobal('foo', 'bar');
@@ -86,7 +86,7 @@ public function testGlobals()
$this->assertEquals('bar', $globals['foo']);
// globals can be modified after a template has been loaded
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->loadTemplate('index');
@@ -95,7 +95,7 @@ public function testGlobals()
$this->assertEquals('bar', $globals['foo']);
// globals can be modified after extensions init
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->getFunctions();
@@ -104,8 +104,8 @@ public function testGlobals()
$this->assertEquals('bar', $globals['foo']);
// globals can be modified after extensions and a template has been loaded
- $arrayLoader = new Twig_Loader_Array(['index' => '{{foo}}']);
- $twig = new Twig_Environment($arrayLoader);
+ $arrayLoader = new \Twig\Loader\ArrayLoader(['index' => '{{foo}}']);
+ $twig = new \Twig\Environment($arrayLoader);
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->getFunctions();
@@ -114,7 +114,7 @@ public function testGlobals()
$globals = $twig->getGlobals();
$this->assertEquals('bar', $globals['foo']);
- $twig = new Twig_Environment($arrayLoader);
+ $twig = new \Twig\Environment($arrayLoader);
$twig->getGlobals();
$twig->addGlobal('foo', 'bar');
$template = $twig->loadTemplate('index');
@@ -122,7 +122,7 @@ public function testGlobals()
/* to be uncomment in Twig 2.0
// globals cannot be added after a template has been loaded
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->loadTemplate('index');
@@ -134,7 +134,7 @@ public function testGlobals()
}
// globals cannot be added after extensions init
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->getFunctions();
@@ -146,7 +146,7 @@ public function testGlobals()
}
// globals cannot be added after extensions and a template has been loaded
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->getFunctions();
@@ -159,7 +159,7 @@ public function testGlobals()
}
// test adding globals after a template has been loaded without call to getGlobals
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$twig->loadTemplate('index');
try {
$twig->addGlobal('bar', 'bar');
@@ -172,18 +172,18 @@ public function testGlobals()
public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()
{
- $cache = new Twig_Cache_Filesystem($dir = sys_get_temp_dir().'/twig');
+ $cache = new \Twig\Cache\FilesystemCache($dir = sys_get_temp_dir().'/twig');
$options = ['cache' => $cache, 'auto_reload' => false, 'debug' => false];
// force compilation
- $twig = new Twig_Environment($loader = new Twig_Loader_Array(['index' => '{{ foo }}']), $options);
+ $twig = new \Twig\Environment($loader = new \Twig\Loader\ArrayLoader(['index' => '{{ foo }}']), $options);
$key = $cache->generateKey('index', $twig->getTemplateClass('index'));
- $cache->write($key, $twig->compileSource(new Twig_Source('{{ foo }}', 'index')));
+ $cache->write($key, $twig->compileSource(new \Twig\Source('{{ foo }}', 'index')));
// check that extensions won't be initialized when rendering a template that is already in the cache
$twig = $this
- ->getMockBuilder('Twig_Environment')
+ ->getMockBuilder('\Twig\Environment')
->setConstructorArgs([$loader, $options])
->setMethods(['initExtensions'])
->getMock()
@@ -203,9 +203,9 @@ public function testAutoReloadCacheMiss()
$templateName = __FUNCTION__;
$templateContent = __FUNCTION__;
- $cache = $this->getMockBuilder('Twig_CacheInterface')->getMock();
+ $cache = $this->getMockBuilder('\Twig\Cache\CacheInterface')->getMock();
$loader = $this->getMockLoader($templateName, $templateContent);
- $twig = new Twig_Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]);
+ $twig = new \Twig\Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]);
// Cache miss: getTimestamp returns 0 and as a result the load() is
// skipped.
@@ -230,9 +230,9 @@ public function testAutoReloadCacheHit()
$templateName = __FUNCTION__;
$templateContent = __FUNCTION__;
- $cache = $this->getMockBuilder('Twig_CacheInterface')->getMock();
+ $cache = $this->getMockBuilder('\Twig\Cache\CacheInterface')->getMock();
$loader = $this->getMockLoader($templateName, $templateContent);
- $twig = new Twig_Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]);
+ $twig = new \Twig\Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]);
$now = time();
@@ -258,9 +258,9 @@ public function testAutoReloadOutdatedCacheHit()
$templateName = __FUNCTION__;
$templateContent = __FUNCTION__;
- $cache = $this->getMockBuilder('Twig_CacheInterface')->getMock();
+ $cache = $this->getMockBuilder('\Twig\Cache\CacheInterface')->getMock();
$loader = $this->getMockLoader($templateName, $templateContent);
- $twig = new Twig_Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]);
+ $twig = new \Twig\Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]);
$now = time();
@@ -286,7 +286,7 @@ public function testAutoReloadOutdatedCacheHit()
*/
public function testHasGetExtensionWithDynamicName()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$ext1 = new Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName('ext1');
$ext2 = new Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName('ext2');
@@ -304,7 +304,7 @@ public function testHasGetExtensionWithDynamicName()
public function testHasGetExtensionByClassName()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$twig->addExtension($ext = new Twig_Tests_EnvironmentTest_Extension());
$this->assertTrue($twig->hasExtension('Twig_Tests_EnvironmentTest_Extension'));
$this->assertTrue($twig->hasExtension('\Twig_Tests_EnvironmentTest_Extension'));
@@ -318,7 +318,7 @@ public function testHasGetExtensionByClassName()
public function testAddExtension()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension());
$this->assertArrayHasKey('test', $twig->getTags());
@@ -343,7 +343,7 @@ public function testAddExtension()
*/
public function testAddExtensionWithDeprecatedGetGlobals()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithGlobals());
$this->deprecations = [];
@@ -362,7 +362,7 @@ public function testAddExtensionWithDeprecatedGetGlobals()
*/
public function testRemoveExtension()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName());
$twig->removeExtension('environment_test');
@@ -379,27 +379,27 @@ public function testRemoveExtension()
public function testAddMockExtension()
{
// should be replaced by the following in 2.0 (this current code is just to avoid a dep notice)
- // $extension = $this->getMockBuilder('Twig_Extension')->getMock();
+ // $extension = $this->getMockBuilder('\Twig\Extension\AbstractExtension')->getMock();
$extension = eval(<< 'hey']);
+ $loader = new \Twig\Loader\ArrayLoader(['page' => 'hey']);
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$twig->addExtension($extension);
- $this->assertInstanceOf('Twig_ExtensionInterface', $twig->getExtension(\get_class($extension)));
+ $this->assertInstanceOf('\Twig\Extension\ExtensionInterface', $twig->getExtension(\get_class($extension)));
$this->assertTrue($twig->isTemplateFresh('page', time()));
}
public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime());
$twig->initRuntime();
@@ -413,7 +413,7 @@ public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation()
*/
public function testInitRuntimeWithAnExtensionUsingInitRuntimeDeprecation()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime());
$this->deprecations = [];
@@ -439,7 +439,7 @@ public function handleError($type, $msg)
*/
public function testOverrideExtension()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime());
$this->deprecations = [];
@@ -456,10 +456,10 @@ public function testOverrideExtension()
public function testAddRuntimeLoader()
{
- $runtimeLoader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
+ $runtimeLoader = $this->getMockBuilder('\Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock();
$runtimeLoader->expects($this->any())->method('load')->will($this->returnValue(new Twig_Tests_EnvironmentTest_Runtime()));
- $loader = new Twig_Loader_Array([
+ $loader = new \Twig\Loader\ArrayLoader([
'func_array' => '{{ from_runtime_array("foo") }}',
'func_array_default' => '{{ from_runtime_array() }}',
'func_array_named_args' => '{{ from_runtime_array(name="foo") }}',
@@ -468,7 +468,7 @@ public function testAddRuntimeLoader()
'func_string_named_args' => '{{ from_runtime_string(name="foo") }}',
]);
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime());
$twig->addRuntimeLoader($runtimeLoader);
@@ -481,12 +481,12 @@ public function testAddRuntimeLoader()
}
/**
- * @expectedException \Twig_Error_Runtime
+ * @expectedException \Twig\Error\RuntimeError
* @expectedExceptionMessage Circular reference detected for Twig template "base.html.twig", path: base.html.twig -> base.html.twig in "base.html.twig" at line 1
*/
public function testFailLoadTemplateOnCircularReference()
{
- $twig = new Twig_Environment(new Twig_Loader_Array([
+ $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([
'base.html.twig' => '{% extends "base.html.twig" %}',
]));
@@ -494,12 +494,12 @@ public function testFailLoadTemplateOnCircularReference()
}
/**
- * @expectedException \Twig_Error_Runtime
+ * @expectedException \Twig\Error\RuntimeError
* @expectedExceptionMessage Circular reference detected for Twig template "base1.html.twig", path: base1.html.twig -> base2.html.twig -> base1.html.twig in "base1.html.twig" at line 1
*/
public function testFailLoadTemplateOnComplexCircularReference()
{
- $twig = new Twig_Environment(new Twig_Loader_Array([
+ $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([
'base1.html.twig' => '{% extends "base2.html.twig" %}',
'base2.html.twig' => '{% extends "base1.html.twig" %}',
]));
@@ -511,11 +511,11 @@ protected function getMockLoader($templateName, $templateContent)
{
// to be removed in 2.0
$loader = $this->getMockBuilder('Twig_EnvironmentTestLoaderInterface')->getMock();
- //$loader = $this->getMockBuilder(['Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'])->getMock();
+ //$loader = $this->getMockBuilder(['\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface'])->getMock();
$loader->expects($this->any())
->method('getSourceContext')
->with($templateName)
- ->will($this->returnValue(new Twig_Source($templateContent, $templateName)));
+ ->will($this->returnValue(new \Twig\Source($templateContent, $templateName)));
$loader->expects($this->any())
->method('getCacheKey')
->with($templateName)
@@ -525,7 +525,7 @@ protected function getMockLoader($templateName, $templateContent)
}
}
-class Twig_Tests_EnvironmentTest_Extension_WithGlobals extends Twig_Extension
+class Twig_Tests_EnvironmentTest_Extension_WithGlobals extends \Twig\Extension\AbstractExtension
{
public function getGlobals()
{
@@ -535,7 +535,7 @@ public function getGlobals()
}
}
-class Twig_Tests_EnvironmentTest_Extension extends Twig_Extension implements Twig_Extension_GlobalsInterface
+class Twig_Tests_EnvironmentTest_Extension extends \Twig\Extension\AbstractExtension implements \Twig\Extension\GlobalsInterface
{
public function getTokenParsers()
{
@@ -554,21 +554,21 @@ public function getNodeVisitors()
public function getFilters()
{
return [
- new Twig_SimpleFilter('foo_filter', 'foo_filter'),
+ new \Twig\TwigFilter('foo_filter', 'foo_filter'),
];
}
public function getTests()
{
return [
- new Twig_SimpleTest('foo_test', 'foo_test'),
+ new \Twig\TwigTest('foo_test', 'foo_test'),
];
}
public function getFunctions()
{
return [
- new Twig_SimpleFunction('foo_function', 'foo_function'),
+ new \Twig\TwigFunction('foo_function', 'foo_function'),
];
}
@@ -589,7 +589,7 @@ public function getGlobals()
}
class_alias('Twig_Tests_EnvironmentTest_Extension', 'Twig\Tests\EnvironmentTest\Extension', false);
-class Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName extends Twig_Extension
+class Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName extends \Twig\Extension\AbstractExtension
{
public function getName()
{
@@ -597,7 +597,7 @@ public function getName()
}
}
-class Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName extends Twig_Extension
+class Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName extends \Twig\Extension\AbstractExtension
{
private $name;
@@ -612,9 +612,9 @@ public function getName()
}
}
-class Twig_Tests_EnvironmentTest_TokenParser extends Twig_TokenParser
+class Twig_Tests_EnvironmentTest_TokenParser extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
}
@@ -624,14 +624,14 @@ public function getTag()
}
}
-class Twig_Tests_EnvironmentTest_NodeVisitor implements Twig_NodeVisitorInterface
+class Twig_Tests_EnvironmentTest_NodeVisitor implements \Twig\NodeVisitor\NodeVisitorInterface
{
- public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
+ public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env)
{
return $node;
}
- public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
+ public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env)
{
return $node;
}
@@ -642,27 +642,27 @@ public function getPriority()
}
}
-class Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime extends Twig_Extension
+class Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime extends \Twig\Extension\AbstractExtension
{
- public function initRuntime(Twig_Environment $env)
+ public function initRuntime(\Twig\Environment $env)
{
}
}
-class Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime extends Twig_Extension implements Twig_Extension_InitRuntimeInterface
+class Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime extends \Twig\Extension\AbstractExtension implements \Twig\Extension\InitRuntimeInterface
{
- public function initRuntime(Twig_Environment $env)
+ public function initRuntime(\Twig\Environment $env)
{
}
}
-class Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime extends Twig_Extension
+class Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime extends \Twig\Extension\AbstractExtension
{
public function getFunctions()
{
return [
- new Twig_SimpleFunction('from_runtime_array', ['Twig_Tests_EnvironmentTest_Runtime', 'fromRuntime']),
- new Twig_SimpleFunction('from_runtime_string', 'Twig_Tests_EnvironmentTest_Runtime::fromRuntime'),
+ new \Twig\TwigFunction('from_runtime_array', ['Twig_Tests_EnvironmentTest_Runtime', 'fromRuntime']),
+ new \Twig\TwigFunction('from_runtime_string', 'Twig_Tests_EnvironmentTest_Runtime::fromRuntime'),
];
}
@@ -681,6 +681,6 @@ public function fromRuntime($name = 'bar')
}
// to be removed in 2.0
-interface Twig_EnvironmentTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface
+interface Twig_EnvironmentTestLoaderInterface extends \Twig\Loader\LoaderInterface, Twig_SourceContextLoaderInterface
{
}
diff --git a/test/Twig/Tests/ErrorTest.php b/test/Twig/Tests/ErrorTest.php
index 3b39ace64e..2337e2399e 100644
--- a/test/Twig/Tests/ErrorTest.php
+++ b/test/Twig/Tests/ErrorTest.php
@@ -13,23 +13,23 @@ class Twig_Tests_ErrorTest extends \PHPUnit\Framework\TestCase
{
public function testErrorWithObjectFilename()
{
- $error = new Twig_Error('foo');
- $error->setSourceContext(new Twig_Source('', new \SplFileInfo(__FILE__)));
+ $error = new \Twig\Error\Error('foo');
+ $error->setSourceContext(new \Twig\Source('', new \SplFileInfo(__FILE__)));
$this->assertContains('test'.DIRECTORY_SEPARATOR.'Twig'.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage());
}
public function testErrorWithArrayFilename()
{
- $error = new Twig_Error('foo');
- $error->setSourceContext(new Twig_Source('', ['foo' => 'bar']));
+ $error = new \Twig\Error\Error('foo');
+ $error->setSourceContext(new \Twig\Source('', ['foo' => 'bar']));
$this->assertEquals('foo in {"foo":"bar"}', $error->getMessage());
}
public function testTwigExceptionGuessWithMissingVarAndArrayLoader()
{
- $loader = new Twig_Loader_Array([
+ $loader = new \Twig\Loader\ArrayLoader([
'base.html' => '{% block content %}{% endblock %}',
'index.html' => << true, 'debug' => true, 'cache' => false]);
+ $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index.html');
try {
$template->render([]);
$this->fail();
- } catch (Twig_Error_Runtime $e) {
+ } catch (\Twig\Error\RuntimeError $e) {
$this->assertEquals('Variable "foo" does not exist in "index.html" at line 3.', $e->getMessage());
$this->assertEquals(3, $e->getTemplateLine());
$this->assertEquals('index.html', $e->getSourceContext()->getName());
@@ -57,7 +57,7 @@ public function testTwigExceptionGuessWithMissingVarAndArrayLoader()
public function testTwigExceptionGuessWithExceptionAndArrayLoader()
{
- $loader = new Twig_Loader_Array([
+ $loader = new \Twig\Loader\ArrayLoader([
'base.html' => '{% block content %}{% endblock %}',
'index.html' => << true, 'debug' => true, 'cache' => false]);
+ $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index.html');
try {
$template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]);
$this->fail();
- } catch (Twig_Error_Runtime $e) {
+ } catch (\Twig\Error\RuntimeError $e) {
$this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3.', $e->getMessage());
$this->assertEquals(3, $e->getTemplateLine());
$this->assertEquals('index.html', $e->getSourceContext()->getName());
@@ -85,15 +85,15 @@ public function testTwigExceptionGuessWithExceptionAndArrayLoader()
public function testTwigExceptionGuessWithMissingVarAndFilesystemLoader()
{
- $loader = new Twig_Loader_Filesystem(__DIR__.'/Fixtures/errors');
- $twig = new Twig_Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
+ $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Fixtures/errors');
+ $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index.html');
try {
$template->render([]);
$this->fail();
- } catch (Twig_Error_Runtime $e) {
+ } catch (\Twig\Error\RuntimeError $e) {
$this->assertEquals('Variable "foo" does not exist.', $e->getMessage());
$this->assertEquals(3, $e->getTemplateLine());
$this->assertEquals('index.html', $e->getSourceContext()->getName());
@@ -104,15 +104,15 @@ public function testTwigExceptionGuessWithMissingVarAndFilesystemLoader()
public function testTwigExceptionGuessWithExceptionAndFilesystemLoader()
{
- $loader = new Twig_Loader_Filesystem(__DIR__.'/Fixtures/errors');
- $twig = new Twig_Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
+ $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Fixtures/errors');
+ $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index.html');
try {
$template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]);
$this->fail();
- } catch (Twig_Error_Runtime $e) {
+ } catch (\Twig\Error\RuntimeError $e) {
$this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...").', $e->getMessage());
$this->assertEquals(3, $e->getTemplateLine());
$this->assertEquals('index.html', $e->getSourceContext()->getName());
@@ -126,8 +126,8 @@ public function testTwigExceptionGuessWithExceptionAndFilesystemLoader()
*/
public function testTwigExceptionAddsFileAndLine($templates, $name, $line)
{
- $loader = new Twig_Loader_Array($templates);
- $twig = new Twig_Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
+ $loader = new \Twig\Loader\ArrayLoader($templates);
+ $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index');
@@ -135,7 +135,7 @@ public function testTwigExceptionAddsFileAndLine($templates, $name, $line)
$template->render([]);
$this->fail();
- } catch (Twig_Error_Runtime $e) {
+ } catch (\Twig\Error\RuntimeError $e) {
$this->assertEquals(sprintf('Variable "foo" does not exist in "%s" at line %d.', $name, $line), $e->getMessage());
$this->assertEquals($line, $e->getTemplateLine());
$this->assertEquals($name, $e->getSourceContext()->getName());
@@ -145,7 +145,7 @@ public function testTwigExceptionAddsFileAndLine($templates, $name, $line)
$template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]);
$this->fail();
- } catch (Twig_Error_Runtime $e) {
+ } catch (\Twig\Error\RuntimeError $e) {
$this->assertEquals(sprintf('An exception has been thrown during the rendering of a template ("Runtime error...") in "%s" at line %d.', $name, $line), $e->getMessage());
$this->assertEquals($line, $e->getTemplateLine());
$this->assertEquals($name, $e->getSourceContext()->getName());
diff --git a/test/Twig/Tests/ExpressionParserTest.php b/test/Twig/Tests/ExpressionParserTest.php
index 64a47f24a0..6982c66bf8 100644
--- a/test/Twig/Tests/ExpressionParserTest.php
+++ b/test/Twig/Tests/ExpressionParserTest.php
@@ -12,15 +12,15 @@
class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase
{
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @dataProvider getFailingTestsForAssignment
*/
public function testCanOnlyAssignToNames($template)
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source($template, 'index')));
}
public function getFailingTestsForAssignment()
@@ -46,23 +46,23 @@ public function getFailingTestsForAssignment()
*/
public function testArrayExpression($template, $expected)
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $stream = $env->tokenize(new Twig_Source($template, ''));
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $stream = $env->tokenize(new \Twig\Source($template, ''));
+ $parser = new \Twig\Parser($env);
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @dataProvider getFailingTestsForArray
*/
public function testArraySyntaxError($template)
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source($template, 'index')));
}
public function getFailingTestsForArray()
@@ -77,86 +77,86 @@ public function getTestsForArray()
{
return [
// simple array
- ['{{ [1, 2] }}', new Twig_Node_Expression_Array([
- new Twig_Node_Expression_Constant(0, 1),
- new Twig_Node_Expression_Constant(1, 1),
+ ['{{ [1, 2] }}', new \Twig\Node\Expression\ArrayExpression([
+ new \Twig\Node\Expression\ConstantExpression(0, 1),
+ new \Twig\Node\Expression\ConstantExpression(1, 1),
- new Twig_Node_Expression_Constant(1, 1),
- new Twig_Node_Expression_Constant(2, 1),
+ new \Twig\Node\Expression\ConstantExpression(1, 1),
+ new \Twig\Node\Expression\ConstantExpression(2, 1),
], 1),
],
// array with trailing ,
- ['{{ [1, 2, ] }}', new Twig_Node_Expression_Array([
- new Twig_Node_Expression_Constant(0, 1),
- new Twig_Node_Expression_Constant(1, 1),
+ ['{{ [1, 2, ] }}', new \Twig\Node\Expression\ArrayExpression([
+ new \Twig\Node\Expression\ConstantExpression(0, 1),
+ new \Twig\Node\Expression\ConstantExpression(1, 1),
- new Twig_Node_Expression_Constant(1, 1),
- new Twig_Node_Expression_Constant(2, 1),
+ new \Twig\Node\Expression\ConstantExpression(1, 1),
+ new \Twig\Node\Expression\ConstantExpression(2, 1),
], 1),
],
// simple hash
- ['{{ {"a": "b", "b": "c"} }}', new Twig_Node_Expression_Array([
- new Twig_Node_Expression_Constant('a', 1),
- new Twig_Node_Expression_Constant('b', 1),
+ ['{{ {"a": "b", "b": "c"} }}', new \Twig\Node\Expression\ArrayExpression([
+ new \Twig\Node\Expression\ConstantExpression('a', 1),
+ new \Twig\Node\Expression\ConstantExpression('b', 1),
- new Twig_Node_Expression_Constant('b', 1),
- new Twig_Node_Expression_Constant('c', 1),
+ new \Twig\Node\Expression\ConstantExpression('b', 1),
+ new \Twig\Node\Expression\ConstantExpression('c', 1),
], 1),
],
// hash with trailing ,
- ['{{ {"a": "b", "b": "c", } }}', new Twig_Node_Expression_Array([
- new Twig_Node_Expression_Constant('a', 1),
- new Twig_Node_Expression_Constant('b', 1),
+ ['{{ {"a": "b", "b": "c", } }}', new \Twig\Node\Expression\ArrayExpression([
+ new \Twig\Node\Expression\ConstantExpression('a', 1),
+ new \Twig\Node\Expression\ConstantExpression('b', 1),
- new Twig_Node_Expression_Constant('b', 1),
- new Twig_Node_Expression_Constant('c', 1),
+ new \Twig\Node\Expression\ConstantExpression('b', 1),
+ new \Twig\Node\Expression\ConstantExpression('c', 1),
], 1),
],
// hash in an array
- ['{{ [1, {"a": "b", "b": "c"}] }}', new Twig_Node_Expression_Array([
- new Twig_Node_Expression_Constant(0, 1),
- new Twig_Node_Expression_Constant(1, 1),
+ ['{{ [1, {"a": "b", "b": "c"}] }}', new \Twig\Node\Expression\ArrayExpression([
+ new \Twig\Node\Expression\ConstantExpression(0, 1),
+ new \Twig\Node\Expression\ConstantExpression(1, 1),
- new Twig_Node_Expression_Constant(1, 1),
- new Twig_Node_Expression_Array([
- new Twig_Node_Expression_Constant('a', 1),
- new Twig_Node_Expression_Constant('b', 1),
+ new \Twig\Node\Expression\ConstantExpression(1, 1),
+ new \Twig\Node\Expression\ArrayExpression([
+ new \Twig\Node\Expression\ConstantExpression('a', 1),
+ new \Twig\Node\Expression\ConstantExpression('b', 1),
- new Twig_Node_Expression_Constant('b', 1),
- new Twig_Node_Expression_Constant('c', 1),
+ new \Twig\Node\Expression\ConstantExpression('b', 1),
+ new \Twig\Node\Expression\ConstantExpression('c', 1),
], 1),
], 1),
],
// array in a hash
- ['{{ {"a": [1, 2], "b": "c"} }}', new Twig_Node_Expression_Array([
- new Twig_Node_Expression_Constant('a', 1),
- new Twig_Node_Expression_Array([
- new Twig_Node_Expression_Constant(0, 1),
- new Twig_Node_Expression_Constant(1, 1),
-
- new Twig_Node_Expression_Constant(1, 1),
- new Twig_Node_Expression_Constant(2, 1),
+ ['{{ {"a": [1, 2], "b": "c"} }}', new \Twig\Node\Expression\ArrayExpression([
+ new \Twig\Node\Expression\ConstantExpression('a', 1),
+ new \Twig\Node\Expression\ArrayExpression([
+ new \Twig\Node\Expression\ConstantExpression(0, 1),
+ new \Twig\Node\Expression\ConstantExpression(1, 1),
+
+ new \Twig\Node\Expression\ConstantExpression(1, 1),
+ new \Twig\Node\Expression\ConstantExpression(2, 1),
], 1),
- new Twig_Node_Expression_Constant('b', 1),
- new Twig_Node_Expression_Constant('c', 1),
+ new \Twig\Node\Expression\ConstantExpression('b', 1),
+ new \Twig\Node\Expression\ConstantExpression('c', 1),
], 1),
],
];
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
*/
public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
- $stream = $env->tokenize(new Twig_Source('{{ "a" "b" }}', 'index'));
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
+ $stream = $env->tokenize(new \Twig\Source('{{ "a" "b" }}', 'index'));
+ $parser = new \Twig\Parser($env);
$parser->parse($stream);
}
@@ -166,9 +166,9 @@ public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings()
*/
public function testStringExpression($template, $expected)
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
- $stream = $env->tokenize(new Twig_Source($template, ''));
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
+ $stream = $env->tokenize(new \Twig\Source($template, ''));
+ $parser = new \Twig\Parser($env);
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
}
@@ -177,43 +177,43 @@ public function getTestsForString()
{
return [
[
- '{{ "foo" }}', new Twig_Node_Expression_Constant('foo', 1),
+ '{{ "foo" }}', new \Twig\Node\Expression\ConstantExpression('foo', 1),
],
[
- '{{ "foo #{bar}" }}', new Twig_Node_Expression_Binary_Concat(
- new Twig_Node_Expression_Constant('foo ', 1),
- new Twig_Node_Expression_Name('bar', 1),
+ '{{ "foo #{bar}" }}', new \Twig\Node\Expression\Binary\ConcatBinary(
+ new \Twig\Node\Expression\ConstantExpression('foo ', 1),
+ new \Twig\Node\Expression\NameExpression('bar', 1),
1
),
],
[
- '{{ "foo #{bar} baz" }}', new Twig_Node_Expression_Binary_Concat(
- new Twig_Node_Expression_Binary_Concat(
- new Twig_Node_Expression_Constant('foo ', 1),
- new Twig_Node_Expression_Name('bar', 1),
+ '{{ "foo #{bar} baz" }}', new \Twig\Node\Expression\Binary\ConcatBinary(
+ new \Twig\Node\Expression\Binary\ConcatBinary(
+ new \Twig\Node\Expression\ConstantExpression('foo ', 1),
+ new \Twig\Node\Expression\NameExpression('bar', 1),
1
),
- new Twig_Node_Expression_Constant(' baz', 1),
+ new \Twig\Node\Expression\ConstantExpression(' baz', 1),
1
),
],
[
- '{{ "foo #{"foo #{bar} baz"} baz" }}', new Twig_Node_Expression_Binary_Concat(
- new Twig_Node_Expression_Binary_Concat(
- new Twig_Node_Expression_Constant('foo ', 1),
- new Twig_Node_Expression_Binary_Concat(
- new Twig_Node_Expression_Binary_Concat(
- new Twig_Node_Expression_Constant('foo ', 1),
- new Twig_Node_Expression_Name('bar', 1),
+ '{{ "foo #{"foo #{bar} baz"} baz" }}', new \Twig\Node\Expression\Binary\ConcatBinary(
+ new \Twig\Node\Expression\Binary\ConcatBinary(
+ new \Twig\Node\Expression\ConstantExpression('foo ', 1),
+ new \Twig\Node\Expression\Binary\ConcatBinary(
+ new \Twig\Node\Expression\Binary\ConcatBinary(
+ new \Twig\Node\Expression\ConstantExpression('foo ', 1),
+ new \Twig\Node\Expression\NameExpression('bar', 1),
1
),
- new Twig_Node_Expression_Constant(' baz', 1),
+ new \Twig\Node\Expression\ConstantExpression(' baz', 1),
1
),
1
),
- new Twig_Node_Expression_Constant(' baz', 1),
+ new \Twig\Node\Expression\ConstantExpression(' baz', 1),
1
),
],
@@ -221,50 +221,50 @@ public function getTestsForString()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
*/
public function testAttributeCallDoesNotSupportNamedArguments()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source('{{ foo.bar(name="Foo") }}', 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source('{{ foo.bar(name="Foo") }}', 'index')));
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
*/
public function testMacroCallDoesNotSupportNamedArguments()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index')));
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage An argument must be a name. Unexpected token "string" of value "a" ("name" expected) in "index" at line 1.
*/
public function testMacroDefinitionDoesNotSupportNonNameVariableName()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source('{% macro foo("a") %}{% endmacro %}', 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source('{% macro foo("a") %}{% endmacro %}', 'index')));
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage A default value for an argument must be a constant (a boolean, a string, a number, or an array) in "index" at line 1
* @dataProvider getMacroDefinitionDoesNotSupportNonConstantDefaultValues
*/
public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template)
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source($template, 'index')));
}
public function getMacroDefinitionDoesNotSupportNonConstantDefaultValues()
@@ -280,10 +280,10 @@ public function getMacroDefinitionDoesNotSupportNonConstantDefaultValues()
*/
public function testMacroDefinitionSupportsConstantDefaultValues($template)
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source($template, 'index')));
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -304,74 +304,74 @@ public function getMacroDefinitionSupportsConstantDefaultValues()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown "cycl" function. Did you mean "cycle" in "index" at line 1?
*/
public function testUnknownFunction()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source('{{ cycl() }}', 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source('{{ cycl() }}', 'index')));
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown "foobar" function in "index" at line 1.
*/
public function testUnknownFunctionWithoutSuggestions()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source('{{ foobar() }}', 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source('{{ foobar() }}', 'index')));
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown "lowe" filter. Did you mean "lower" in "index" at line 1?
*/
public function testUnknownFilter()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source('{{ 1|lowe }}', 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source('{{ 1|lowe }}', 'index')));
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown "foobar" filter in "index" at line 1.
*/
public function testUnknownFilterWithoutSuggestions()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source('{{ 1|foobar }}', 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source('{{ 1|foobar }}', 'index')));
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown "nul" test. Did you mean "null" in "index" at line 1
*/
public function testUnknownTest()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
- $stream = $env->tokenize(new Twig_Source('{{ 1 is nul }}', 'index'));
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
+ $stream = $env->tokenize(new \Twig\Source('{{ 1 is nul }}', 'index'));
$parser->parse($stream);
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown "foobar" test in "index" at line 1.
*/
public function testUnknownTestWithoutSuggestions()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $parser = new Twig_Parser($env);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $parser = new \Twig\Parser($env);
- $parser->parse($env->tokenize(new Twig_Source('{{ 1 is foobar }}', 'index')));
+ $parser->parse($env->tokenize(new \Twig\Source('{{ 1 is foobar }}', 'index')));
}
}
diff --git a/test/Twig/Tests/Extension/CoreTest.php b/test/Twig/Tests/Extension/CoreTest.php
index 61f29099cc..a8b707b145 100644
--- a/test/Twig/Tests/Extension/CoreTest.php
+++ b/test/Twig/Tests/Extension/CoreTest.php
@@ -16,7 +16,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase
*/
public function testRandomFunction($value, $expectedInArray)
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
for ($i = 0; $i < 100; ++$i) {
$this->assertTrue(\in_array(twig_random($env, $value), $expectedInArray, true)); // assertContains() would not consider the type
@@ -62,26 +62,26 @@ public function testRandomFunctionWithoutParameter()
$max = mt_getrandmax();
for ($i = 0; $i < 100; ++$i) {
- $val = twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $val = twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
$this->assertTrue(\is_int($val) && $val >= 0 && $val <= $max);
}
}
public function testRandomFunctionReturnsAsIs()
{
- $this->assertSame('', twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), ''));
- $this->assertSame('', twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['charset' => null]), ''));
+ $this->assertSame('', twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), ''));
+ $this->assertSame('', twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['charset' => null]), ''));
$instance = new \stdClass();
- $this->assertSame($instance, twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), $instance));
+ $this->assertSame($instance, twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), $instance));
}
/**
- * @expectedException \Twig_Error_Runtime
+ * @expectedException \Twig\Error\RuntimeError
*/
public function testRandomFunctionOfEmptyArrayThrowsException()
{
- twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), []);
+ twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), []);
}
public function testRandomFunctionOnNonUTF8String()
@@ -90,7 +90,7 @@ public function testRandomFunctionOnNonUTF8String()
$this->markTestSkipped('needs iconv or mbstring');
}
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$twig->setCharset('ISO-8859-1');
$text = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8');
@@ -106,7 +106,7 @@ public function testReverseFilterOnNonUTF8String()
$this->markTestSkipped('needs iconv or mbstring');
}
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$twig->setCharset('ISO-8859-1');
$input = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8');
@@ -120,8 +120,8 @@ public function testReverseFilterOnNonUTF8String()
*/
public function testCustomEscaper($expected, $string, $strategy)
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $twig->getExtension('Twig_Extension_Core')->setEscaper('foo', 'foo_escaper_for_test');
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
+ $twig->getExtension('\Twig\Extension\CoreExtension')->setEscaper('foo', 'foo_escaper_for_test');
$this->assertSame($expected, twig_escape_filter($twig, $string, $strategy));
}
@@ -136,11 +136,11 @@ public function provideCustomEscaperCases()
}
/**
- * @expectedException \Twig_Error_Runtime
+ * @expectedException \Twig\Error\RuntimeError
*/
public function testUnknownCustomEscaper()
{
- twig_escape_filter(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), 'foo', 'bar');
+ twig_escape_filter(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), 'foo', 'bar');
}
/**
@@ -148,7 +148,7 @@ public function testUnknownCustomEscaper()
*/
public function testTwigFirst($expected, $input)
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$this->assertSame($expected, twig_first($twig, $input));
}
@@ -170,7 +170,7 @@ public function provideTwigFirstCases()
*/
public function testTwigLast($expected, $input)
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$this->assertSame($expected, twig_last($twig, $input));
}
@@ -243,7 +243,7 @@ public function provideInFilterCases()
*/
public function testSliceFilter($expected, $input, $start, $length = null, $preserveKeys = false)
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$this->assertSame($expected, twig_slice($twig, $input, $start, $length, $preserveKeys));
}
diff --git a/test/Twig/Tests/Extension/SandboxTest.php b/test/Twig/Tests/Extension/SandboxTest.php
index a9177736c6..5e49f9f0ce 100644
--- a/test/Twig/Tests/Extension/SandboxTest.php
+++ b/test/Twig/Tests/Extension/SandboxTest.php
@@ -41,7 +41,7 @@ protected function setUp()
}
/**
- * @expectedException \Twig_Sandbox_SecurityError
+ * @expectedException \Twig\Sandbox\SecurityError
* @expectedExceptionMessage Filter "json_encode" is not allowed in "1_child" at line 3.
*/
public function testSandboxWithInheritance()
@@ -62,8 +62,8 @@ public function testSandboxUnallowedMethodAccessor()
try {
$twig->loadTemplate('1_basic1')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed method is called');
- } catch (Twig_Sandbox_SecurityError $e) {
- $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
+ } catch (\Twig\Sandbox\SecurityError $e) {
+ $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
$this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class');
$this->assertEquals('foo', $e->getMethodName(), 'Exception should be raised on the "foo" method');
}
@@ -75,8 +75,8 @@ public function testSandboxUnallowedFilter()
try {
$twig->loadTemplate('1_basic2')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called');
- } catch (Twig_Sandbox_SecurityError $e) {
- $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
+ } catch (\Twig\Sandbox\SecurityError $e) {
+ $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
$this->assertEquals('upper', $e->getFilterName(), 'Exception should be raised on the "upper" filter');
}
}
@@ -87,8 +87,8 @@ public function testSandboxUnallowedTag()
try {
$twig->loadTemplate('1_basic3')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed tag is used in the template');
- } catch (Twig_Sandbox_SecurityError $e) {
- $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError');
+ } catch (\Twig\Sandbox\SecurityError $e) {
+ $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError');
$this->assertEquals('if', $e->getTagName(), 'Exception should be raised on the "if" tag');
}
}
@@ -99,8 +99,8 @@ public function testSandboxUnallowedProperty()
try {
$twig->loadTemplate('1_basic4')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed property is called in the template');
- } catch (Twig_Sandbox_SecurityError $e) {
- $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedPropertyError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedPropertyError');
+ } catch (\Twig\Sandbox\SecurityError $e) {
+ $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedPropertyError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedPropertyError');
$this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class');
$this->assertEquals('bar', $e->getPropertyName(), 'Exception should be raised on the "bar" property');
}
@@ -112,8 +112,8 @@ public function testSandboxUnallowedToString()
try {
$twig->loadTemplate('1_basic5')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template');
- } catch (Twig_Sandbox_SecurityError $e) {
- $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
+ } catch (\Twig\Sandbox\SecurityError $e) {
+ $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
$this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class');
$this->assertEquals('__tostring', $e->getMethodName(), 'Exception should be raised on the "__toString" method');
}
@@ -125,8 +125,8 @@ public function testSandboxUnallowedToStringArray()
try {
$twig->loadTemplate('1_basic6')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template');
- } catch (Twig_Sandbox_SecurityError $e) {
- $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
+ } catch (\Twig\Sandbox\SecurityError $e) {
+ $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
$this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class');
$this->assertEquals('__tostring', $e->getMethodName(), 'Exception should be raised on the "__toString" method');
}
@@ -138,8 +138,8 @@ public function testSandboxUnallowedFunction()
try {
$twig->loadTemplate('1_basic7')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed function is called in the template');
- } catch (Twig_Sandbox_SecurityError $e) {
- $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError');
+ } catch (\Twig\Sandbox\SecurityError $e) {
+ $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError');
$this->assertEquals('cycle', $e->getFunctionName(), 'Exception should be raised on the "cycle" function');
}
}
@@ -150,8 +150,8 @@ public function testSandboxUnallowedRangeOperator()
try {
$twig->loadTemplate('1_range_operator')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if the unallowed range operator is called');
- } catch (Twig_Sandbox_SecurityError $e) {
- $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError');
+ } catch (\Twig\Sandbox\SecurityError $e) {
+ $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError');
$this->assertEquals('range', $e->getFunctionName(), 'Exception should be raised on the "range" function');
}
}
@@ -241,8 +241,8 @@ public function testSandboxLocallySetForAnInclude()
try {
$twig->loadTemplate('3_basic')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception when the included file is sandboxed');
- } catch (Twig_Sandbox_SecurityError $e) {
- $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError');
+ } catch (\Twig\Sandbox\SecurityError $e) {
+ $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError');
$this->assertEquals('sandbox', $e->getTagName());
}
}
@@ -275,15 +275,15 @@ public function testSandboxDisabledAfterIncludeFunctionError()
$this->fail('An exception should be thrown for this test to be valid.');
}
- $this->assertFalse($twig->getExtension('Twig_Extension_Sandbox')->isSandboxed(), 'Sandboxed include() function call should not leave Sandbox enabled when an error occurs.');
+ $this->assertFalse($twig->getExtension('\Twig\Extension\SandboxExtension')->isSandboxed(), 'Sandboxed include() function call should not leave Sandbox enabled when an error occurs.');
}
protected function getEnvironment($sandboxed, $options, $templates, $tags = [], $filters = [], $methods = [], $properties = [], $functions = [])
{
- $loader = new Twig_Loader_Array($templates);
- $twig = new Twig_Environment($loader, array_merge(['debug' => true, 'cache' => false, 'autoescape' => false], $options));
- $policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions);
- $twig->addExtension(new Twig_Extension_Sandbox($policy, $sandboxed));
+ $loader = new \Twig\Loader\ArrayLoader($templates);
+ $twig = new \Twig\Environment($loader, array_merge(['debug' => true, 'cache' => false, 'autoescape' => false], $options));
+ $policy = new \Twig\Sandbox\SecurityPolicy($tags, $filters, $methods, $properties, $functions);
+ $twig->addExtension(new \Twig\Extension\SandboxExtension($policy, $sandboxed));
return $twig;
}
diff --git a/test/Twig/Tests/FactoryRuntimeLoaderTest.php b/test/Twig/Tests/FactoryRuntimeLoaderTest.php
index 59da9c2adf..59328eeea0 100644
--- a/test/Twig/Tests/FactoryRuntimeLoaderTest.php
+++ b/test/Twig/Tests/FactoryRuntimeLoaderTest.php
@@ -13,14 +13,14 @@ class Twig_Tests_FactoryRuntimeLoaderTest extends \PHPUnit\Framework\TestCase
{
public function testLoad()
{
- $loader = new Twig_FactoryRuntimeLoader(['stdClass' => 'getRuntime']);
+ $loader = new \Twig\RuntimeLoader\FactoryRuntimeLoader(['stdClass' => 'getRuntime']);
$this->assertInstanceOf('stdClass', $loader->load('stdClass'));
}
public function testLoadReturnsNullForUnmappedRuntime()
{
- $loader = new Twig_FactoryRuntimeLoader();
+ $loader = new \Twig\RuntimeLoader\FactoryRuntimeLoader();
$this->assertNull($loader->load('stdClass'));
}
diff --git a/test/Twig/Tests/FileCachingTest.php b/test/Twig/Tests/FileCachingTest.php
index df5344573f..640f13b4af 100644
--- a/test/Twig/Tests/FileCachingTest.php
+++ b/test/Twig/Tests/FileCachingTest.php
@@ -27,7 +27,7 @@ protected function setUp()
$this->markTestSkipped(sprintf('Unable to run the tests as "%s" is not writable.', $this->tmpDir));
}
- $this->env = new Twig_Environment(new Twig_Loader_Array(['index' => 'index', 'index2' => 'index2']), ['cache' => $this->tmpDir]);
+ $this->env = new \Twig\Environment(new \Twig\Loader\ArrayLoader(['index' => 'index', 'index2' => 'index2']), ['cache' => $this->tmpDir]);
}
protected function tearDown()
diff --git a/test/Twig/Tests/FileExtensionEscapingStrategyTest.php b/test/Twig/Tests/FileExtensionEscapingStrategyTest.php
index 6cdff00fac..a6959744be 100644
--- a/test/Twig/Tests/FileExtensionEscapingStrategyTest.php
+++ b/test/Twig/Tests/FileExtensionEscapingStrategyTest.php
@@ -16,7 +16,7 @@ class Twig_Tests_FileExtensionEscapingStrategyTest extends \PHPUnit\Framework\Te
*/
public function testGuess($strategy, $filename)
{
- $this->assertSame($strategy, Twig_FileExtensionEscapingStrategy::guess($filename));
+ $this->assertSame($strategy, \Twig\FileExtensionEscapingStrategy::guess($filename));
}
public function getGuessData()
diff --git a/test/Twig/Tests/Fixtures/filters/date_default_format.test b/test/Twig/Tests/Fixtures/filters/date_default_format.test
index bd27863684..c6e81302df 100644
--- a/test/Twig/Tests/Fixtures/filters/date_default_format.test
+++ b/test/Twig/Tests/Fixtures/filters/date_default_format.test
@@ -5,7 +5,7 @@
{{ date1|date('d/m/Y') }}
--DATA--
date_default_timezone_set('UTC');
-$twig->getExtension('Twig_Extension_Core')->setDateFormat('Y-m-d', '%d days %h hours');
+$twig->getExtension('\Twig\Extension\CoreExtension')->setDateFormat('Y-m-d', '%d days %h hours');
return [
'date1' => mktime(13, 45, 0, 10, 4, 2010),
]
diff --git a/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test b/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test
index 88d663be2e..a72fb81d62 100644
--- a/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test
+++ b/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test
@@ -7,7 +7,7 @@ version_compare(phpversion(), '5.3.0', '>=')
{{ date2|date('%d days') }}
--DATA--
date_default_timezone_set('UTC');
-$twig->getExtension('Twig_Extension_Core')->setDateFormat('Y-m-d', '%d days %h hours');
+$twig->getExtension('\Twig\Extension\CoreExtension')->setDateFormat('Y-m-d', '%d days %h hours');
return [
'date2' => new \DateInterval('P2D'),
]
diff --git a/test/Twig/Tests/Fixtures/filters/json_encode.test b/test/Twig/Tests/Fixtures/filters/json_encode.test
index ea45218f63..902f90b337 100644
--- a/test/Twig/Tests/Fixtures/filters/json_encode.test
+++ b/test/Twig/Tests/Fixtures/filters/json_encode.test
@@ -5,7 +5,7 @@
{{ foo|json_encode|raw }}
{{ [foo, "foo"]|json_encode|raw }}
--DATA--
-return ['foo' => new Twig_Markup('foo', 'UTF-8')]
+return ['foo' => new \Twig\Markup('foo', 'UTF-8')]
--EXPECT--
"foo"
"foo"
diff --git a/test/Twig/Tests/Fixtures/filters/length_utf8.test b/test/Twig/Tests/Fixtures/filters/length_utf8.test
index be2170715b..b1e9681a5d 100644
--- a/test/Twig/Tests/Fixtures/filters/length_utf8.test
+++ b/test/Twig/Tests/Fixtures/filters/length_utf8.test
@@ -6,7 +6,7 @@ function_exists('mb_get_info')
{{ string|length }}
{{ markup|length }}
--DATA--
-return ['string' => 'été', 'markup' => new Twig_Markup('foo', 'UTF-8')]
+return ['string' => 'été', 'markup' => new \Twig\Markup('foo', 'UTF-8')]
--EXPECT--
3
3
diff --git a/test/Twig/Tests/Fixtures/filters/number_format_default.test b/test/Twig/Tests/Fixtures/filters/number_format_default.test
index c550bb6740..beedd901a0 100644
--- a/test/Twig/Tests/Fixtures/filters/number_format_default.test
+++ b/test/Twig/Tests/Fixtures/filters/number_format_default.test
@@ -9,7 +9,7 @@
{{ 1020.25|number_format(2, ',') }}
{{ 1020.25|number_format(2, ',', '.') }}
--DATA--
-$twig->getExtension('Twig_Extension_Core')->setNumberFormat(2, '!', '=');
+$twig->getExtension('\Twig\Extension\CoreExtension')->setNumberFormat(2, '!', '=');
return []
--EXPECT--
20!00
diff --git a/test/Twig/Tests/Fixtures/tests/empty.test b/test/Twig/Tests/Fixtures/tests/empty.test
index f227cda957..3e7fcf0183 100644
--- a/test/Twig/Tests/Fixtures/tests/empty.test
+++ b/test/Twig/Tests/Fixtures/tests/empty.test
@@ -23,7 +23,7 @@ return [
'magically_callable' => new MagicCallStub(),
'countable_empty' => new CountableStub([]), 'countable_not_empty' => new CountableStub([1, 2]),
'tostring_empty' => new ToStringStub(''), 'tostring_not_empty' => new ToStringStub('0' /* edge case of using "0" as the string */),
- 'markup_empty' => new Twig_Markup('', 'UTF-8'), 'markup_not_empty' => new Twig_Markup('test', 'UTF-8'),
+ 'markup_empty' => new \Twig\Markup('', 'UTF-8'), 'markup_not_empty' => new \Twig\Markup('test', 'UTF-8'),
]
--EXPECT--
ok
diff --git a/test/Twig/Tests/IntegrationTest.php b/test/Twig/Tests/IntegrationTest.php
index 9afc0b1b5c..1cef44929b 100644
--- a/test/Twig/Tests/IntegrationTest.php
+++ b/test/Twig/Tests/IntegrationTest.php
@@ -16,16 +16,16 @@ function html()
return 'foo';
}
-class Twig_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase
+class Twig_Tests_IntegrationTest extends \Twig\Test\IntegrationTestCase
{
public function getExtensions()
{
- $policy = new Twig_Sandbox_SecurityPolicy([], [], [], [], []);
+ $policy = new \Twig\Sandbox\SecurityPolicy([], [], [], [], []);
return [
- new Twig_Extension_Debug(),
- new Twig_Extension_Sandbox($policy, false),
- new Twig_Extension_StringLoader(),
+ new \Twig\Extension\DebugExtension(),
+ new \Twig\Extension\SandboxExtension($policy, false),
+ new \Twig\Extension\StringLoaderExtension(),
new TwigTestExtension(),
];
}
@@ -109,13 +109,13 @@ public function valid()
}
}
-class TwigTestTokenParser_§ extends Twig_TokenParser
+class TwigTestTokenParser_§ extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node_Print(new Twig_Node_Expression_Constant('§', -1), -1);
+ return new \Twig\Node\PrintNode(new \Twig\Node\Expression\ConstantExpression('§', -1), -1);
}
public function getTag()
@@ -124,7 +124,7 @@ public function getTag()
}
}
-class TwigTestExtension extends Twig_Extension
+class TwigTestExtension extends \Twig\Extension\AbstractExtension
{
public function getTokenParsers()
{
@@ -136,39 +136,39 @@ public function getTokenParsers()
public function getFilters()
{
return [
- new Twig_SimpleFilter('§', [$this, '§Filter']),
- new Twig_SimpleFilter('escape_and_nl2br', [$this, 'escape_and_nl2br'], ['needs_environment' => true, 'is_safe' => ['html']]),
- new Twig_SimpleFilter('nl2br', [$this, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
- new Twig_SimpleFilter('escape_something', [$this, 'escape_something'], ['is_safe' => ['something']]),
- new Twig_SimpleFilter('preserves_safety', [$this, 'preserves_safety'], ['preserves_safety' => ['html']]),
- new Twig_SimpleFilter('static_call_string', 'TwigTestExtension::staticCall'),
- new Twig_SimpleFilter('static_call_array', ['TwigTestExtension', 'staticCall']),
- new Twig_SimpleFilter('magic_call', [$this, 'magicCall']),
- new Twig_SimpleFilter('magic_call_string', 'TwigTestExtension::magicStaticCall'),
- new Twig_SimpleFilter('magic_call_array', ['TwigTestExtension', 'magicStaticCall']),
- new Twig_SimpleFilter('*_path', [$this, 'dynamic_path']),
- new Twig_SimpleFilter('*_foo_*_bar', [$this, 'dynamic_foo']),
+ new \Twig\TwigFilter('§', [$this, '§Filter']),
+ new \Twig\TwigFilter('escape_and_nl2br', [$this, 'escape_and_nl2br'], ['needs_environment' => true, 'is_safe' => ['html']]),
+ new \Twig\TwigFilter('nl2br', [$this, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
+ new \Twig\TwigFilter('escape_something', [$this, 'escape_something'], ['is_safe' => ['something']]),
+ new \Twig\TwigFilter('preserves_safety', [$this, 'preserves_safety'], ['preserves_safety' => ['html']]),
+ new \Twig\TwigFilter('static_call_string', 'TwigTestExtension::staticCall'),
+ new \Twig\TwigFilter('static_call_array', ['TwigTestExtension', 'staticCall']),
+ new \Twig\TwigFilter('magic_call', [$this, 'magicCall']),
+ new \Twig\TwigFilter('magic_call_string', 'TwigTestExtension::magicStaticCall'),
+ new \Twig\TwigFilter('magic_call_array', ['TwigTestExtension', 'magicStaticCall']),
+ new \Twig\TwigFilter('*_path', [$this, 'dynamic_path']),
+ new \Twig\TwigFilter('*_foo_*_bar', [$this, 'dynamic_foo']),
];
}
public function getFunctions()
{
return [
- new Twig_SimpleFunction('§', [$this, '§Function']),
- new Twig_SimpleFunction('safe_br', [$this, 'br'], ['is_safe' => ['html']]),
- new Twig_SimpleFunction('unsafe_br', [$this, 'br']),
- new Twig_SimpleFunction('static_call_string', 'TwigTestExtension::staticCall'),
- new Twig_SimpleFunction('static_call_array', ['TwigTestExtension', 'staticCall']),
- new Twig_SimpleFunction('*_path', [$this, 'dynamic_path']),
- new Twig_SimpleFunction('*_foo_*_bar', [$this, 'dynamic_foo']),
+ new \Twig\TwigFunction('§', [$this, '§Function']),
+ new \Twig\TwigFunction('safe_br', [$this, 'br'], ['is_safe' => ['html']]),
+ new \Twig\TwigFunction('unsafe_br', [$this, 'br']),
+ new \Twig\TwigFunction('static_call_string', 'TwigTestExtension::staticCall'),
+ new \Twig\TwigFunction('static_call_array', ['TwigTestExtension', 'staticCall']),
+ new \Twig\TwigFunction('*_path', [$this, 'dynamic_path']),
+ new \Twig\TwigFunction('*_foo_*_bar', [$this, 'dynamic_foo']),
];
}
public function getTests()
{
return [
- new Twig_SimpleTest('multi word', [$this, 'is_multi_word']),
- new Twig_SimpleTest('test_*', [$this, 'dynamic_test']),
+ new \Twig\TwigTest('multi word', [$this, 'is_multi_word']),
+ new \Twig\TwigTest('test_*', [$this, 'dynamic_test']),
];
}
diff --git a/test/Twig/Tests/LegacyIntegrationTest.php b/test/Twig/Tests/LegacyIntegrationTest.php
index fce3eac8c7..578609546a 100644
--- a/test/Twig/Tests/LegacyIntegrationTest.php
+++ b/test/Twig/Tests/LegacyIntegrationTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_LegacyIntegrationTest extends Twig_Test_IntegrationTestCase
+class Twig_Tests_LegacyIntegrationTest extends \Twig\Test\IntegrationTestCase
{
public function getExtensions()
{
@@ -33,7 +33,7 @@ public function getTests($name, $legacyTests = false)
}
}
-class LegacyTwigTestExtension extends Twig_Extension
+class LegacyTwigTestExtension extends \Twig\Extension\AbstractExtension
{
public function getTests()
{
diff --git a/test/Twig/Tests/LexerTest.php b/test/Twig/Tests/LexerTest.php
index c7521a7cde..8984c7f341 100644
--- a/test/Twig/Tests/LexerTest.php
+++ b/test/Twig/Tests/LexerTest.php
@@ -15,7 +15,7 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase
*/
public function testLegacyConstructorSignature()
{
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
$stream = $lexer->tokenize('{{ foo }}', 'foo');
$this->assertEquals('foo', $stream->getFilename());
$this->assertEquals('{{ foo }}', $stream->getSource());
@@ -25,36 +25,36 @@ public function testNameLabelForTag()
{
$template = '{% § %}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
- $stream->expect(Twig_Token::BLOCK_START_TYPE);
- $this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue());
+ $stream->expect(\Twig\Token::BLOCK_START_TYPE);
+ $this->assertSame('§', $stream->expect(\Twig\Token::NAME_TYPE)->getValue());
}
public function testNameLabelForFunction()
{
$template = '{{ §() }}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
- $stream->expect(Twig_Token::VAR_START_TYPE);
- $this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue());
+ $stream->expect(\Twig\Token::VAR_START_TYPE);
+ $this->assertSame('§', $stream->expect(\Twig\Token::NAME_TYPE)->getValue());
}
public function testBracketsNesting()
{
$template = '{{ {"a":{"b":"c"}} }}';
- $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '{'));
- $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '}'));
+ $this->assertEquals(2, $this->countToken($template, \Twig\Token::PUNCTUATION_TYPE, '{'));
+ $this->assertEquals(2, $this->countToken($template, \Twig\Token::PUNCTUATION_TYPE, '}'));
}
protected function countToken($template, $type, $value = null)
{
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
$count = 0;
while (!$stream->isEOF()) {
@@ -78,17 +78,17 @@ public function testLineDirective()
."baz\n"
."}}\n";
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
// foo\nbar\n
- $this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine());
+ $this->assertSame(1, $stream->expect(\Twig\Token::TEXT_TYPE)->getLine());
// \n (after {% line %})
- $this->assertSame(10, $stream->expect(Twig_Token::TEXT_TYPE)->getLine());
+ $this->assertSame(10, $stream->expect(\Twig\Token::TEXT_TYPE)->getLine());
// {{
- $this->assertSame(11, $stream->expect(Twig_Token::VAR_START_TYPE)->getLine());
+ $this->assertSame(11, $stream->expect(\Twig\Token::VAR_START_TYPE)->getLine());
// baz
- $this->assertSame(12, $stream->expect(Twig_Token::NAME_TYPE)->getLine());
+ $this->assertSame(12, $stream->expect(\Twig\Token::NAME_TYPE)->getLine());
}
public function testLineDirectiveInline()
@@ -98,23 +98,23 @@ public function testLineDirectiveInline()
."baz\n"
."}}\n";
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
// foo\nbar
- $this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine());
+ $this->assertSame(1, $stream->expect(\Twig\Token::TEXT_TYPE)->getLine());
// {{
- $this->assertSame(10, $stream->expect(Twig_Token::VAR_START_TYPE)->getLine());
+ $this->assertSame(10, $stream->expect(\Twig\Token::VAR_START_TYPE)->getLine());
// baz
- $this->assertSame(11, $stream->expect(Twig_Token::NAME_TYPE)->getLine());
+ $this->assertSame(11, $stream->expect(\Twig\Token::NAME_TYPE)->getLine());
}
public function testLongComments()
{
$template = '{# '.str_repeat('*', 100000).' #}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $lexer->tokenize(new \Twig\Source($template, 'index'));
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -125,8 +125,8 @@ public function testLongVerbatim()
{
$template = '{% verbatim %}'.str_repeat('*', 100000).'{% endverbatim %}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $lexer->tokenize(new \Twig\Source($template, 'index'));
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -137,8 +137,8 @@ public function testLongVar()
{
$template = '{{ '.str_repeat('x', 100000).' }}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $lexer->tokenize(new \Twig\Source($template, 'index'));
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -149,8 +149,8 @@ public function testLongBlock()
{
$template = '{% '.str_repeat('x', 100000).' %}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $lexer->tokenize(new \Twig\Source($template, 'index'));
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -161,8 +161,8 @@ public function testBigNumbers()
{
$template = '{{ 922337203685477580700 }}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
$stream->next();
$node = $stream->next();
$this->assertEquals('922337203685477580700', $node->getValue());
@@ -174,11 +174,11 @@ public function testStringWithEscapedDelimiter()
"{{ 'foo \' bar' }}" => 'foo \' bar',
'{{ "foo \" bar" }}' => 'foo " bar',
];
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
foreach ($tests as $template => $expected) {
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
- $stream->expect(Twig_Token::VAR_START_TYPE);
- $stream->expect(Twig_Token::STRING_TYPE, $expected);
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
+ $stream->expect(\Twig\Token::VAR_START_TYPE);
+ $stream->expect(\Twig\Token::STRING_TYPE, $expected);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -190,17 +190,17 @@ public function testStringWithInterpolation()
{
$template = 'foo {{ "bar #{ baz + 1 }" }}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
- $stream->expect(Twig_Token::TEXT_TYPE, 'foo ');
- $stream->expect(Twig_Token::VAR_START_TYPE);
- $stream->expect(Twig_Token::STRING_TYPE, 'bar ');
- $stream->expect(Twig_Token::INTERPOLATION_START_TYPE);
- $stream->expect(Twig_Token::NAME_TYPE, 'baz');
- $stream->expect(Twig_Token::OPERATOR_TYPE, '+');
- $stream->expect(Twig_Token::NUMBER_TYPE, '1');
- $stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
- $stream->expect(Twig_Token::VAR_END_TYPE);
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
+ $stream->expect(\Twig\Token::TEXT_TYPE, 'foo ');
+ $stream->expect(\Twig\Token::VAR_START_TYPE);
+ $stream->expect(\Twig\Token::STRING_TYPE, 'bar ');
+ $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE);
+ $stream->expect(\Twig\Token::NAME_TYPE, 'baz');
+ $stream->expect(\Twig\Token::OPERATOR_TYPE, '+');
+ $stream->expect(\Twig\Token::NUMBER_TYPE, '1');
+ $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE);
+ $stream->expect(\Twig\Token::VAR_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -211,11 +211,11 @@ public function testStringWithEscapedInterpolation()
{
$template = '{{ "bar \#{baz+1}" }}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
- $stream->expect(Twig_Token::VAR_START_TYPE);
- $stream->expect(Twig_Token::STRING_TYPE, 'bar #{baz+1}');
- $stream->expect(Twig_Token::VAR_END_TYPE);
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
+ $stream->expect(\Twig\Token::VAR_START_TYPE);
+ $stream->expect(\Twig\Token::STRING_TYPE, 'bar #{baz+1}');
+ $stream->expect(\Twig\Token::VAR_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -226,11 +226,11 @@ public function testStringWithHash()
{
$template = '{{ "bar # baz" }}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
- $stream->expect(Twig_Token::VAR_START_TYPE);
- $stream->expect(Twig_Token::STRING_TYPE, 'bar # baz');
- $stream->expect(Twig_Token::VAR_END_TYPE);
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
+ $stream->expect(\Twig\Token::VAR_START_TYPE);
+ $stream->expect(\Twig\Token::STRING_TYPE, 'bar # baz');
+ $stream->expect(\Twig\Token::VAR_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -238,32 +238,32 @@ public function testStringWithHash()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unclosed """
*/
public function testStringWithUnterminatedInterpolation()
{
$template = '{{ "bar #{x" }}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $lexer->tokenize(new \Twig\Source($template, 'index'));
}
public function testStringWithNestedInterpolations()
{
$template = '{{ "bar #{ "foo#{bar}" }" }}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
- $stream->expect(Twig_Token::VAR_START_TYPE);
- $stream->expect(Twig_Token::STRING_TYPE, 'bar ');
- $stream->expect(Twig_Token::INTERPOLATION_START_TYPE);
- $stream->expect(Twig_Token::STRING_TYPE, 'foo');
- $stream->expect(Twig_Token::INTERPOLATION_START_TYPE);
- $stream->expect(Twig_Token::NAME_TYPE, 'bar');
- $stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
- $stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
- $stream->expect(Twig_Token::VAR_END_TYPE);
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
+ $stream->expect(\Twig\Token::VAR_START_TYPE);
+ $stream->expect(\Twig\Token::STRING_TYPE, 'bar ');
+ $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE);
+ $stream->expect(\Twig\Token::STRING_TYPE, 'foo');
+ $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE);
+ $stream->expect(\Twig\Token::NAME_TYPE, 'bar');
+ $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE);
+ $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE);
+ $stream->expect(\Twig\Token::VAR_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -274,18 +274,18 @@ public function testStringWithNestedInterpolationsInBlock()
{
$template = '{% foo "bar #{ "foo#{bar}" }" %}';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
- $stream->expect(Twig_Token::BLOCK_START_TYPE);
- $stream->expect(Twig_Token::NAME_TYPE, 'foo');
- $stream->expect(Twig_Token::STRING_TYPE, 'bar ');
- $stream->expect(Twig_Token::INTERPOLATION_START_TYPE);
- $stream->expect(Twig_Token::STRING_TYPE, 'foo');
- $stream->expect(Twig_Token::INTERPOLATION_START_TYPE);
- $stream->expect(Twig_Token::NAME_TYPE, 'bar');
- $stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
- $stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
+ $stream->expect(\Twig\Token::BLOCK_START_TYPE);
+ $stream->expect(\Twig\Token::NAME_TYPE, 'foo');
+ $stream->expect(\Twig\Token::STRING_TYPE, 'bar ');
+ $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE);
+ $stream->expect(\Twig\Token::STRING_TYPE, 'foo');
+ $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE);
+ $stream->expect(\Twig\Token::NAME_TYPE, 'bar');
+ $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE);
+ $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE);
+ $stream->expect(\Twig\Token::BLOCK_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -296,11 +296,11 @@ public function testOperatorEndingWithALetterAtTheEndOfALine()
{
$template = "{{ 1 and\n0}}";
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
- $stream->expect(Twig_Token::VAR_START_TYPE);
- $stream->expect(Twig_Token::NUMBER_TYPE, 1);
- $stream->expect(Twig_Token::OPERATOR_TYPE, 'and');
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $stream = $lexer->tokenize(new \Twig\Source($template, 'index'));
+ $stream->expect(\Twig\Token::VAR_START_TYPE);
+ $stream->expect(\Twig\Token::NUMBER_TYPE, 1);
+ $stream->expect(\Twig\Token::OPERATOR_TYPE, 'and');
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
@@ -308,7 +308,7 @@ public function testOperatorEndingWithALetterAtTheEndOfALine()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unclosed "variable" in "index" at line 3
*/
public function testUnterminatedVariable()
@@ -322,12 +322,12 @@ public function testUnterminatedVariable()
';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $lexer->tokenize(new \Twig\Source($template, 'index'));
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unclosed "block" in "index" at line 3
*/
public function testUnterminatedBlock()
@@ -341,7 +341,7 @@ public function testUnterminatedBlock()
';
- $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
- $lexer->tokenize(new Twig_Source($template, 'index'));
+ $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $lexer->tokenize(new \Twig\Source($template, 'index'));
}
}
diff --git a/test/Twig/Tests/Loader/ArrayTest.php b/test/Twig/Tests/Loader/ArrayTest.php
index 74be2c80a0..bc9fa2ffa6 100644
--- a/test/Twig/Tests/Loader/ArrayTest.php
+++ b/test/Twig/Tests/Loader/ArrayTest.php
@@ -16,42 +16,42 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase
*/
public function testGetSource()
{
- $loader = new Twig_Loader_Array(['foo' => 'bar']);
+ $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']);
$this->assertEquals('bar', $loader->getSource('foo'));
}
/**
* @group legacy
- * @expectedException \Twig_Error_Loader
+ * @expectedException \Twig\Error\LoaderError
*/
public function testGetSourceWhenTemplateDoesNotExist()
{
- $loader = new Twig_Loader_Array([]);
+ $loader = new \Twig\Loader\ArrayLoader([]);
$loader->getSource('foo');
}
/**
- * @expectedException \Twig_Error_Loader
+ * @expectedException \Twig\Error\LoaderError
*/
public function testGetSourceContextWhenTemplateDoesNotExist()
{
- $loader = new Twig_Loader_Array([]);
+ $loader = new \Twig\Loader\ArrayLoader([]);
$loader->getSourceContext('foo');
}
public function testGetCacheKey()
{
- $loader = new Twig_Loader_Array(['foo' => 'bar']);
+ $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']);
$this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
}
public function testGetCacheKeyWhenTemplateHasDuplicateContent()
{
- $loader = new Twig_Loader_Array([
+ $loader = new \Twig\Loader\ArrayLoader([
'foo' => 'bar',
'baz' => 'bar',
]);
@@ -62,7 +62,7 @@ public function testGetCacheKeyWhenTemplateHasDuplicateContent()
public function testGetCacheKeyIsProtectedFromEdgeCollisions()
{
- $loader = new Twig_Loader_Array([
+ $loader = new \Twig\Loader\ArrayLoader([
'foo__' => 'bar',
'foo' => '__bar',
]);
@@ -72,18 +72,18 @@ public function testGetCacheKeyIsProtectedFromEdgeCollisions()
}
/**
- * @expectedException \Twig_Error_Loader
+ * @expectedException \Twig\Error\LoaderError
*/
public function testGetCacheKeyWhenTemplateDoesNotExist()
{
- $loader = new Twig_Loader_Array([]);
+ $loader = new \Twig\Loader\ArrayLoader([]);
$loader->getCacheKey('foo');
}
public function testSetTemplate()
{
- $loader = new Twig_Loader_Array([]);
+ $loader = new \Twig\Loader\ArrayLoader([]);
$loader->setTemplate('foo', 'bar');
$this->assertEquals('bar', $loader->getSourceContext('foo')->getCode());
@@ -91,16 +91,16 @@ public function testSetTemplate()
public function testIsFresh()
{
- $loader = new Twig_Loader_Array(['foo' => 'bar']);
+ $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']);
$this->assertTrue($loader->isFresh('foo', time()));
}
/**
- * @expectedException \Twig_Error_Loader
+ * @expectedException \Twig\Error\LoaderError
*/
public function testIsFreshWhenTemplateDoesNotExist()
{
- $loader = new Twig_Loader_Array([]);
+ $loader = new \Twig\Loader\ArrayLoader([]);
$loader->isFresh('foo', time());
}
@@ -108,7 +108,7 @@ public function testIsFreshWhenTemplateDoesNotExist()
public function testTemplateReference()
{
$name = new Twig_Test_Loader_TemplateReference('foo');
- $loader = new Twig_Loader_Array(['foo' => 'bar']);
+ $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']);
$loader->getCacheKey($name);
$loader->getSourceContext($name);
diff --git a/test/Twig/Tests/Loader/ChainTest.php b/test/Twig/Tests/Loader/ChainTest.php
index a42ad932ad..609a979b93 100644
--- a/test/Twig/Tests/Loader/ChainTest.php
+++ b/test/Twig/Tests/Loader/ChainTest.php
@@ -16,9 +16,9 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase
*/
public function testGetSource()
{
- $loader = new Twig_Loader_Chain([
- new Twig_Loader_Array(['foo' => 'bar']),
- new Twig_Loader_Array(['foo' => 'foobar', 'bar' => 'foo']),
+ $loader = new \Twig\Loader\ChainLoader([
+ new \Twig\Loader\ArrayLoader(['foo' => 'bar']),
+ new \Twig\Loader\ArrayLoader(['foo' => 'foobar', 'bar' => 'foo']),
]);
$this->assertEquals('bar', $loader->getSource('foo'));
@@ -28,10 +28,10 @@ public function testGetSource()
public function testGetSourceContext()
{
$path = __DIR__.'/../Fixtures';
- $loader = new Twig_Loader_Chain([
- new Twig_Loader_Array(['foo' => 'bar']),
- new Twig_Loader_Array(['errors/index.html' => 'baz']),
- new Twig_Loader_Filesystem([$path]),
+ $loader = new \Twig\Loader\ChainLoader([
+ new \Twig\Loader\ArrayLoader(['foo' => 'bar']),
+ new \Twig\Loader\ArrayLoader(['errors/index.html' => 'baz']),
+ new \Twig\Loader\FilesystemLoader([$path]),
]);
$this->assertEquals('foo', $loader->getSourceContext('foo')->getName());
@@ -47,31 +47,31 @@ public function testGetSourceContext()
}
/**
- * @expectedException \Twig_Error_Loader
+ * @expectedException \Twig\Error\LoaderError
*/
public function testGetSourceContextWhenTemplateDoesNotExist()
{
- $loader = new Twig_Loader_Chain([]);
+ $loader = new \Twig\Loader\ChainLoader([]);
$loader->getSourceContext('foo');
}
/**
* @group legacy
- * @expectedException \Twig_Error_Loader
+ * @expectedException \Twig\Error\LoaderError
*/
public function testGetSourceWhenTemplateDoesNotExist()
{
- $loader = new Twig_Loader_Chain([]);
+ $loader = new \Twig\Loader\ChainLoader([]);
$loader->getSource('foo');
}
public function testGetCacheKey()
{
- $loader = new Twig_Loader_Chain([
- new Twig_Loader_Array(['foo' => 'bar']),
- new Twig_Loader_Array(['foo' => 'foobar', 'bar' => 'foo']),
+ $loader = new \Twig\Loader\ChainLoader([
+ new \Twig\Loader\ArrayLoader(['foo' => 'bar']),
+ new \Twig\Loader\ArrayLoader(['foo' => 'foobar', 'bar' => 'foo']),
]);
$this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
@@ -79,19 +79,19 @@ public function testGetCacheKey()
}
/**
- * @expectedException \Twig_Error_Loader
+ * @expectedException \Twig\Error\LoaderError
*/
public function testGetCacheKeyWhenTemplateDoesNotExist()
{
- $loader = new Twig_Loader_Chain([]);
+ $loader = new \Twig\Loader\ChainLoader([]);
$loader->getCacheKey('foo');
}
public function testAddLoader()
{
- $loader = new Twig_Loader_Chain();
- $loader->addLoader(new Twig_Loader_Array(['foo' => 'bar']));
+ $loader = new \Twig\Loader\ChainLoader();
+ $loader->addLoader(new \Twig\Loader\ArrayLoader(['foo' => 'bar']));
$this->assertEquals('bar', $loader->getSourceContext('foo')->getCode());
}
@@ -104,10 +104,10 @@ public function testExists()
// can be removed in 2.0
$loader2 = $this->getMockBuilder('Twig_ChainTestLoaderInterface')->getMock();
- //$loader2 = $this->getMockBuilder(['Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'])->getMock();
- $loader2->expects($this->once())->method('getSourceContext')->will($this->returnValue(new Twig_Source('content', 'index')));
+ //$loader2 = $this->getMockBuilder(['\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface'])->getMock();
+ $loader2->expects($this->once())->method('getSourceContext')->will($this->returnValue(new \Twig\Source('content', 'index')));
- $loader = new Twig_Loader_Chain();
+ $loader = new \Twig\Loader\ChainLoader();
$loader->addLoader($loader1);
$loader->addLoader($loader2);
@@ -115,10 +115,10 @@ public function testExists()
}
}
-interface Twig_ChainTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface
+interface Twig_ChainTestLoaderInterface extends \Twig\Loader\LoaderInterface, Twig_SourceContextLoaderInterface
{
}
-interface Twig_ChainTestLoaderWithExistsInterface extends Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
+interface Twig_ChainTestLoaderWithExistsInterface extends \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
{
}
diff --git a/test/Twig/Tests/Loader/FilesystemTest.php b/test/Twig/Tests/Loader/FilesystemTest.php
index d8ae84b4a4..c9574cd985 100644
--- a/test/Twig/Tests/Loader/FilesystemTest.php
+++ b/test/Twig/Tests/Loader/FilesystemTest.php
@@ -14,7 +14,7 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase
public function testGetSourceContext()
{
$path = __DIR__.'/../Fixtures';
- $loader = new Twig_Loader_Filesystem([$path]);
+ $loader = new \Twig\Loader\FilesystemLoader([$path]);
$this->assertEquals('errors/index.html', $loader->getSourceContext('errors/index.html')->getName());
$this->assertEquals(realpath($path.'/errors/index.html'), realpath($loader->getSourceContext('errors/index.html')->getPath()));
}
@@ -24,12 +24,12 @@ public function testGetSourceContext()
*/
public function testSecurity($template)
{
- $loader = new Twig_Loader_Filesystem([__DIR__.'/../Fixtures']);
+ $loader = new \Twig\Loader\FilesystemLoader([__DIR__.'/../Fixtures']);
try {
$loader->getCacheKey($template);
$this->fail();
- } catch (Twig_Error_Loader $e) {
+ } catch (\Twig\Error\LoaderError $e) {
$this->assertNotContains('Unable to find template', $e->getMessage());
}
}
@@ -64,7 +64,7 @@ public function getSecurityTests()
*/
public function testPaths($basePath, $cacheKey, $rootPath)
{
- $loader = new Twig_Loader_Filesystem([$basePath.'/normal', $basePath.'/normal_bis'], $rootPath);
+ $loader = new \Twig\Loader\FilesystemLoader([$basePath.'/normal', $basePath.'/normal_bis'], $rootPath);
$loader->setPaths([$basePath.'/named', $basePath.'/named_bis'], 'named');
$loader->addPath($basePath.'/named_ter', 'named');
$loader->addPath($basePath.'/normal_ter');
@@ -126,30 +126,30 @@ public function getBasePaths()
public function testEmptyConstructor()
{
- $loader = new Twig_Loader_Filesystem();
+ $loader = new \Twig\Loader\FilesystemLoader();
$this->assertEquals([], $loader->getPaths());
}
public function testGetNamespaces()
{
- $loader = new Twig_Loader_Filesystem(sys_get_temp_dir());
- $this->assertEquals([Twig_Loader_Filesystem::MAIN_NAMESPACE], $loader->getNamespaces());
+ $loader = new \Twig\Loader\FilesystemLoader(sys_get_temp_dir());
+ $this->assertEquals([\Twig\Loader\FilesystemLoader::MAIN_NAMESPACE], $loader->getNamespaces());
$loader->addPath(sys_get_temp_dir(), 'named');
- $this->assertEquals([Twig_Loader_Filesystem::MAIN_NAMESPACE, 'named'], $loader->getNamespaces());
+ $this->assertEquals([\Twig\Loader\FilesystemLoader::MAIN_NAMESPACE, 'named'], $loader->getNamespaces());
}
public function testFindTemplateExceptionNamespace()
{
$basePath = __DIR__.'/Fixtures';
- $loader = new Twig_Loader_Filesystem([$basePath.'/normal']);
+ $loader = new \Twig\Loader\FilesystemLoader([$basePath.'/normal']);
$loader->addPath($basePath.'/named', 'named');
try {
$loader->getSourceContext('@named/nowhere.html');
} catch (\Exception $e) {
- $this->assertInstanceOf('Twig_Error_Loader', $e);
+ $this->assertInstanceOf('\Twig\Error\LoaderError', $e);
$this->assertContains('Unable to find template "@named/nowhere.html"', $e->getMessage());
}
}
@@ -158,7 +158,7 @@ public function testFindTemplateWithCache()
{
$basePath = __DIR__.'/Fixtures';
- $loader = new Twig_Loader_Filesystem([$basePath.'/normal']);
+ $loader = new \Twig\Loader\FilesystemLoader([$basePath.'/normal']);
$loader->addPath($basePath.'/named', 'named');
// prime the cache for index.html in the named namespace
@@ -171,12 +171,12 @@ public function testFindTemplateWithCache()
public function testLoadTemplateAndRenderBlockWithCache()
{
- $loader = new Twig_Loader_Filesystem([]);
+ $loader = new \Twig\Loader\FilesystemLoader([]);
$loader->addPath(__DIR__.'/Fixtures/themes/theme2');
$loader->addPath(__DIR__.'/Fixtures/themes/theme1');
$loader->addPath(__DIR__.'/Fixtures/themes/theme1', 'default_theme');
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$template = $twig->loadTemplate('blocks.html.twig');
$this->assertSame('block from theme 1', $template->renderBlock('b1', []));
@@ -202,10 +202,10 @@ public function getArrayInheritanceTests()
*/
public function testArrayInheritance($templateName)
{
- $loader = new Twig_Loader_Filesystem([]);
+ $loader = new \Twig\Loader\FilesystemLoader([]);
$loader->addPath(__DIR__.'/Fixtures/inheritance');
- $twig = new Twig_Environment($loader);
+ $twig = new \Twig\Environment($loader);
$template = $twig->loadTemplate($templateName);
$this->assertSame('VALID Child', $template->renderBlock('body', []));
@@ -216,7 +216,7 @@ public function testArrayInheritance($templateName)
*/
public function testLoadTemplateFromPhar()
{
- $loader = new Twig_Loader_Filesystem([]);
+ $loader = new \Twig\Loader\FilesystemLoader([]);
// phar-sample.phar was created with the following script:
// $f = new Phar('phar-test.phar');
// $f->addFromString('hello.twig', 'hello from phar');
@@ -226,7 +226,7 @@ public function testLoadTemplateFromPhar()
public function testTemplateExistsAlwaysReturnsBool()
{
- $loader = new Twig_Loader_Filesystem([]);
+ $loader = new \Twig\Loader\FilesystemLoader([]);
$this->assertFalse($loader->exists("foo\0.twig"));
$this->assertFalse($loader->exists('../foo.twig'));
$this->assertFalse($loader->exists('@foo'));
diff --git a/test/Twig/Tests/NativeExtensionTest.php b/test/Twig/Tests/NativeExtensionTest.php
index 2b969a024c..379132d774 100644
--- a/test/Twig/Tests/NativeExtensionTest.php
+++ b/test/Twig/Tests/NativeExtensionTest.php
@@ -20,7 +20,7 @@ public function testGetProperties()
$this->markTestSkipped('Extension is not available on PHP 7+');
}
- $twig = new Twig_Environment(new Twig_Loader_Array(['index' => '{{ d1.date }}{{ d2.date }}']), [
+ $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader(['index' => '{{ d1.date }}{{ d2.date }}']), [
'debug' => true,
'cache' => false,
'autoescape' => false,
diff --git a/test/Twig/Tests/Node/AutoEscapeTest.php b/test/Twig/Tests/Node/AutoEscapeTest.php
index 1c9f09393e..1eeddc457d 100644
--- a/test/Twig/Tests/Node/AutoEscapeTest.php
+++ b/test/Twig/Tests/Node/AutoEscapeTest.php
@@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_AutoEscapeTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_AutoEscapeTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $body = new Twig_Node([new Twig_Node_Text('foo', 1)]);
- $node = new Twig_Node_AutoEscape(true, $body, 1);
+ $body = new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)]);
+ $node = new \Twig\Node\AutoEscapeNode(true, $body, 1);
$this->assertEquals($body, $node->getNode('body'));
$this->assertTrue($node->getAttribute('value'));
@@ -22,8 +22,8 @@ public function testConstructor()
public function getTests()
{
- $body = new Twig_Node([new Twig_Node_Text('foo', 1)]);
- $node = new Twig_Node_AutoEscape(true, $body, 1);
+ $body = new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)]);
+ $node = new \Twig\Node\AutoEscapeNode(true, $body, 1);
return [
[$node, "// line 1\necho \"foo\";"],
diff --git a/test/Twig/Tests/Node/BlockReferenceTest.php b/test/Twig/Tests/Node/BlockReferenceTest.php
index 0eb60ca019..de37e37f15 100644
--- a/test/Twig/Tests/Node/BlockReferenceTest.php
+++ b/test/Twig/Tests/Node/BlockReferenceTest.php
@@ -9,11 +9,11 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_BlockReferenceTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_BlockReferenceTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $node = new Twig_Node_BlockReference('foo', 1);
+ $node = new \Twig\Node\BlockReferenceNode('foo', 1);
$this->assertEquals('foo', $node->getAttribute('name'));
}
@@ -21,7 +21,7 @@ public function testConstructor()
public function getTests()
{
return [
- [new Twig_Node_BlockReference('foo', 1), <<displayBlock('foo', \$context, \$blocks);
EOF
diff --git a/test/Twig/Tests/Node/BlockTest.php b/test/Twig/Tests/Node/BlockTest.php
index 0b347df029..d2256a6d88 100644
--- a/test/Twig/Tests/Node/BlockTest.php
+++ b/test/Twig/Tests/Node/BlockTest.php
@@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_BlockTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_BlockTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $body = new Twig_Node_Text('foo', 1);
- $node = new Twig_Node_Block('foo', $body, 1);
+ $body = new \Twig\Node\TextNode('foo', 1);
+ $node = new \Twig\Node\BlockNode('foo', $body, 1);
$this->assertEquals($body, $node->getNode('body'));
$this->assertEquals('foo', $node->getAttribute('name'));
@@ -22,8 +22,8 @@ public function testConstructor()
public function getTests()
{
- $body = new Twig_Node_Text('foo', 1);
- $node = new Twig_Node_Block('foo', $body, 1);
+ $body = new \Twig\Node\TextNode('foo', 1);
+ $node = new \Twig\Node\BlockNode('foo', $body, 1);
return [
[$node, <<assertEquals($expr, $node->getNode('expr'));
}
@@ -23,8 +23,8 @@ public function getTests()
{
$tests = [];
- $expr = new Twig_Node_Expression_Constant('This section is deprecated', 1);
- $node = new Twig_Node_Deprecated($expr, 1, 'deprecated');
+ $expr = new \Twig\Node\Expression\ConstantExpression('This section is deprecated', 1);
+ $node = new \Twig\Node\DeprecatedNode($expr, 1, 'deprecated');
$node->setTemplateName('foo.twig');
$tests[] = [$node, <<setTemplateName('foo.twig');
$tests[] = [$node, <<getMockBuilder('Twig_LoaderInterface')->getMock());
- $environment->addFunction(new Twig_SimpleFunction('foo', 'foo', []));
+ $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
+ $environment->addFunction(new \Twig\TwigFunction('foo', 'foo', []));
- $expr = new Twig_Node_Expression_Function('foo', new Twig_Node(), 1);
- $node = new Twig_Node_Deprecated($expr, 1, 'deprecated');
+ $expr = new \Twig\Node\Expression\FunctionExpression('foo', new \Twig\Node\Node(), 1);
+ $node = new \Twig\Node\DeprecatedNode($expr, 1, 'deprecated');
$node->setTemplateName('foo.twig');
$compiler = $this->getCompiler($environment);
diff --git a/test/Twig/Tests/Node/DoTest.php b/test/Twig/Tests/Node/DoTest.php
index 64d6eead30..6e60ab413e 100644
--- a/test/Twig/Tests/Node/DoTest.php
+++ b/test/Twig/Tests/Node/DoTest.php
@@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_DoTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_DoTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $expr = new Twig_Node_Expression_Constant('foo', 1);
- $node = new Twig_Node_Do($expr, 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1);
+ $node = new \Twig\Node\DoNode($expr, 1);
$this->assertEquals($expr, $node->getNode('expr'));
}
@@ -23,8 +23,8 @@ public function getTests()
{
$tests = [];
- $expr = new Twig_Node_Expression_Constant('foo', 1);
- $node = new Twig_Node_Do($expr, 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1);
+ $node = new \Twig\Node\DoNode($expr, 1);
$tests[] = [$node, "// line 1\n\"foo\";"];
return $tests;
diff --git a/test/Twig/Tests/Node/Expression/ArrayTest.php b/test/Twig/Tests/Node/Expression/ArrayTest.php
index ecb5055d2d..2175ccc2e4 100644
--- a/test/Twig/Tests/Node/Expression/ArrayTest.php
+++ b/test/Twig/Tests/Node/Expression/ArrayTest.php
@@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_ArrayTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_ArrayTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $elements = [new Twig_Node_Expression_Constant('foo', 1), $foo = new Twig_Node_Expression_Constant('bar', 1)];
- $node = new Twig_Node_Expression_Array($elements, 1);
+ $elements = [new \Twig\Node\Expression\ConstantExpression('foo', 1), $foo = new \Twig\Node\Expression\ConstantExpression('bar', 1)];
+ $node = new \Twig\Node\Expression\ArrayExpression($elements, 1);
$this->assertEquals($foo, $node->getNode(1));
}
@@ -22,13 +22,13 @@ public function testConstructor()
public function getTests()
{
$elements = [
- new Twig_Node_Expression_Constant('foo', 1),
- new Twig_Node_Expression_Constant('bar', 1),
+ new \Twig\Node\Expression\ConstantExpression('foo', 1),
+ new \Twig\Node\Expression\ConstantExpression('bar', 1),
- new Twig_Node_Expression_Constant('bar', 1),
- new Twig_Node_Expression_Constant('foo', 1),
+ new \Twig\Node\Expression\ConstantExpression('bar', 1),
+ new \Twig\Node\Expression\ConstantExpression('foo', 1),
];
- $node = new Twig_Node_Expression_Array($elements, 1);
+ $node = new \Twig\Node\Expression\ArrayExpression($elements, 1);
return [
[$node, '["foo" => "bar", "bar" => "foo"]'],
diff --git a/test/Twig/Tests/Node/Expression/AssignNameTest.php b/test/Twig/Tests/Node/Expression/AssignNameTest.php
index a325f0b4ab..28470e5000 100644
--- a/test/Twig/Tests/Node/Expression/AssignNameTest.php
+++ b/test/Twig/Tests/Node/Expression/AssignNameTest.php
@@ -9,18 +9,18 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_AssignNameTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_AssignNameTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $node = new Twig_Node_Expression_AssignName('foo', 1);
+ $node = new \Twig\Node\Expression\AssignNameExpression('foo', 1);
$this->assertEquals('foo', $node->getAttribute('name'));
}
public function getTests()
{
- $node = new Twig_Node_Expression_AssignName('foo', 1);
+ $node = new \Twig\Node\Expression\AssignNameExpression('foo', 1);
return [
[$node, '$context["foo"]'],
diff --git a/test/Twig/Tests/Node/Expression/Binary/AddTest.php b/test/Twig/Tests/Node/Expression/Binary/AddTest.php
index 333b2056a8..64a1c06b79 100644
--- a/test/Twig/Tests/Node/Expression/Binary/AddTest.php
+++ b/test/Twig/Tests/Node/Expression/Binary/AddTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Binary_AddTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Binary_AddTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Add($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\AddBinary($left, $right, 1);
$this->assertEquals($left, $node->getNode('left'));
$this->assertEquals($right, $node->getNode('right'));
@@ -23,9 +23,9 @@ public function testConstructor()
public function getTests()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Add($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\AddBinary($left, $right, 1);
return [
[$node, '(1 + 2)'],
diff --git a/test/Twig/Tests/Node/Expression/Binary/AndTest.php b/test/Twig/Tests/Node/Expression/Binary/AndTest.php
index 56c055e7d3..6292f9e382 100644
--- a/test/Twig/Tests/Node/Expression/Binary/AndTest.php
+++ b/test/Twig/Tests/Node/Expression/Binary/AndTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Binary_AndTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Binary_AndTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_And($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\AndBinary($left, $right, 1);
$this->assertEquals($left, $node->getNode('left'));
$this->assertEquals($right, $node->getNode('right'));
@@ -23,9 +23,9 @@ public function testConstructor()
public function getTests()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_And($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\AndBinary($left, $right, 1);
return [
[$node, '(1 && 2)'],
diff --git a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php
index e83712e50e..9a6f56acfa 100644
--- a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php
+++ b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Binary_ConcatTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Binary_ConcatTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Concat($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\ConcatBinary($left, $right, 1);
$this->assertEquals($left, $node->getNode('left'));
$this->assertEquals($right, $node->getNode('right'));
@@ -23,9 +23,9 @@ public function testConstructor()
public function getTests()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Concat($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\ConcatBinary($left, $right, 1);
return [
[$node, '(1 . 2)'],
diff --git a/test/Twig/Tests/Node/Expression/Binary/DivTest.php b/test/Twig/Tests/Node/Expression/Binary/DivTest.php
index 011e7ce4fb..58719c2b20 100644
--- a/test/Twig/Tests/Node/Expression/Binary/DivTest.php
+++ b/test/Twig/Tests/Node/Expression/Binary/DivTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Binary_DivTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Binary_DivTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Div($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\DivBinary($left, $right, 1);
$this->assertEquals($left, $node->getNode('left'));
$this->assertEquals($right, $node->getNode('right'));
@@ -23,9 +23,9 @@ public function testConstructor()
public function getTests()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Div($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\DivBinary($left, $right, 1);
return [
[$node, '(1 / 2)'],
diff --git a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php
index 1131a4e226..4ca3840210 100644
--- a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php
+++ b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Binary_FloorDivTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Binary_FloorDivTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_FloorDiv($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\FloorDivBinary($left, $right, 1);
$this->assertEquals($left, $node->getNode('left'));
$this->assertEquals($right, $node->getNode('right'));
@@ -23,9 +23,9 @@ public function testConstructor()
public function getTests()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_FloorDiv($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\FloorDivBinary($left, $right, 1);
return [
[$node, '(int) floor((1 / 2))'],
diff --git a/test/Twig/Tests/Node/Expression/Binary/ModTest.php b/test/Twig/Tests/Node/Expression/Binary/ModTest.php
index 7c3d00b8af..d4d48acdb3 100644
--- a/test/Twig/Tests/Node/Expression/Binary/ModTest.php
+++ b/test/Twig/Tests/Node/Expression/Binary/ModTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Binary_ModTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Binary_ModTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Mod($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\ModBinary($left, $right, 1);
$this->assertEquals($left, $node->getNode('left'));
$this->assertEquals($right, $node->getNode('right'));
@@ -23,9 +23,9 @@ public function testConstructor()
public function getTests()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Mod($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\ModBinary($left, $right, 1);
return [
[$node, '(1 % 2)'],
diff --git a/test/Twig/Tests/Node/Expression/Binary/MulTest.php b/test/Twig/Tests/Node/Expression/Binary/MulTest.php
index 6ed79bc48c..b35655b752 100644
--- a/test/Twig/Tests/Node/Expression/Binary/MulTest.php
+++ b/test/Twig/Tests/Node/Expression/Binary/MulTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Binary_MulTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Binary_MulTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Mul($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\MulBinary($left, $right, 1);
$this->assertEquals($left, $node->getNode('left'));
$this->assertEquals($right, $node->getNode('right'));
@@ -23,9 +23,9 @@ public function testConstructor()
public function getTests()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Mul($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\MulBinary($left, $right, 1);
return [
[$node, '(1 * 2)'],
diff --git a/test/Twig/Tests/Node/Expression/Binary/OrTest.php b/test/Twig/Tests/Node/Expression/Binary/OrTest.php
index fe9acb0c58..9a40ffbd91 100644
--- a/test/Twig/Tests/Node/Expression/Binary/OrTest.php
+++ b/test/Twig/Tests/Node/Expression/Binary/OrTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Binary_OrTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Binary_OrTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Or($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\OrBinary($left, $right, 1);
$this->assertEquals($left, $node->getNode('left'));
$this->assertEquals($right, $node->getNode('right'));
@@ -23,9 +23,9 @@ public function testConstructor()
public function getTests()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Or($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\OrBinary($left, $right, 1);
return [
[$node, '(1 || 2)'],
diff --git a/test/Twig/Tests/Node/Expression/Binary/SubTest.php b/test/Twig/Tests/Node/Expression/Binary/SubTest.php
index e142016125..191ad7e96c 100644
--- a/test/Twig/Tests/Node/Expression/Binary/SubTest.php
+++ b/test/Twig/Tests/Node/Expression/Binary/SubTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Binary_SubTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Binary_SubTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Sub($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\SubBinary($left, $right, 1);
$this->assertEquals($left, $node->getNode('left'));
$this->assertEquals($right, $node->getNode('right'));
@@ -23,9 +23,9 @@ public function testConstructor()
public function getTests()
{
- $left = new Twig_Node_Expression_Constant(1, 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_Binary_Sub($left, $right, 1);
+ $left = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\Binary\SubBinary($left, $right, 1);
return [
[$node, '(1 - 2)'],
diff --git a/test/Twig/Tests/Node/Expression/CallTest.php b/test/Twig/Tests/Node/Expression/CallTest.php
index ede330987c..72780d7115 100644
--- a/test/Twig/Tests/Node/Expression/CallTest.php
+++ b/test/Twig/Tests/Node/Expression/CallTest.php
@@ -18,7 +18,7 @@ public function testGetArguments()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Positional arguments cannot be used after named arguments for function "date".
*/
public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments()
@@ -28,7 +28,7 @@ public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Argument "format" is defined twice for function "date".
*/
public function testGetArgumentsWhenArgumentIsDefinedTwice()
@@ -38,7 +38,7 @@ public function testGetArgumentsWhenArgumentIsDefinedTwice()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown argument "unknown" for function "date(format, timestamp)".
*/
public function testGetArgumentsWithWrongNamedArgumentName()
@@ -48,7 +48,7 @@ public function testGetArgumentsWithWrongNamedArgumentName()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown arguments "unknown1", "unknown2" for function "date(format, timestamp)".
*/
public function testGetArgumentsWithWrongNamedArgumentNames()
@@ -58,7 +58,7 @@ public function testGetArgumentsWithWrongNamedArgumentNames()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Argument "case_sensitivity" could not be assigned for function "substr_compare(main_str, str, offset, length, case_sensitivity)" because it is mapped to an internal PHP function which cannot determine default value for optional argument "length".
*/
public function testResolveArgumentsWithMissingValueForOptionalArgument()
@@ -123,7 +123,7 @@ public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnO
}
}
-class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call
+class Twig_Tests_Node_Expression_Call extends \Twig\Node\Expression\CallExpression
{
public function getArguments($callable, $arguments)
{
diff --git a/test/Twig/Tests/Node/Expression/ConditionalTest.php b/test/Twig/Tests/Node/Expression/ConditionalTest.php
index ff9a5ad484..1c37e6106f 100644
--- a/test/Twig/Tests/Node/Expression/ConditionalTest.php
+++ b/test/Twig/Tests/Node/Expression/ConditionalTest.php
@@ -9,14 +9,14 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_ConditionalTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_ConditionalTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $expr1 = new Twig_Node_Expression_Constant(1, 1);
- $expr2 = new Twig_Node_Expression_Constant(2, 1);
- $expr3 = new Twig_Node_Expression_Constant(3, 1);
- $node = new Twig_Node_Expression_Conditional($expr1, $expr2, $expr3, 1);
+ $expr1 = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $expr2 = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $expr3 = new \Twig\Node\Expression\ConstantExpression(3, 1);
+ $node = new \Twig\Node\Expression\ConditionalExpression($expr1, $expr2, $expr3, 1);
$this->assertEquals($expr1, $node->getNode('expr1'));
$this->assertEquals($expr2, $node->getNode('expr2'));
@@ -27,10 +27,10 @@ public function getTests()
{
$tests = [];
- $expr1 = new Twig_Node_Expression_Constant(1, 1);
- $expr2 = new Twig_Node_Expression_Constant(2, 1);
- $expr3 = new Twig_Node_Expression_Constant(3, 1);
- $node = new Twig_Node_Expression_Conditional($expr1, $expr2, $expr3, 1);
+ $expr1 = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $expr2 = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $expr3 = new \Twig\Node\Expression\ConstantExpression(3, 1);
+ $node = new \Twig\Node\Expression\ConditionalExpression($expr1, $expr2, $expr3, 1);
$tests[] = [$node, '((1) ? (2) : (3))'];
return $tests;
diff --git a/test/Twig/Tests/Node/Expression/ConstantTest.php b/test/Twig/Tests/Node/Expression/ConstantTest.php
index c43de0020f..1cb1242e7a 100644
--- a/test/Twig/Tests/Node/Expression/ConstantTest.php
+++ b/test/Twig/Tests/Node/Expression/ConstantTest.php
@@ -9,11 +9,11 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_ConstantTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_ConstantTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $node = new Twig_Node_Expression_Constant('foo', 1);
+ $node = new \Twig\Node\Expression\ConstantExpression('foo', 1);
$this->assertEquals('foo', $node->getAttribute('value'));
}
@@ -22,7 +22,7 @@ public function getTests()
{
$tests = [];
- $node = new Twig_Node_Expression_Constant('foo', 1);
+ $node = new \Twig\Node\Expression\ConstantExpression('foo', 1);
$tests[] = [$node, '"foo"'];
return $tests;
diff --git a/test/Twig/Tests/Node/Expression/FilterTest.php b/test/Twig/Tests/Node/Expression/FilterTest.php
index 05dd264d40..a21650f839 100644
--- a/test/Twig/Tests/Node/Expression/FilterTest.php
+++ b/test/Twig/Tests/Node/Expression/FilterTest.php
@@ -9,14 +9,14 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $expr = new Twig_Node_Expression_Constant('foo', 1);
- $name = new Twig_Node_Expression_Constant('upper', 1);
- $args = new Twig_Node();
- $node = new Twig_Node_Expression_Filter($expr, $name, $args, 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1);
+ $name = new \Twig\Node\Expression\ConstantExpression('upper', 1);
+ $args = new \Twig\Node\Node();
+ $node = new \Twig\Node\Expression\FilterExpression($expr, $name, $args, 1);
$this->assertEquals($expr, $node->getNode('node'));
$this->assertEquals($name, $node->getNode('filter'));
@@ -25,15 +25,15 @@ public function testConstructor()
public function getTests()
{
- $environment = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $environment->addFilter(new Twig_SimpleFilter('bar', 'bar', ['needs_environment' => true]));
- $environment->addFilter(new Twig_SimpleFilter('barbar', 'twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true]));
+ $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
+ $environment->addFilter(new \Twig\TwigFilter('bar', 'bar', ['needs_environment' => true]));
+ $environment->addFilter(new \Twig\TwigFilter('barbar', 'twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true]));
$tests = [];
- $expr = new Twig_Node_Expression_Constant('foo', 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1);
$node = $this->createFilter($expr, 'upper');
- $node = $this->createFilter($node, 'number_format', [new Twig_Node_Expression_Constant(2, 1), new Twig_Node_Expression_Constant('.', 1), new Twig_Node_Expression_Constant(',', 1)]);
+ $node = $this->createFilter($node, 'number_format', [new \Twig\Node\Expression\ConstantExpression(2, 1), new \Twig\Node\Expression\ConstantExpression('.', 1), new \Twig\Node\Expression\ConstantExpression(',', 1)]);
if (\function_exists('mb_get_info')) {
$tests[] = [$node, 'twig_number_format_filter($this->env, twig_upper_filter($this->env, "foo"), 2, ".", ",")'];
@@ -42,34 +42,34 @@ public function getTests()
}
// named arguments
- $date = new Twig_Node_Expression_Constant(0, 1);
+ $date = new \Twig\Node\Expression\ConstantExpression(0, 1);
$node = $this->createFilter($date, 'date', [
- 'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1),
- 'format' => new Twig_Node_Expression_Constant('d/m/Y H:i:s P', 1),
+ 'timezone' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1),
+ 'format' => new \Twig\Node\Expression\ConstantExpression('d/m/Y H:i:s P', 1),
]);
$tests[] = [$node, 'twig_date_format_filter($this->env, 0, "d/m/Y H:i:s P", "America/Chicago")'];
// skip an optional argument
- $date = new Twig_Node_Expression_Constant(0, 1);
+ $date = new \Twig\Node\Expression\ConstantExpression(0, 1);
$node = $this->createFilter($date, 'date', [
- 'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1),
+ 'timezone' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1),
]);
$tests[] = [$node, 'twig_date_format_filter($this->env, 0, null, "America/Chicago")'];
// underscores vs camelCase for named arguments
- $string = new Twig_Node_Expression_Constant('abc', 1);
+ $string = new \Twig\Node\Expression\ConstantExpression('abc', 1);
$node = $this->createFilter($string, 'reverse', [
- 'preserve_keys' => new Twig_Node_Expression_Constant(true, 1),
+ 'preserve_keys' => new \Twig\Node\Expression\ConstantExpression(true, 1),
]);
$tests[] = [$node, 'twig_reverse_filter($this->env, "abc", true)'];
$node = $this->createFilter($string, 'reverse', [
- 'preserveKeys' => new Twig_Node_Expression_Constant(true, 1),
+ 'preserveKeys' => new \Twig\Node\Expression\ConstantExpression(true, 1),
]);
$tests[] = [$node, 'twig_reverse_filter($this->env, "abc", true)'];
// filter as an anonymous function
if (PHP_VERSION_ID >= 50300) {
- $node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous');
+ $node = $this->createFilter(new \Twig\Node\Expression\ConstantExpression('foo', 1), 'anonymous');
$tests[] = [$node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), ["foo"])'];
}
@@ -77,24 +77,24 @@ public function getTests()
$node = $this->createFilter($string, 'bar');
$tests[] = [$node, 'bar($this->env, "abc")', $environment];
- $node = $this->createFilter($string, 'bar', [new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createFilter($string, 'bar', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'bar($this->env, "abc", "bar")', $environment];
// arbitrary named arguments
$node = $this->createFilter($string, 'barbar');
$tests[] = [$node, 'twig_tests_filter_barbar($context, "abc")', $environment];
- $node = $this->createFilter($string, 'barbar', ['foo' => new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createFilter($string, 'barbar', ['foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'twig_tests_filter_barbar($context, "abc", null, null, ["foo" => "bar"])', $environment];
- $node = $this->createFilter($string, 'barbar', ['arg2' => new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createFilter($string, 'barbar', ['arg2' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'twig_tests_filter_barbar($context, "abc", null, "bar")', $environment];
$node = $this->createFilter($string, 'barbar', [
- new Twig_Node_Expression_Constant('1', 1),
- new Twig_Node_Expression_Constant('2', 1),
- new Twig_Node_Expression_Constant('3', 1),
- 'foo' => new Twig_Node_Expression_Constant('bar', 1),
+ new \Twig\Node\Expression\ConstantExpression('1', 1),
+ new \Twig\Node\Expression\ConstantExpression('2', 1),
+ new \Twig\Node\Expression\ConstantExpression('3', 1),
+ 'foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1),
]);
$tests[] = [$node, 'twig_tests_filter_barbar($context, "abc", "1", "2", [0 => "3", "foo" => "bar"])', $environment];
@@ -102,14 +102,14 @@ public function getTests()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown argument "foobar" for filter "date(format, timezone)" at line 1.
*/
public function testCompileWithWrongNamedArgumentName()
{
- $date = new Twig_Node_Expression_Constant(0, 1);
+ $date = new \Twig\Node\Expression\ConstantExpression(0, 1);
$node = $this->createFilter($date, 'date', [
- 'foobar' => new Twig_Node_Expression_Constant('America/Chicago', 1),
+ 'foobar' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1),
]);
$compiler = $this->getCompiler();
@@ -117,14 +117,14 @@ public function testCompileWithWrongNamedArgumentName()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Value for argument "from" is required for filter "replace" at line 1.
*/
public function testCompileWithMissingNamedArgument()
{
- $value = new Twig_Node_Expression_Constant(0, 1);
+ $value = new \Twig\Node\Expression\ConstantExpression(0, 1);
$node = $this->createFilter($value, 'replace', [
- 'to' => new Twig_Node_Expression_Constant('foo', 1),
+ 'to' => new \Twig\Node\Expression\ConstantExpression('foo', 1),
]);
$compiler = $this->getCompiler();
@@ -133,10 +133,10 @@ public function testCompileWithMissingNamedArgument()
protected function createFilter($node, $name, array $arguments = [])
{
- $name = new Twig_Node_Expression_Constant($name, 1);
- $arguments = new Twig_Node($arguments);
+ $name = new \Twig\Node\Expression\ConstantExpression($name, 1);
+ $arguments = new \Twig\Node\Node($arguments);
- return new Twig_Node_Expression_Filter($node, $name, $arguments, 1);
+ return new \Twig\Node\Expression\FilterExpression($node, $name, $arguments, 1);
}
protected function getEnvironment()
diff --git a/test/Twig/Tests/Node/Expression/FunctionTest.php b/test/Twig/Tests/Node/Expression/FunctionTest.php
index ef1d29cd3e..2aa3a2c2dc 100644
--- a/test/Twig/Tests/Node/Expression/FunctionTest.php
+++ b/test/Twig/Tests/Node/Expression/FunctionTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_FunctionTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
$name = 'function';
- $args = new Twig_Node();
- $node = new Twig_Node_Expression_Function($name, $args, 1);
+ $args = new \Twig\Node\Node();
+ $node = new \Twig\Node\Expression\FunctionExpression($name, $args, 1);
$this->assertEquals($name, $node->getAttribute('name'));
$this->assertEquals($args, $node->getNode('arguments'));
@@ -23,43 +23,43 @@ public function testConstructor()
public function getTests()
{
- $environment = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $environment->addFunction(new Twig_SimpleFunction('foo', 'foo', []));
- $environment->addFunction(new Twig_SimpleFunction('bar', 'bar', ['needs_environment' => true]));
- $environment->addFunction(new Twig_SimpleFunction('foofoo', 'foofoo', ['needs_context' => true]));
- $environment->addFunction(new Twig_SimpleFunction('foobar', 'foobar', ['needs_environment' => true, 'needs_context' => true]));
- $environment->addFunction(new Twig_SimpleFunction('barbar', 'twig_tests_function_barbar', ['is_variadic' => true]));
+ $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
+ $environment->addFunction(new \Twig\TwigFunction('foo', 'foo', []));
+ $environment->addFunction(new \Twig\TwigFunction('bar', 'bar', ['needs_environment' => true]));
+ $environment->addFunction(new \Twig\TwigFunction('foofoo', 'foofoo', ['needs_context' => true]));
+ $environment->addFunction(new \Twig\TwigFunction('foobar', 'foobar', ['needs_environment' => true, 'needs_context' => true]));
+ $environment->addFunction(new \Twig\TwigFunction('barbar', 'twig_tests_function_barbar', ['is_variadic' => true]));
$tests = [];
$node = $this->createFunction('foo');
$tests[] = [$node, 'foo()', $environment];
- $node = $this->createFunction('foo', [new Twig_Node_Expression_Constant('bar', 1), new Twig_Node_Expression_Constant('foobar', 1)]);
+ $node = $this->createFunction('foo', [new \Twig\Node\Expression\ConstantExpression('bar', 1), new \Twig\Node\Expression\ConstantExpression('foobar', 1)]);
$tests[] = [$node, 'foo("bar", "foobar")', $environment];
$node = $this->createFunction('bar');
$tests[] = [$node, 'bar($this->env)', $environment];
- $node = $this->createFunction('bar', [new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createFunction('bar', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'bar($this->env, "bar")', $environment];
$node = $this->createFunction('foofoo');
$tests[] = [$node, 'foofoo($context)', $environment];
- $node = $this->createFunction('foofoo', [new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createFunction('foofoo', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'foofoo($context, "bar")', $environment];
$node = $this->createFunction('foobar');
$tests[] = [$node, 'foobar($this->env, $context)', $environment];
- $node = $this->createFunction('foobar', [new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createFunction('foobar', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'foobar($this->env, $context, "bar")', $environment];
// named arguments
$node = $this->createFunction('date', [
- 'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1),
- 'date' => new Twig_Node_Expression_Constant(0, 1),
+ 'timezone' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1),
+ 'date' => new \Twig\Node\Expression\ConstantExpression(0, 1),
]);
$tests[] = [$node, 'twig_date_converter($this->env, 0, "America/Chicago")'];
@@ -67,23 +67,23 @@ public function getTests()
$node = $this->createFunction('barbar');
$tests[] = [$node, 'twig_tests_function_barbar()', $environment];
- $node = $this->createFunction('barbar', ['foo' => new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createFunction('barbar', ['foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'twig_tests_function_barbar(null, null, ["foo" => "bar"])', $environment];
- $node = $this->createFunction('barbar', ['arg2' => new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createFunction('barbar', ['arg2' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'twig_tests_function_barbar(null, "bar")', $environment];
$node = $this->createFunction('barbar', [
- new Twig_Node_Expression_Constant('1', 1),
- new Twig_Node_Expression_Constant('2', 1),
- new Twig_Node_Expression_Constant('3', 1),
- 'foo' => new Twig_Node_Expression_Constant('bar', 1),
+ new \Twig\Node\Expression\ConstantExpression('1', 1),
+ new \Twig\Node\Expression\ConstantExpression('2', 1),
+ new \Twig\Node\Expression\ConstantExpression('3', 1),
+ 'foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1),
]);
$tests[] = [$node, 'twig_tests_function_barbar("1", "2", [0 => "3", "foo" => "bar"])', $environment];
// function as an anonymous function
if (PHP_VERSION_ID >= 50300) {
- $node = $this->createFunction('anonymous', [new Twig_Node_Expression_Constant('foo', 1)]);
+ $node = $this->createFunction('anonymous', [new \Twig\Node\Expression\ConstantExpression('foo', 1)]);
$tests[] = [$node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), ["foo"])'];
}
@@ -92,7 +92,7 @@ public function getTests()
protected function createFunction($name, array $arguments = [])
{
- return new Twig_Node_Expression_Function($name, new Twig_Node($arguments), 1);
+ return new \Twig\Node\Expression\FunctionExpression($name, new \Twig\Node\Node($arguments), 1);
}
protected function getEnvironment()
diff --git a/test/Twig/Tests/Node/Expression/GetAttrTest.php b/test/Twig/Tests/Node/Expression/GetAttrTest.php
index 1a465509e7..130fd9fb48 100644
--- a/test/Twig/Tests/Node/Expression/GetAttrTest.php
+++ b/test/Twig/Tests/Node/Expression/GetAttrTest.php
@@ -9,40 +9,40 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_GetAttrTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $expr = new Twig_Node_Expression_Name('foo', 1);
- $attr = new Twig_Node_Expression_Constant('bar', 1);
- $args = new Twig_Node_Expression_Array([], 1);
- $args->addElement(new Twig_Node_Expression_Name('foo', 1));
- $args->addElement(new Twig_Node_Expression_Constant('bar', 1));
- $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1);
+ $expr = new \Twig\Node\Expression\NameExpression('foo', 1);
+ $attr = new \Twig\Node\Expression\ConstantExpression('bar', 1);
+ $args = new \Twig\Node\Expression\ArrayExpression([], 1);
+ $args->addElement(new \Twig\Node\Expression\NameExpression('foo', 1));
+ $args->addElement(new \Twig\Node\Expression\ConstantExpression('bar', 1));
+ $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::ARRAY_CALL, 1);
$this->assertEquals($expr, $node->getNode('node'));
$this->assertEquals($attr, $node->getNode('attribute'));
$this->assertEquals($args, $node->getNode('arguments'));
- $this->assertEquals(Twig_Template::ARRAY_CALL, $node->getAttribute('type'));
+ $this->assertEquals(\Twig\Template::ARRAY_CALL, $node->getAttribute('type'));
}
public function getTests()
{
$tests = [];
- $expr = new Twig_Node_Expression_Name('foo', 1);
- $attr = new Twig_Node_Expression_Constant('bar', 1);
- $args = new Twig_Node_Expression_Array([], 1);
- $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1);
+ $expr = new \Twig\Node\Expression\NameExpression('foo', 1);
+ $attr = new \Twig\Node\Expression\ConstantExpression('bar', 1);
+ $args = new \Twig\Node\Expression\ArrayExpression([], 1);
+ $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::ANY_CALL, 1);
$tests[] = [$node, sprintf('%s%s, "bar", [])', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))];
- $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1);
+ $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::ARRAY_CALL, 1);
$tests[] = [$node, sprintf('%s%s, "bar", [], "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))];
- $args = new Twig_Node_Expression_Array([], 1);
- $args->addElement(new Twig_Node_Expression_Name('foo', 1));
- $args->addElement(new Twig_Node_Expression_Constant('bar', 1));
- $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::METHOD_CALL, 1);
+ $args = new \Twig\Node\Expression\ArrayExpression([], 1);
+ $args->addElement(new \Twig\Node\Expression\NameExpression('foo', 1));
+ $args->addElement(new \Twig\Node\Expression\ConstantExpression('bar', 1));
+ $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::METHOD_CALL, 1);
$tests[] = [$node, sprintf('%s%s, "bar", [0 => %s, 1 => "bar"], "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo'))];
return $tests;
diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php
index 73c050b6ae..25eaa02736 100644
--- a/test/Twig/Tests/Node/Expression/NameTest.php
+++ b/test/Twig/Tests/Node/Expression/NameTest.php
@@ -9,22 +9,22 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_NameTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $node = new Twig_Node_Expression_Name('foo', 1);
+ $node = new \Twig\Node\Expression\NameExpression('foo', 1);
$this->assertEquals('foo', $node->getAttribute('name'));
}
public function getTests()
{
- $node = new Twig_Node_Expression_Name('foo', 1);
- $context = new Twig_Node_Expression_Name('_context', 1);
+ $node = new \Twig\Node\Expression\NameExpression('foo', 1);
+ $context = new \Twig\Node\Expression\NameExpression('_context', 1);
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => true]);
- $env1 = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => false]);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true]);
+ $env1 = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => false]);
if (PHP_VERSION_ID >= 70000) {
$output = '($context["foo"] ?? $this->getContext($context, "foo"))';
diff --git a/test/Twig/Tests/Node/Expression/NullCoalesceTest.php b/test/Twig/Tests/Node/Expression/NullCoalesceTest.php
index 39b5d704cc..398c12f469 100644
--- a/test/Twig/Tests/Node/Expression/NullCoalesceTest.php
+++ b/test/Twig/Tests/Node/Expression/NullCoalesceTest.php
@@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_NullCoalesceTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_NullCoalesceTest extends \Twig\Test\NodeTestCase
{
public function getTests()
{
$tests = [];
- $left = new Twig_Node_Expression_Name('foo', 1);
- $right = new Twig_Node_Expression_Constant(2, 1);
- $node = new Twig_Node_Expression_NullCoalesce($left, $right, 1);
+ $left = new \Twig\Node\Expression\NameExpression('foo', 1);
+ $right = new \Twig\Node\Expression\ConstantExpression(2, 1);
+ $node = new \Twig\Node\Expression\NullCoalesceExpression($left, $right, 1);
if (PHP_VERSION_ID >= 70000) {
$tests[] = [$node, "((// line 1\n\$context[\"foo\"]) ?? (2))"];
} elseif (PHP_VERSION_ID >= 50400) {
diff --git a/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php b/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php
index 3a9ff41a61..5ea41d80bb 100644
--- a/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php
+++ b/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php
@@ -1,6 +1,6 @@
addFilter(new Twig_SimpleFilter('anonymous', function () {}));
+$env = new \Twig\Environment(new \Twig\Loader\ArrayLoader([]));
+$env->addFilter(new \Twig\TwigFilter('anonymous', function () {}));
return $env;
diff --git a/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php b/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php
index 57ee62ad3c..44cd979974 100644
--- a/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php
+++ b/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php
@@ -1,6 +1,6 @@
addFunction(new Twig_SimpleFunction('anonymous', function () {}));
+$env = new \Twig\Environment(new \Twig\Loader\ArrayLoader([]));
+$env->addFunction(new \Twig\TwigFunction('anonymous', function () {}));
return $env;
diff --git a/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php b/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php
index eba333db1e..1f30a71ecf 100644
--- a/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php
+++ b/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php
@@ -1,6 +1,6 @@
addTest(new Twig_SimpleTest('anonymous', function () {}));
+$env = new \Twig\Environment(new \Twig\Loader\ArrayLoader([]));
+$env->addTest(new \Twig\TwigTest('anonymous', function () {}));
return $env;
diff --git a/test/Twig/Tests/Node/Expression/ParentTest.php b/test/Twig/Tests/Node/Expression/ParentTest.php
index 4e25a8bee6..940db7169c 100644
--- a/test/Twig/Tests/Node/Expression/ParentTest.php
+++ b/test/Twig/Tests/Node/Expression/ParentTest.php
@@ -9,11 +9,11 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_ParentTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_ParentTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $node = new Twig_Node_Expression_Parent('foo', 1);
+ $node = new \Twig\Node\Expression\ParentExpression('foo', 1);
$this->assertEquals('foo', $node->getAttribute('name'));
}
@@ -21,7 +21,7 @@ public function testConstructor()
public function getTests()
{
$tests = [];
- $tests[] = [new Twig_Node_Expression_Parent('foo', 1), '$this->renderParentBlock("foo", $context, $blocks)'];
+ $tests[] = [new \Twig\Node\Expression\ParentExpression('foo', 1), '$this->renderParentBlock("foo", $context, $blocks)'];
return $tests;
}
diff --git a/test/Twig/Tests/Node/Expression/TestTest.php b/test/Twig/Tests/Node/Expression/TestTest.php
index 28de6cbfdf..c23b2b2225 100644
--- a/test/Twig/Tests/Node/Expression/TestTest.php
+++ b/test/Twig/Tests/Node/Expression/TestTest.php
@@ -9,14 +9,14 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_TestTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $expr = new Twig_Node_Expression_Constant('foo', 1);
- $name = new Twig_Node_Expression_Constant('null', 1);
- $args = new Twig_Node();
- $node = new Twig_Node_Expression_Test($expr, $name, $args, 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1);
+ $name = new \Twig\Node\Expression\ConstantExpression('null', 1);
+ $args = new \Twig\Node\Node();
+ $node = new \Twig\Node\Expression\TestExpression($expr, $name, $args, 1);
$this->assertEquals($expr, $node->getNode('node'));
$this->assertEquals($args, $node->getNode('arguments'));
@@ -25,37 +25,37 @@ public function testConstructor()
public function getTests()
{
- $environment = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $environment->addTest(new Twig_SimpleTest('barbar', 'twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true]));
+ $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
+ $environment->addTest(new \Twig\TwigTest('barbar', 'twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true]));
$tests = [];
- $expr = new Twig_Node_Expression_Constant('foo', 1);
- $node = new Twig_Node_Expression_Test_Null($expr, 'null', new Twig_Node([]), 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1);
+ $node = new \Twig\Node\Expression\Test\NullTest($expr, 'null', new \Twig\Node\Node([]), 1);
$tests[] = [$node, '(null === "foo")'];
// test as an anonymous function
if (PHP_VERSION_ID >= 50300) {
- $node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', [new Twig_Node_Expression_Constant('foo', 1)]);
+ $node = $this->createTest(new \Twig\Node\Expression\ConstantExpression('foo', 1), 'anonymous', [new \Twig\Node\Expression\ConstantExpression('foo', 1)]);
$tests[] = [$node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), ["foo", "foo"])'];
}
// arbitrary named arguments
- $string = new Twig_Node_Expression_Constant('abc', 1);
+ $string = new \Twig\Node\Expression\ConstantExpression('abc', 1);
$node = $this->createTest($string, 'barbar');
$tests[] = [$node, 'twig_tests_test_barbar("abc")', $environment];
- $node = $this->createTest($string, 'barbar', ['foo' => new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createTest($string, 'barbar', ['foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'twig_tests_test_barbar("abc", null, null, ["foo" => "bar"])', $environment];
- $node = $this->createTest($string, 'barbar', ['arg2' => new Twig_Node_Expression_Constant('bar', 1)]);
+ $node = $this->createTest($string, 'barbar', ['arg2' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]);
$tests[] = [$node, 'twig_tests_test_barbar("abc", null, "bar")', $environment];
$node = $this->createTest($string, 'barbar', [
- new Twig_Node_Expression_Constant('1', 1),
- new Twig_Node_Expression_Constant('2', 1),
- new Twig_Node_Expression_Constant('3', 1),
- 'foo' => new Twig_Node_Expression_Constant('bar', 1),
+ new \Twig\Node\Expression\ConstantExpression('1', 1),
+ new \Twig\Node\Expression\ConstantExpression('2', 1),
+ new \Twig\Node\Expression\ConstantExpression('3', 1),
+ 'foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1),
]);
$tests[] = [$node, 'twig_tests_test_barbar("abc", "1", "2", [0 => "3", "foo" => "bar"])', $environment];
@@ -64,7 +64,7 @@ public function getTests()
protected function createTest($node, $name, array $arguments = [])
{
- return new Twig_Node_Expression_Test($node, $name, new Twig_Node($arguments), 1);
+ return new \Twig\Node\Expression\TestExpression($node, $name, new \Twig\Node\Node($arguments), 1);
}
protected function getEnvironment()
diff --git a/test/Twig/Tests/Node/Expression/Unary/NegTest.php b/test/Twig/Tests/Node/Expression/Unary/NegTest.php
index 5c058816ee..d46f2ae9ac 100644
--- a/test/Twig/Tests/Node/Expression/Unary/NegTest.php
+++ b/test/Twig/Tests/Node/Expression/Unary/NegTest.php
@@ -9,24 +9,24 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Unary_NegTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Unary_NegTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $expr = new Twig_Node_Expression_Constant(1, 1);
- $node = new Twig_Node_Expression_Unary_Neg($expr, 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $node = new \Twig\Node\Expression\Unary\NegUnary($expr, 1);
$this->assertEquals($expr, $node->getNode('node'));
}
public function getTests()
{
- $node = new Twig_Node_Expression_Constant(1, 1);
- $node = new Twig_Node_Expression_Unary_Neg($node, 1);
+ $node = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $node = new \Twig\Node\Expression\Unary\NegUnary($node, 1);
return [
[$node, '-1'],
- [new Twig_Node_Expression_Unary_Neg($node, 1), '- -1'],
+ [new \Twig\Node\Expression\Unary\NegUnary($node, 1), '- -1'],
];
}
}
diff --git a/test/Twig/Tests/Node/Expression/Unary/NotTest.php b/test/Twig/Tests/Node/Expression/Unary/NotTest.php
index 9e45760a4a..95ab487e22 100644
--- a/test/Twig/Tests/Node/Expression/Unary/NotTest.php
+++ b/test/Twig/Tests/Node/Expression/Unary/NotTest.php
@@ -9,20 +9,20 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Unary_NotTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Unary_NotTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $expr = new Twig_Node_Expression_Constant(1, 1);
- $node = new Twig_Node_Expression_Unary_Not($expr, 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $node = new \Twig\Node\Expression\Unary\NotUnary($expr, 1);
$this->assertEquals($expr, $node->getNode('node'));
}
public function getTests()
{
- $node = new Twig_Node_Expression_Constant(1, 1);
- $node = new Twig_Node_Expression_Unary_Not($node, 1);
+ $node = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $node = new \Twig\Node\Expression\Unary\NotUnary($node, 1);
return [
[$node, '!1'],
diff --git a/test/Twig/Tests/Node/Expression/Unary/PosTest.php b/test/Twig/Tests/Node/Expression/Unary/PosTest.php
index bddcc4bf98..38469c4377 100644
--- a/test/Twig/Tests/Node/Expression/Unary/PosTest.php
+++ b/test/Twig/Tests/Node/Expression/Unary/PosTest.php
@@ -9,20 +9,20 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_Expression_Unary_PosTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_Expression_Unary_PosTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $expr = new Twig_Node_Expression_Constant(1, 1);
- $node = new Twig_Node_Expression_Unary_Pos($expr, 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $node = new \Twig\Node\Expression\Unary\PosUnary($expr, 1);
$this->assertEquals($expr, $node->getNode('node'));
}
public function getTests()
{
- $node = new Twig_Node_Expression_Constant(1, 1);
- $node = new Twig_Node_Expression_Unary_Pos($node, 1);
+ $node = new \Twig\Node\Expression\ConstantExpression(1, 1);
+ $node = new \Twig\Node\Expression\Unary\PosUnary($node, 1);
return [
[$node, '+1'],
diff --git a/test/Twig/Tests/Node/ForTest.php b/test/Twig/Tests/Node/ForTest.php
index bfb4d0ceaf..5a065681ee 100644
--- a/test/Twig/Tests/Node/ForTest.php
+++ b/test/Twig/Tests/Node/ForTest.php
@@ -9,29 +9,29 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_ForTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_ForTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $keyTarget = new Twig_Node_Expression_AssignName('key', 1);
- $valueTarget = new Twig_Node_Expression_AssignName('item', 1);
- $seq = new Twig_Node_Expression_Name('items', 1);
- $ifexpr = new Twig_Node_Expression_Constant(true, 1);
- $body = new Twig_Node([new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1)], [], 1);
+ $keyTarget = new \Twig\Node\Expression\AssignNameExpression('key', 1);
+ $valueTarget = new \Twig\Node\Expression\AssignNameExpression('item', 1);
+ $seq = new \Twig\Node\Expression\NameExpression('items', 1);
+ $ifexpr = new \Twig\Node\Expression\ConstantExpression(true, 1);
+ $body = new \Twig\Node\Node([new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1)], [], 1);
$else = null;
- $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1);
+ $node = new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1);
$node->setAttribute('with_loop', false);
$this->assertEquals($keyTarget, $node->getNode('key_target'));
$this->assertEquals($valueTarget, $node->getNode('value_target'));
$this->assertEquals($seq, $node->getNode('seq'));
$this->assertTrue($node->getAttribute('ifexpr'));
- $this->assertInstanceOf('Twig_Node_If', $node->getNode('body'));
+ $this->assertInstanceOf('\Twig\Node\IfNode', $node->getNode('body'));
$this->assertEquals($body, $node->getNode('body')->getNode('tests')->getNode(1)->getNode(0));
$this->assertFalse($node->hasNode('else'));
- $else = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1);
- $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1);
+ $else = new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1);
+ $node = new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1);
$node->setAttribute('with_loop', false);
$this->assertEquals($else, $node->getNode('else'));
}
@@ -40,13 +40,13 @@ public function getTests()
{
$tests = [];
- $keyTarget = new Twig_Node_Expression_AssignName('key', 1);
- $valueTarget = new Twig_Node_Expression_AssignName('item', 1);
- $seq = new Twig_Node_Expression_Name('items', 1);
+ $keyTarget = new \Twig\Node\Expression\AssignNameExpression('key', 1);
+ $valueTarget = new \Twig\Node\Expression\AssignNameExpression('item', 1);
+ $seq = new \Twig\Node\Expression\NameExpression('items', 1);
$ifexpr = null;
- $body = new Twig_Node([new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1)], [], 1);
+ $body = new \Twig\Node\Node([new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1)], [], 1);
$else = null;
- $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1);
+ $node = new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1);
$node->setAttribute('with_loop', false);
$tests[] = [$node, <<setAttribute('with_loop', true);
$tests[] = [$node, <<setAttribute('with_loop', true);
$tests[] = [$node, <<setAttribute('with_loop', true);
$tests[] = [$node, <<assertEquals($t, $node->getNode('tests'));
$this->assertFalse($node->hasNode('else'));
- $else = new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1);
- $node = new Twig_Node_If($t, $else, 1);
+ $else = new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('bar', 1), 1);
+ $node = new \Twig\Node\IfNode($t, $else, 1);
$this->assertEquals($else, $node->getNode('else'));
}
@@ -32,12 +32,12 @@ public function getTests()
{
$tests = [];
- $t = new Twig_Node([
- new Twig_Node_Expression_Constant(true, 1),
- new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1),
+ $t = new \Twig\Node\Node([
+ new \Twig\Node\Expression\ConstantExpression(true, 1),
+ new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1),
], [], 1);
$else = null;
- $node = new Twig_Node_If($t, $else, 1);
+ $node = new \Twig\Node\IfNode($t, $else, 1);
$tests[] = [$node, <<assertEquals($macro, $node->getNode('expr'));
$this->assertEquals($var, $node->getNode('var'));
@@ -25,9 +25,9 @@ public function getTests()
{
$tests = [];
- $macro = new Twig_Node_Expression_Constant('foo.twig', 1);
- $var = new Twig_Node_Expression_AssignName('macro', 1);
- $node = new Twig_Node_Import($macro, $var, 1);
+ $macro = new \Twig\Node\Expression\ConstantExpression('foo.twig', 1);
+ $var = new \Twig\Node\Expression\AssignNameExpression('macro', 1);
+ $node = new \Twig\Node\ImportNode($macro, $var, 1);
$tests[] = [$node, <<assertFalse($node->hasNode('variables'));
$this->assertEquals($expr, $node->getNode('expr'));
$this->assertFalse($node->getAttribute('only'));
- $vars = new Twig_Node_Expression_Array([new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)], 1);
- $node = new Twig_Node_Include($expr, $vars, true, false, 1);
+ $vars = new \Twig\Node\Expression\ArrayExpression([new \Twig\Node\Expression\ConstantExpression('foo', 1), new \Twig\Node\Expression\ConstantExpression(true, 1)], 1);
+ $node = new \Twig\Node\IncludeNode($expr, $vars, true, false, 1);
$this->assertEquals($vars, $node->getNode('variables'));
$this->assertTrue($node->getAttribute('only'));
}
@@ -30,49 +30,49 @@ public function getTests()
{
$tests = [];
- $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
- $node = new Twig_Node_Include($expr, null, false, false, 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression('foo.twig', 1);
+ $node = new \Twig\Node\IncludeNode($expr, null, false, false, 1);
$tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(\$context);
EOF
];
- $expr = new Twig_Node_Expression_Conditional(
- new Twig_Node_Expression_Constant(true, 1),
- new Twig_Node_Expression_Constant('foo', 1),
- new Twig_Node_Expression_Constant('foo', 1),
+ $expr = new \Twig\Node\Expression\ConditionalExpression(
+ new \Twig\Node\Expression\ConstantExpression(true, 1),
+ new \Twig\Node\Expression\ConstantExpression('foo', 1),
+ new \Twig\Node\Expression\ConstantExpression('foo', 1),
0
);
- $node = new Twig_Node_Include($expr, null, false, false, 1);
+ $node = new \Twig\Node\IncludeNode($expr, null, false, false, 1);
$tests[] = [$node, <<loadTemplate(((true) ? ("foo") : ("foo")), null, 1)->display(\$context);
EOF
];
- $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
- $vars = new Twig_Node_Expression_Array([new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)], 1);
- $node = new Twig_Node_Include($expr, $vars, false, false, 1);
+ $expr = new \Twig\Node\Expression\ConstantExpression('foo.twig', 1);
+ $vars = new \Twig\Node\Expression\ArrayExpression([new \Twig\Node\Expression\ConstantExpression('foo', 1), new \Twig\Node\Expression\ConstantExpression(true, 1)], 1);
+ $node = new \Twig\Node\IncludeNode($expr, $vars, false, false, 1);
$tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, ["foo" => true]));
EOF
];
- $node = new Twig_Node_Include($expr, $vars, true, false, 1);
+ $node = new \Twig\Node\IncludeNode($expr, $vars, true, false, 1);
$tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(["foo" => true]);
EOF
];
- $node = new Twig_Node_Include($expr, $vars, true, true, 1);
+ $node = new \Twig\Node\IncludeNode($expr, $vars, true, true, 1);
$tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(["foo" => true]);
-} catch (Twig_Error_Loader \$e) {
+} catch (\Twig\Error\LoaderError \$e) {
// ignore missing template
}
EOF
diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php
index 69203f31f1..944532ca11 100644
--- a/test/Twig/Tests/Node/MacroTest.php
+++ b/test/Twig/Tests/Node/MacroTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_MacroTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $body = new Twig_Node_Text('foo', 1);
- $arguments = new Twig_Node([new Twig_Node_Expression_Name('foo', 1)], [], 1);
- $node = new Twig_Node_Macro('foo', $body, $arguments, 1);
+ $body = new \Twig\Node\TextNode('foo', 1);
+ $arguments = new \Twig\Node\Node([new \Twig\Node\Expression\NameExpression('foo', 1)], [], 1);
+ $node = new \Twig\Node\MacroNode('foo', $body, $arguments, 1);
$this->assertEquals($body, $node->getNode('body'));
$this->assertEquals($arguments, $node->getNode('arguments'));
@@ -24,12 +24,12 @@ public function testConstructor()
public function getTests()
{
- $body = new Twig_Node_Text('foo', 1);
- $arguments = new Twig_Node([
- 'foo' => new Twig_Node_Expression_Constant(null, 1),
- 'bar' => new Twig_Node_Expression_Constant('Foo', 1),
+ $body = new \Twig\Node\TextNode('foo', 1);
+ $arguments = new \Twig\Node\Node([
+ 'foo' => new \Twig\Node\Expression\ConstantExpression(null, 1),
+ 'bar' => new \Twig\Node\Expression\ConstantExpression('Foo', 1),
], [], 1);
- $node = new Twig_Node_Macro('foo', $body, $arguments, 1);
+ $node = new \Twig\Node\MacroNode('foo', $body, $arguments, 1);
if (PHP_VERSION_ID >= 50600) {
$declaration = ', ...$__varargs__';
@@ -65,7 +65,7 @@ public function getfoo(\$__foo__ = null, \$__bar__ = "Foo"$declaration)
throw \$e;
}
- return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
+ return ('' === \$tmp = ob_get_clean()) ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset());
}
EOF
],
diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php
index 07be195479..61c94a10a2 100644
--- a/test/Twig/Tests/Node/ModuleTest.php
+++ b/test/Twig/Tests/Node/ModuleTest.php
@@ -9,17 +9,17 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_ModuleTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_ModuleTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $body = new Twig_Node_Text('foo', 1);
- $parent = new Twig_Node_Expression_Constant('layout.twig', 1);
- $blocks = new Twig_Node();
- $macros = new Twig_Node();
- $traits = new Twig_Node();
- $source = new Twig_Source('{{ foo }}', 'foo.twig');
- $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $traits, new Twig_Node([]), $source);
+ $body = new \Twig\Node\TextNode('foo', 1);
+ $parent = new \Twig\Node\Expression\ConstantExpression('layout.twig', 1);
+ $blocks = new \Twig\Node\Node();
+ $macros = new \Twig\Node\Node();
+ $traits = new \Twig\Node\Node();
+ $source = new \Twig\Source('{{ foo }}', 'foo.twig');
+ $node = new \Twig\Node\ModuleNode($body, $parent, $blocks, $macros, $traits, new \Twig\Node\Node([]), $source);
$this->assertEquals($body, $node->getNode('body'));
$this->assertEquals($blocks, $node->getNode('blocks'));
@@ -30,25 +30,25 @@ public function testConstructor()
public function getTests()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
$tests = [];
- $body = new Twig_Node_Text('foo', 1);
+ $body = new \Twig\Node\TextNode('foo', 1);
$extends = null;
- $blocks = new Twig_Node();
- $macros = new Twig_Node();
- $traits = new Twig_Node();
- $source = new Twig_Source('{{ foo }}', 'foo.twig');
+ $blocks = new \Twig\Node\Node();
+ $macros = new \Twig\Node\Node();
+ $traits = new \Twig\Node\Node();
+ $source = new \Twig\Source('{{ foo }}', 'foo.twig');
- $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node([]), $source);
+ $node = new \Twig\Node\ModuleNode($body, $extends, $blocks, $macros, $traits, new \Twig\Node\Node([]), $source);
$tests[] = [$node, <<getMockBuilder('Twig_LoaderInterface')->getMock(), ['debug' => true]);
- $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node([]), $source);
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['debug' => true]);
+ $node = new \Twig\Node\ModuleNode($body, $extends, $blocks, $macros, $traits, new \Twig\Node\Node([]), $source);
$tests[] = [$node, <<assertEquals($expr, $node->getNode('expr'));
}
@@ -22,7 +22,7 @@ public function testConstructor()
public function getTests()
{
$tests = [];
- $tests[] = [new Twig_Node_Print(new Twig_Node_Expression_Constant('foo', 1), 1), "// line 1\necho \"foo\";"];
+ $tests[] = [new \Twig\Node\PrintNode(new \Twig\Node\Expression\ConstantExpression('foo', 1), 1), "// line 1\necho \"foo\";"];
return $tests;
}
diff --git a/test/Twig/Tests/Node/SandboxTest.php b/test/Twig/Tests/Node/SandboxTest.php
index 24297da1c3..bfb3613913 100644
--- a/test/Twig/Tests/Node/SandboxTest.php
+++ b/test/Twig/Tests/Node/SandboxTest.php
@@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_SandboxTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_SandboxTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $body = new Twig_Node_Text('foo', 1);
- $node = new Twig_Node_Sandbox($body, 1);
+ $body = new \Twig\Node\TextNode('foo', 1);
+ $node = new \Twig\Node\SandboxNode($body, 1);
$this->assertEquals($body, $node->getNode('body'));
}
@@ -23,12 +23,12 @@ public function getTests()
{
$tests = [];
- $body = new Twig_Node_Text('foo', 1);
- $node = new Twig_Node_Sandbox($body, 1);
+ $body = new \Twig\Node\TextNode('foo', 1);
+ $node = new \Twig\Node\SandboxNode($body, 1);
$tests[] = [$node, <<env->getExtension('Twig_Extension_Sandbox');
+\$sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');
if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {
\$sandbox->enableSandbox();
}
diff --git a/test/Twig/Tests/Node/SandboxedPrintTest.php b/test/Twig/Tests/Node/SandboxedPrintTest.php
index 61b69b279b..be593400fa 100644
--- a/test/Twig/Tests/Node/SandboxedPrintTest.php
+++ b/test/Twig/Tests/Node/SandboxedPrintTest.php
@@ -9,11 +9,11 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_SandboxedPrintTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_SandboxedPrintTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $node = new Twig_Node_SandboxedPrint($expr = new Twig_Node_Expression_Constant('foo', 1), 1);
+ $node = new \Twig\Node\SandboxedPrintNode($expr = new \Twig\Node\Expression\ConstantExpression('foo', 1), 1);
$this->assertEquals($expr, $node->getNode('expr'));
}
@@ -22,9 +22,9 @@ public function getTests()
{
$tests = [];
- $tests[] = [new Twig_Node_SandboxedPrint(new Twig_Node_Expression_Constant('foo', 1), 1), <<env->getExtension('Twig_Extension_Sandbox')->ensureToStringAllowed("foo");
+echo \$this->env->getExtension('\Twig\Extension\SandboxExtension')->ensureToStringAllowed("foo");
EOF
];
diff --git a/test/Twig/Tests/Node/SetTest.php b/test/Twig/Tests/Node/SetTest.php
index e09583f8c0..d1b12d620e 100644
--- a/test/Twig/Tests/Node/SetTest.php
+++ b/test/Twig/Tests/Node/SetTest.php
@@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_SetTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_SetTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $names = new Twig_Node([new Twig_Node_Expression_AssignName('foo', 1)], [], 1);
- $values = new Twig_Node([new Twig_Node_Expression_Constant('foo', 1)], [], 1);
- $node = new Twig_Node_Set(false, $names, $values, 1);
+ $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1)], [], 1);
+ $values = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression('foo', 1)], [], 1);
+ $node = new \Twig\Node\SetNode(false, $names, $values, 1);
$this->assertEquals($names, $node->getNode('names'));
$this->assertEquals($values, $node->getNode('values'));
@@ -26,38 +26,38 @@ public function getTests()
{
$tests = [];
- $names = new Twig_Node([new Twig_Node_Expression_AssignName('foo', 1)], [], 1);
- $values = new Twig_Node([new Twig_Node_Expression_Constant('foo', 1)], [], 1);
- $node = new Twig_Node_Set(false, $names, $values, 1);
+ $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1)], [], 1);
+ $values = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression('foo', 1)], [], 1);
+ $node = new \Twig\Node\SetNode(false, $names, $values, 1);
$tests[] = [$node, <<env->getCharset());
+\$context["foo"] = ('' === \$tmp = ob_get_clean()) ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset());
EOF
];
- $names = new Twig_Node([new Twig_Node_Expression_AssignName('foo', 1)], [], 1);
- $values = new Twig_Node_Text('foo', 1);
- $node = new Twig_Node_Set(true, $names, $values, 1);
+ $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1)], [], 1);
+ $values = new \Twig\Node\TextNode('foo', 1);
+ $node = new \Twig\Node\SetNode(true, $names, $values, 1);
$tests[] = [$node, <<env->getCharset());
+\$context["foo"] = ('' === \$tmp = "foo") ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset());
EOF
];
- $names = new Twig_Node([new Twig_Node_Expression_AssignName('foo', 1), new Twig_Node_Expression_AssignName('bar', 1)], [], 1);
- $values = new Twig_Node([new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Name('bar', 1)], [], 1);
- $node = new Twig_Node_Set(false, $names, $values, 1);
+ $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1), new \Twig\Node\Expression\AssignNameExpression('bar', 1)], [], 1);
+ $values = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression('foo', 1), new \Twig\Node\Expression\NameExpression('bar', 1)], [], 1);
+ $node = new \Twig\Node\SetNode(false, $names, $values, 1);
$tests[] = [$node, <<getVariableGetter('bar')}];
diff --git a/test/Twig/Tests/Node/SpacelessTest.php b/test/Twig/Tests/Node/SpacelessTest.php
index c7e5fb6565..4cb5f996e7 100644
--- a/test/Twig/Tests/Node/SpacelessTest.php
+++ b/test/Twig/Tests/Node/SpacelessTest.php
@@ -9,20 +9,20 @@
* file that was distributed with this source code.
*/
-class Twig_Tests_Node_SpacelessTest extends Twig_Test_NodeTestCase
+class Twig_Tests_Node_SpacelessTest extends \Twig\Test\NodeTestCase
{
public function testConstructor()
{
- $body = new Twig_Node([new Twig_Node_Text('', 1)]);
- $node = new Twig_Node_Spaceless($body, 1);
+ $body = new \Twig\Node\Node([new \Twig\Node\TextNode('', 1)]);
+ $node = new \Twig\Node\SpacelessNode($body, 1);
$this->assertEquals($body, $node->getNode('body'));
}
public function getTests()
{
- $body = new Twig_Node([new Twig_Node_Text('', 1)]);
- $node = new Twig_Node_Spaceless($body, 1);
+ $body = new \Twig\Node\Node([new \Twig\Node\TextNode('', 1)]);
+ $node = new \Twig\Node\SpacelessNode($body, 1);
return [
[$node, <<assertEquals('foo', $node->getAttribute('data'));
}
@@ -21,7 +21,7 @@ public function testConstructor()
public function getTests()
{
$tests = [];
- $tests[] = [new Twig_Node_Text('foo', 1), "// line 1\necho \"foo\";"];
+ $tests[] = [new \Twig\Node\TextNode('foo', 1), "// line 1\necho \"foo\";"];
return $tests;
}
diff --git a/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/test/Twig/Tests/NodeVisitor/OptimizerTest.php
index 1f8f9dba1e..0f5d2e347d 100644
--- a/test/Twig/Tests/NodeVisitor/OptimizerTest.php
+++ b/test/Twig/Tests/NodeVisitor/OptimizerTest.php
@@ -12,25 +12,25 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase
{
public function testRenderBlockOptimizer()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $stream = $env->parse($env->tokenize(new Twig_Source('{{ block("foo") }}', 'index')));
+ $stream = $env->parse($env->tokenize(new \Twig\Source('{{ block("foo") }}', 'index')));
$node = $stream->getNode('body')->getNode(0);
- $this->assertInstanceOf('Twig_Node_Expression_BlockReference', $node);
+ $this->assertInstanceOf('\Twig\Node\Expression\BlockReferenceExpression', $node);
$this->assertTrue($node->getAttribute('output'));
}
public function testRenderParentBlockOptimizer()
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $stream = $env->parse($env->tokenize(new Twig_Source('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index')));
+ $stream = $env->parse($env->tokenize(new \Twig\Source('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index')));
$node = $stream->getNode('blocks')->getNode('content')->getNode(0)->getNode('body');
- $this->assertInstanceOf('Twig_Node_Expression_Parent', $node);
+ $this->assertInstanceOf('\Twig\Node\Expression\ParentExpression', $node);
$this->assertTrue($node->getAttribute('output'));
}
@@ -40,12 +40,12 @@ public function testRenderVariableBlockOptimizer()
$this->markTestSkipped('not needed on PHP >= 5.4');
}
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
- $stream = $env->parse($env->tokenize(new Twig_Source('{{ block(name|lower) }}', 'index')));
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]);
+ $stream = $env->parse($env->tokenize(new \Twig\Source('{{ block(name|lower) }}', 'index')));
$node = $stream->getNode('body')->getNode(0)->getNode(1);
- $this->assertInstanceOf('Twig_Node_Expression_BlockReference', $node);
+ $this->assertInstanceOf('\Twig\Node\Expression\BlockReferenceExpression', $node);
$this->assertTrue($node->getAttribute('output'));
}
@@ -54,9 +54,9 @@ public function testRenderVariableBlockOptimizer()
*/
public function testForOptimizer($template, $expected)
{
- $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['cache' => false]);
+ $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false]);
- $stream = $env->parse($env->tokenize(new Twig_Source($template, 'index')));
+ $stream = $env->parse($env->tokenize(new \Twig\Source($template, 'index')));
foreach ($expected as $target => $withLoop) {
$this->assertTrue($this->checkForConfiguration($stream, $target, $withLoop), sprintf('variable %s is %soptimized', $target, $withLoop ? 'not ' : ''));
@@ -109,7 +109,7 @@ public function checkForConfiguration(Twig_NodeInterface $node = null, $target,
}
foreach ($node as $n) {
- if ($n instanceof Twig_Node_For) {
+ if ($n instanceof \Twig\Node\ForNode) {
if ($target === $n->getNode('value_target')->getAttribute('name')) {
return $withLoop == $n->getAttribute('with_loop');
}
diff --git a/test/Twig/Tests/ParserTest.php b/test/Twig/Tests/ParserTest.php
index 2180200b70..4f8299eb57 100644
--- a/test/Twig/Tests/ParserTest.php
+++ b/test/Twig/Tests/ParserTest.php
@@ -11,43 +11,43 @@
class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase
{
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
*/
public function testSetMacroThrowsExceptionOnReservedMethods()
{
$parser = $this->getParser();
- $parser->setMacro('parent', $this->getMockBuilder('Twig_Node_Macro')->disableOriginalConstructor()->getMock());
+ $parser->setMacro('parent', $this->getMockBuilder('\Twig\Node\MacroNode')->disableOriginalConstructor()->getMock());
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown "foo" tag. Did you mean "for" at line 1?
*/
public function testUnknownTag()
{
- $stream = new Twig_TokenStream([
- new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1),
- new Twig_Token(Twig_Token::NAME_TYPE, 'foo', 1),
- new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1),
- new Twig_Token(Twig_Token::EOF_TYPE, '', 1),
+ $stream = new \Twig\TokenStream([
+ new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::NAME_TYPE, 'foo', 1),
+ new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1),
]);
- $parser = new Twig_Parser(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $parser = new \Twig\Parser(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
$parser->parse($stream);
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unknown "foobar" tag at line 1.
*/
public function testUnknownTagWithoutSuggestions()
{
- $stream = new Twig_TokenStream([
- new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1),
- new Twig_Token(Twig_Token::NAME_TYPE, 'foobar', 1),
- new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1),
- new Twig_Token(Twig_Token::EOF_TYPE, '', 1),
+ $stream = new \Twig\TokenStream([
+ new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::NAME_TYPE, 'foobar', 1),
+ new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1),
]);
- $parser = new Twig_Parser(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $parser = new \Twig\Parser(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
$parser->parse($stream);
}
@@ -65,15 +65,15 @@ public function getFilterBodyNodesData()
{
return [
[
- new Twig_Node([new Twig_Node_Text(' ', 1)]),
- new Twig_Node([]),
+ new \Twig\Node\Node([new \Twig\Node\TextNode(' ', 1)]),
+ new \Twig\Node\Node([]),
],
[
- $input = new Twig_Node([new Twig_Node_Set(false, new Twig_Node(), new Twig_Node(), 1)]),
+ $input = new \Twig\Node\Node([new \Twig\Node\SetNode(false, new \Twig\Node\Node(), new \Twig\Node\Node(), 1)]),
$input,
],
[
- $input = new Twig_Node([new Twig_Node_Set(true, new Twig_Node(), new Twig_Node([new Twig_Node([new Twig_Node_Text('foo', 1)])]), 1)]),
+ $input = new \Twig\Node\Node([new \Twig\Node\SetNode(true, new \Twig\Node\Node(), new \Twig\Node\Node([new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)])]), 1)]),
$input,
],
];
@@ -81,7 +81,7 @@ public function getFilterBodyNodesData()
/**
* @dataProvider getFilterBodyNodesDataThrowsException
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
*/
public function testFilterBodyNodesThrowsException($input)
{
@@ -93,8 +93,8 @@ public function testFilterBodyNodesThrowsException($input)
public function getFilterBodyNodesDataThrowsException()
{
return [
- [new Twig_Node_Text('foo', 1)],
- [new Twig_Node([new Twig_Node([new Twig_Node_Text('foo', 1)])])],
+ [new \Twig\Node\TextNode('foo', 1)],
+ [new \Twig\Node\Node([new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)])])],
];
}
@@ -103,7 +103,7 @@ public function getFilterBodyNodesDataThrowsException()
*/
public function testFilterBodyNodesWithBOM($emptyNode)
{
- $this->assertNull($this->getParser()->filterBodyNodes(new Twig_Node_Text(\chr(0xEF).\chr(0xBB).\chr(0xBF).$emptyNode, 1)));
+ $this->assertNull($this->getParser()->filterBodyNodes(new \Twig\Node\TextNode(\chr(0xEF).\chr(0xBB).\chr(0xBF).$emptyNode, 1)));
}
public function getFilterBodyNodesWithBOMData()
@@ -118,22 +118,22 @@ public function getFilterBodyNodesWithBOMData()
public function testParseIsReentrant()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), [
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), [
'autoescape' => false,
'optimizations' => 0,
]);
$twig->addTokenParser(new TestTokenParser());
- $parser = new Twig_Parser($twig);
+ $parser = new \Twig\Parser($twig);
- $parser->parse(new Twig_TokenStream([
- new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1),
- new Twig_Token(Twig_Token::NAME_TYPE, 'test', 1),
- new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1),
- new Twig_Token(Twig_Token::VAR_START_TYPE, '', 1),
- new Twig_Token(Twig_Token::NAME_TYPE, 'foo', 1),
- new Twig_Token(Twig_Token::VAR_END_TYPE, '', 1),
- new Twig_Token(Twig_Token::EOF_TYPE, '', 1),
+ $parser->parse(new \Twig\TokenStream([
+ new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::NAME_TYPE, 'test', 1),
+ new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::VAR_START_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::NAME_TYPE, 'foo', 1),
+ new \Twig\Token(\Twig\Token::VAR_END_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1),
]));
$this->assertNull($parser->getParent());
@@ -141,12 +141,12 @@ public function testParseIsReentrant()
public function testGetVarName()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), [
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), [
'autoescape' => false,
'optimizations' => 0,
]);
- $twig->parse($twig->tokenize(new Twig_Source(<<parse($twig->tokenize(new \Twig\Source(<<getMockBuilder('Twig_LoaderInterface')->getMock()));
- $parser->setParent(new Twig_Node());
- $parser->stream = new Twig_TokenStream([]);
+ $parser = new TestParser(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
+ $parser->setParent(new \Twig\Node\Node());
+ $parser->stream = new \Twig\TokenStream([]);
return $parser;
}
}
-class TestParser extends Twig_Parser
+class TestParser extends \Twig\Parser
{
public $stream;
@@ -181,22 +181,22 @@ public function filterBodyNodes(Twig_NodeInterface $node)
}
}
-class TestTokenParser extends Twig_TokenParser
+class TestTokenParser extends \Twig\TokenParser\AbstractTokenParser
{
- public function parse(Twig_Token $token)
+ public function parse(\Twig\Token $token)
{
// simulate the parsing of another template right in the middle of the parsing of the current template
- $this->parser->parse(new Twig_TokenStream([
- new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1),
- new Twig_Token(Twig_Token::NAME_TYPE, 'extends', 1),
- new Twig_Token(Twig_Token::STRING_TYPE, 'base', 1),
- new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1),
- new Twig_Token(Twig_Token::EOF_TYPE, '', 1),
+ $this->parser->parse(new \Twig\TokenStream([
+ new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::NAME_TYPE, 'extends', 1),
+ new \Twig\Token(\Twig\Token::STRING_TYPE, 'base', 1),
+ new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1),
+ new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1),
]));
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
- return new Twig_Node([]);
+ return new \Twig\Node\Node([]);
}
public function getTag()
diff --git a/test/Twig/Tests/Profiler/Dumper/AbstractTest.php b/test/Twig/Tests/Profiler/Dumper/AbstractTest.php
index ed3797b48c..62f3821cfe 100644
--- a/test/Twig/Tests/Profiler/Dumper/AbstractTest.php
+++ b/test/Twig/Tests/Profiler/Dumper/AbstractTest.php
@@ -13,7 +13,7 @@ abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends \PHPUnit\Framewor
{
protected function getProfile()
{
- $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock();
+ $profile = $this->getMockBuilder('\Twig\Profiler\Profile')->disableOriginalConstructor()->getMock();
$profile->expects($this->any())->method('isRoot')->will($this->returnValue(true));
$profile->expects($this->any())->method('getName')->will($this->returnValue('main'));
@@ -79,11 +79,11 @@ private function getMacroProfile(array $subProfiles = [])
* @param string $templateName
* @param array $subProfiles
*
- * @return Twig_Profiler_Profile
+ * @return \Twig\Profiler\Profile
*/
private function generateProfile($name, $duration, $isTemplate, $type, $templateName, array $subProfiles = [])
{
- $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock();
+ $profile = $this->getMockBuilder('\Twig\Profiler\Profile')->disableOriginalConstructor()->getMock();
$profile->expects($this->any())->method('isRoot')->will($this->returnValue(false));
$profile->expects($this->any())->method('getName')->will($this->returnValue($name));
diff --git a/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php b/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php
index 1a1b9d299b..23846630e6 100644
--- a/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php
+++ b/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php
@@ -13,7 +13,7 @@ class Twig_Tests_Profiler_Dumper_BlackfireTest extends Twig_Tests_Profiler_Dumpe
{
public function testDump()
{
- $dumper = new Twig_Profiler_Dumper_Blackfire();
+ $dumper = new \Twig\Profiler\Dumper\BlackfireDumper();
$this->assertStringMatchesFormat(<<assertStringMatchesFormat(<<main %d.%dms/%d%
└ index.twig %d.%dms/%d%
diff --git a/test/Twig/Tests/Profiler/Dumper/TextTest.php b/test/Twig/Tests/Profiler/Dumper/TextTest.php
index e2ea165ace..fbd7475c00 100644
--- a/test/Twig/Tests/Profiler/Dumper/TextTest.php
+++ b/test/Twig/Tests/Profiler/Dumper/TextTest.php
@@ -13,7 +13,7 @@ class Twig_Tests_Profiler_Dumper_TextTest extends Twig_Tests_Profiler_Dumper_Abs
{
public function testDump()
{
- $dumper = new Twig_Profiler_Dumper_Text();
+ $dumper = new \Twig\Profiler\Dumper\TextDumper();
$this->assertStringMatchesFormat(<<assertEquals('template', $profile->getTemplate());
$this->assertEquals('type', $profile->getType());
@@ -22,45 +22,45 @@ public function testConstructor()
public function testIsRoot()
{
- $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
+ $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT);
$this->assertTrue($profile->isRoot());
- $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::TEMPLATE);
+ $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::TEMPLATE);
$this->assertFalse($profile->isRoot());
}
public function testIsTemplate()
{
- $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::TEMPLATE);
+ $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::TEMPLATE);
$this->assertTrue($profile->isTemplate());
- $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
+ $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT);
$this->assertFalse($profile->isTemplate());
}
public function testIsBlock()
{
- $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::BLOCK);
+ $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::BLOCK);
$this->assertTrue($profile->isBlock());
- $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
+ $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT);
$this->assertFalse($profile->isBlock());
}
public function testIsMacro()
{
- $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::MACRO);
+ $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::MACRO);
$this->assertTrue($profile->isMacro());
- $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
+ $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT);
$this->assertFalse($profile->isMacro());
}
public function testGetAddProfile()
{
- $profile = new Twig_Profiler_Profile();
- $profile->addProfile($a = new Twig_Profiler_Profile());
- $profile->addProfile($b = new Twig_Profiler_Profile());
+ $profile = new \Twig\Profiler\Profile();
+ $profile->addProfile($a = new \Twig\Profiler\Profile());
+ $profile->addProfile($b = new \Twig\Profiler\Profile());
$this->assertSame([$a, $b], $profile->getProfiles());
$this->assertSame([$a, $b], iterator_to_array($profile));
@@ -68,7 +68,7 @@ public function testGetAddProfile()
public function testGetDuration()
{
- $profile = new Twig_Profiler_Profile();
+ $profile = new \Twig\Profiler\Profile();
usleep(1);
$profile->leave();
@@ -77,8 +77,8 @@ public function testGetDuration()
public function testSerialize()
{
- $profile = new Twig_Profiler_Profile('template', 'type', 'name');
- $profile1 = new Twig_Profiler_Profile('template1', 'type1', 'name1');
+ $profile = new \Twig\Profiler\Profile('template', 'type', 'name');
+ $profile1 = new \Twig\Profiler\Profile('template1', 'type1', 'name1');
$profile->addProfile($profile1);
$profile->leave();
$profile1->leave();
@@ -100,7 +100,7 @@ public function testSerialize()
public function testReset()
{
- $profile = new Twig_Profiler_Profile();
+ $profile = new \Twig\Profiler\Profile();
usleep(1);
$profile->leave();
$profile->reset();
diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php
index 16a01a3573..eb499d4d48 100644
--- a/test/Twig/Tests/TemplateTest.php
+++ b/test/Twig/Tests/TemplateTest.php
@@ -15,7 +15,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase
*/
public function testDisplayBlocksAcceptTemplateOnlyAsBlocks()
{
- $template = $this->getMockForAbstractClass('Twig_Template', [], '', false);
+ $template = $this->getMockForAbstractClass('\Twig\Template', [], '', false);
$template->displayBlock('foo', [], ['foo' => [new \stdClass(), 'foo']]);
}
@@ -25,7 +25,7 @@ public function testDisplayBlocksAcceptTemplateOnlyAsBlocks()
public function testGetAttributeExceptions($template, $message)
{
$templates = ['index' => $template];
- $env = new Twig_Environment(new Twig_Loader_Array($templates), ['strict_variables' => true]);
+ $env = new \Twig\Environment(new \Twig\Loader\ArrayLoader($templates), ['strict_variables' => true]);
$template = $env->loadTemplate('index');
$context = [
@@ -41,7 +41,7 @@ public function testGetAttributeExceptions($template, $message)
try {
$template->render($context);
$this->fail('Accessing an invalid attribute should throw an exception.');
- } catch (Twig_Error_Runtime $e) {
+ } catch (\Twig\Error\RuntimeError $e) {
$this->assertSame(sprintf($message, 'index'), $e->getMessage());
}
}
@@ -74,9 +74,9 @@ public function getAttributeExceptions()
*/
public function testGetAttributeWithSandbox($object, $item, $allowed)
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $policy = new Twig_Sandbox_SecurityPolicy([], [], [/*method*/], [/*prop*/], []);
- $twig->addExtension(new Twig_Extension_Sandbox($policy, !$allowed));
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
+ $policy = new \Twig\Sandbox\SecurityPolicy([], [], [/*method*/], [/*prop*/], []);
+ $twig->addExtension(new \Twig\Extension\SandboxExtension($policy, !$allowed));
$template = new Twig_TemplateTest($twig);
try {
@@ -87,7 +87,7 @@ public function testGetAttributeWithSandbox($object, $item, $allowed)
} else {
$this->addToAssertionCount(1);
}
- } catch (Twig_Sandbox_SecurityError $e) {
+ } catch (\Twig\Sandbox\SecurityError $e) {
if ($allowed) {
$this->fail();
} else {
@@ -114,28 +114,28 @@ public function getGetAttributeWithSandbox()
public function testGetAttributeWithTemplateAsObject()
{
// to be removed in 2.0
- $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
- //$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
+ //$twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface')->getMock());
$template = new Twig_TemplateTest($twig, 'index.twig');
$template1 = new Twig_TemplateTest($twig, 'index1.twig');
- $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'string'));
+ $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'string'));
$this->assertEquals('some_string', $template->getAttribute($template1, 'string'));
- $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'true'));
+ $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'true'));
$this->assertEquals('1', $template->getAttribute($template1, 'true'));
- $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'zero'));
+ $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'zero'));
$this->assertEquals('0', $template->getAttribute($template1, 'zero'));
- $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty'));
+ $this->assertNotInstanceof('\Twig\Markup', $template->getAttribute($template1, 'empty'));
$this->assertSame('', $template->getAttribute($template1, 'empty'));
- $this->assertFalse($template->getAttribute($template1, 'env', [], Twig_Template::ANY_CALL, true));
- $this->assertFalse($template->getAttribute($template1, 'environment', [], Twig_Template::ANY_CALL, true));
- $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], Twig_Template::METHOD_CALL, true));
- $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], Twig_Template::METHOD_CALL, true));
+ $this->assertFalse($template->getAttribute($template1, 'env', [], \Twig\Template::ANY_CALL, true));
+ $this->assertFalse($template->getAttribute($template1, 'environment', [], \Twig\Template::ANY_CALL, true));
+ $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], \Twig\Template::METHOD_CALL, true));
+ $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], \Twig\Template::METHOD_CALL, true));
}
/**
@@ -162,22 +162,22 @@ public function testGetAttributeWithTemplateAsObject()
public function testGetAttributeWithTemplateAsObjectForDeprecations()
{
// to be removed in 2.0
- $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
- //$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
+ //$twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface')->getMock());
$template = new Twig_TemplateTest($twig, 'index.twig');
$template1 = new Twig_TemplateTest($twig, 'index1.twig');
- $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'string'));
+ $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'string'));
$this->assertEquals('some_string', $template->getAttribute($template1, 'string'));
- $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'true'));
+ $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'true'));
$this->assertEquals('1', $template->getAttribute($template1, 'true'));
- $this->assertInstanceOf('Twig_Markup', $template->getAttribute($template1, 'zero'));
+ $this->assertInstanceOf('\Twig\Markup', $template->getAttribute($template1, 'zero'));
$this->assertEquals('0', $template->getAttribute($template1, 'zero'));
- $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty'));
+ $this->assertNotInstanceof('\Twig\Markup', $template->getAttribute($template1, 'empty'));
$this->assertSame('', $template->getAttribute($template1, 'empty'));
$blocks = ['name' => [$template1, 'block_name']];
@@ -195,10 +195,10 @@ public function testGetAttributeWithTemplateAsObjectForDeprecations()
$template->getAttribute($template1, 'render', [[]]);
$template->getAttribute($template1, 'display', [[]]);
- $this->assertFalse($template->getAttribute($template1, 'env', [], Twig_Template::ANY_CALL, true));
- $this->assertFalse($template->getAttribute($template1, 'environment', [], Twig_Template::ANY_CALL, true));
- $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], Twig_Template::METHOD_CALL, true));
- $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], Twig_Template::METHOD_CALL, true));
+ $this->assertFalse($template->getAttribute($template1, 'env', [], \Twig\Template::ANY_CALL, true));
+ $this->assertFalse($template->getAttribute($template1, 'environment', [], \Twig\Template::ANY_CALL, true));
+ $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], \Twig\Template::METHOD_CALL, true));
+ $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], \Twig\Template::METHOD_CALL, true));
}
/**
@@ -208,7 +208,7 @@ public function testGetAttributeWithTemplateAsObjectForDeprecations()
*/
public function testRenderBlockWithUndefinedBlock()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
+ $twig = new \Twig\Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
$template = new Twig_TemplateTest($twig, 'index.twig');
$template->renderBlock('unknown', []);
@@ -217,7 +217,7 @@ public function testRenderBlockWithUndefinedBlock()
public function testGetAttributeOnArrayWithConfusableKey()
{
- $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
$array = ['Zero', 'One', -1 => 'MinusOne', '' => 'EmptyString', '1.5' => 'FloatButString', '01' => 'IntegerButStringWithLeadingZeros'];
@@ -245,7 +245,7 @@ public function testGetAttributeOnArrayWithConfusableKey()
*/
public function testGetAttribute($defined, $value, $object, $item, $arguments, $type)
{
- $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
$this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type));
}
@@ -255,18 +255,18 @@ public function testGetAttribute($defined, $value, $object, $item, $arguments, $
*/
public function testGetAttributeStrict($defined, $value, $object, $item, $arguments, $type, $exceptionMessage = null)
{
- $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => true]));
+ $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true]));
if ($defined) {
$this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type));
} else {
if (method_exists($this, 'expectException')) {
- $this->expectException('Twig_Error_Runtime');
+ $this->expectException('\Twig\Error\RuntimeError');
if (null !== $exceptionMessage) {
$this->expectExceptionMessage($exceptionMessage);
}
} else {
- $this->setExpectedException('Twig_Error_Runtime', $exceptionMessage);
+ $this->setExpectedException('\Twig\Error\RuntimeError', $exceptionMessage);
}
$this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type));
}
@@ -277,7 +277,7 @@ public function testGetAttributeStrict($defined, $value, $object, $item, $argume
*/
public function testGetAttributeDefined($defined, $value, $object, $item, $arguments, $type)
{
- $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
$this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true));
}
@@ -287,14 +287,14 @@ public function testGetAttributeDefined($defined, $value, $object, $item, $argum
*/
public function testGetAttributeDefinedStrict($defined, $value, $object, $item, $arguments, $type)
{
- $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => true]));
+ $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true]));
$this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true));
}
public function testGetAttributeCallExceptions()
{
- $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()));
$object = new Twig_TemplateMagicMethodExceptionObject();
@@ -325,9 +325,9 @@ public function getGetAttributeTests()
$methodObject = new Twig_TemplateMethodObject();
$magicMethodObject = new Twig_TemplateMagicMethodObject();
- $anyType = Twig_Template::ANY_CALL;
- $methodType = Twig_Template::METHOD_CALL;
- $arrayType = Twig_Template::ARRAY_CALL;
+ $anyType = \Twig\Template::ANY_CALL;
+ $methodType = \Twig\Template::METHOD_CALL;
+ $arrayType = \Twig\Template::ARRAY_CALL;
$basicTests = [
// array(defined, value, property to fetch)
@@ -434,12 +434,12 @@ public function getGetAttributeTests()
}
/**
- * @expectedException \Twig_Error_Runtime
+ * @expectedException \Twig\Error\RuntimeError
*/
public function testGetIsMethods()
{
$getIsObject = new Twig_TemplateGetIsMethods();
- $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), ['strict_variables' => true]));
+ $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true]));
// first time should not create a cache for "get"
$this->assertNull($template->getAttribute($getIsObject, 'get'));
// 0 should be in the method cache now, so this should fail
@@ -447,11 +447,11 @@ public function testGetIsMethods()
}
}
-class Twig_TemplateTest extends Twig_Template
+class Twig_TemplateTest extends \Twig\Template
{
private $name;
- public function __construct(Twig_Environment $env, $name = 'index.twig')
+ public function __construct(\Twig\Environment $env, $name = 'index.twig')
{
parent::__construct($env);
self::$cache = [];
@@ -497,7 +497,7 @@ protected function doDisplay(array $context, array $blocks = [])
{
}
- public function getAttribute($object, $item, array $arguments = [], $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
+ public function getAttribute($object, $item, array $arguments = [], $type = \Twig\Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
{
if (\function_exists('twig_template_get_attributes')) {
return twig_template_get_attributes($this, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
@@ -771,18 +771,18 @@ public function __call($method, $arguments)
}
}
-class CExtDisablingNodeVisitor implements Twig_NodeVisitorInterface
+class CExtDisablingNodeVisitor implements \Twig\NodeVisitor\NodeVisitorInterface
{
- public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
+ public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env)
{
- if ($node instanceof Twig_Node_Expression_GetAttr) {
+ if ($node instanceof \Twig\Node\Expression\GetAttrExpression) {
$node->setAttribute('disable_c_ext', true);
}
return $node;
}
- public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
+ public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env)
{
return $node;
}
@@ -794,6 +794,6 @@ public function getPriority()
}
// to be removed in 2.0
-interface Twig_TemplateTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface
+interface Twig_TemplateTestLoaderInterface extends \Twig\Loader\LoaderInterface, Twig_SourceContextLoaderInterface
{
}
diff --git a/test/Twig/Tests/TemplateWrapperTest.php b/test/Twig/Tests/TemplateWrapperTest.php
index 0e7833ed11..68646e80fb 100644
--- a/test/Twig/Tests/TemplateWrapperTest.php
+++ b/test/Twig/Tests/TemplateWrapperTest.php
@@ -12,7 +12,7 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase
{
public function testHasGetBlocks()
{
- $twig = new Twig_Environment(new Twig_Loader_Array([
+ $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([
'index' => '{% block foo %}{% endblock %}',
'index_with_use' => '{% use "imported" %}{% block foo %}{% endblock %}',
'index_with_extends' => '{% extends "extended" %}{% block foo %}{% endblock %}',
@@ -20,17 +20,17 @@ public function testHasGetBlocks()
'extended' => '{% block extended %}{% endblock %}',
]));
- $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index'));
+ $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index'));
$this->assertTrue($wrapper->hasBlock('foo'));
$this->assertFalse($wrapper->hasBlock('bar'));
$this->assertEquals(['foo'], $wrapper->getBlockNames());
- $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index_with_use'));
+ $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index_with_use'));
$this->assertTrue($wrapper->hasBlock('foo'));
$this->assertTrue($wrapper->hasBlock('imported'));
$this->assertEquals(['imported', 'foo'], $wrapper->getBlockNames());
- $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index_with_extends'));
+ $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index_with_extends'));
$this->assertTrue($wrapper->hasBlock('foo'));
$this->assertTrue($wrapper->hasBlock('extended'));
$this->assertEquals(['foo', 'extended'], $wrapper->getBlockNames());
@@ -38,23 +38,23 @@ public function testHasGetBlocks()
public function testRenderBlock()
{
- $twig = new Twig_Environment(new Twig_Loader_Array([
+ $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([
'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}',
]));
$twig->addGlobal('bar', 'BAR');
- $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index'));
+ $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index'));
$this->assertEquals('FOOBAR', $wrapper->renderBlock('foo', ['foo' => 'FOO']));
}
public function testDisplayBlock()
{
- $twig = new Twig_Environment(new Twig_Loader_Array([
+ $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([
'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}',
]));
$twig->addGlobal('bar', 'BAR');
- $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index'));
+ $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index'));
ob_start();
$wrapper->displayBlock('foo', ['foo' => 'FOO']);
diff --git a/test/Twig/Tests/TokenStreamTest.php b/test/Twig/Tests/TokenStreamTest.php
index 1867b42989..a7f4d181c3 100644
--- a/test/Twig/Tests/TokenStreamTest.php
+++ b/test/Twig/Tests/TokenStreamTest.php
@@ -16,14 +16,14 @@ class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase
protected function setUp()
{
self::$tokens = [
- new Twig_Token(Twig_Token::TEXT_TYPE, 1, 1),
- new Twig_Token(Twig_Token::TEXT_TYPE, 2, 1),
- new Twig_Token(Twig_Token::TEXT_TYPE, 3, 1),
- new Twig_Token(Twig_Token::TEXT_TYPE, 4, 1),
- new Twig_Token(Twig_Token::TEXT_TYPE, 5, 1),
- new Twig_Token(Twig_Token::TEXT_TYPE, 6, 1),
- new Twig_Token(Twig_Token::TEXT_TYPE, 7, 1),
- new Twig_Token(Twig_Token::EOF_TYPE, 0, 1),
+ new \Twig\Token(\Twig\Token::TEXT_TYPE, 1, 1),
+ new \Twig\Token(\Twig\Token::TEXT_TYPE, 2, 1),
+ new \Twig\Token(\Twig\Token::TEXT_TYPE, 3, 1),
+ new \Twig\Token(\Twig\Token::TEXT_TYPE, 4, 1),
+ new \Twig\Token(\Twig\Token::TEXT_TYPE, 5, 1),
+ new \Twig\Token(\Twig\Token::TEXT_TYPE, 6, 1),
+ new \Twig\Token(\Twig\Token::TEXT_TYPE, 7, 1),
+ new \Twig\Token(\Twig\Token::EOF_TYPE, 0, 1),
];
}
@@ -32,7 +32,7 @@ protected function setUp()
*/
public function testLegacyConstructorSignature()
{
- $stream = new Twig_TokenStream([], 'foo', '{{ foo }}');
+ $stream = new \Twig\TokenStream([], 'foo', '{{ foo }}');
$this->assertEquals('foo', $stream->getFilename());
$this->assertEquals('{{ foo }}', $stream->getSource());
$this->assertEquals('foo', $stream->getSourceContext()->getName());
@@ -41,7 +41,7 @@ public function testLegacyConstructorSignature()
public function testNext()
{
- $stream = new Twig_TokenStream(self::$tokens);
+ $stream = new \Twig\TokenStream(self::$tokens);
$repr = [];
while (!$stream->isEOF()) {
$token = $stream->next();
@@ -52,13 +52,13 @@ public function testNext()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unexpected end of template
*/
public function testEndOfTemplateNext()
{
- $stream = new Twig_TokenStream([
- new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1),
+ $stream = new \Twig\TokenStream([
+ new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, 1, 1),
]);
while (!$stream->isEOF()) {
$stream->next();
@@ -66,13 +66,13 @@ public function testEndOfTemplateNext()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unexpected end of template
*/
public function testEndOfTemplateLook()
{
- $stream = new Twig_TokenStream([
- new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1),
+ $stream = new \Twig\TokenStream([
+ new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, 1, 1),
]);
while (!$stream->isEOF()) {
$stream->look();
diff --git a/test/Twig/Tests/Util/DeprecationCollectorTest.php b/test/Twig/Tests/Util/DeprecationCollectorTest.php
index 1d0ff01760..5d72f94074 100644
--- a/test/Twig/Tests/Util/DeprecationCollectorTest.php
+++ b/test/Twig/Tests/Util/DeprecationCollectorTest.php
@@ -16,10 +16,10 @@ class Twig_Tests_Util_DeprecationCollectorTest extends \PHPUnit\Framework\TestCa
*/
public function testCollect()
{
- $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $twig->addFunction(new Twig_SimpleFunction('deprec', [$this, 'deprec'], ['deprecated' => true]));
+ $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
+ $twig->addFunction(new \Twig\TwigFunction('deprec', [$this, 'deprec'], ['deprecated' => true]));
- $collector = new Twig_Util_DeprecationCollector($twig);
+ $collector = new \Twig\Util\DeprecationCollector($twig);
$deprecations = $collector->collect(new Twig_Tests_Util_Iterator());
$this->assertEquals(['Twig Function "deprec" is deprecated in deprec.twig at line 1.'], $deprecations);
diff --git a/test/Twig/Tests/escapingTest.php b/test/Twig/Tests/escapingTest.php
index 7bbd92cfed..6de31a9354 100644
--- a/test/Twig/Tests/escapingTest.php
+++ b/test/Twig/Tests/escapingTest.php
@@ -151,7 +151,7 @@ class Twig_Test_EscapingTest extends \PHPUnit\Framework\TestCase
protected function setUp()
{
- $this->env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $this->env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
}
public function testHtmlEscapingConvertsSpecialChars()