[TwigBridge] fix tests

Adapt tests for null coalescing support from twigphp/Twig#2238.
This commit is contained in:
Christian Flothmann 2016-11-14 08:52:03 +01:00
parent 6648615081
commit 1f1539579c
5 changed files with 33 additions and 4 deletions

View File

@ -80,7 +80,13 @@ if ($this->env->isDebug()) {
}
EOTXT;
$expected = preg_replace('/%(.*?)%/', PHP_VERSION_ID >= 50400 ? '(isset($context["$1"]) ? $context["$1"] : null)' : '$this->getContext($context, "$1")', $expected);
if (PHP_VERSION_ID >= 70000) {
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
} elseif (PHP_VERSION_ID >= 50400) {
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
} else {
$expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected);
}
$this->assertSame($expected, $compiler->compile($node)->getSource());
}
@ -106,7 +112,14 @@ if ($this->env->isDebug()) {
}
EOTXT;
$expected = preg_replace('/%(.*?)%/', PHP_VERSION_ID >= 50400 ? '(isset($context["$1"]) ? $context["$1"] : null)' : '$this->getContext($context, "$1")', $expected);
if (PHP_VERSION_ID >= 70000) {
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
} elseif (PHP_VERSION_ID >= 50400) {
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
} else {
$expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected);
}
$this->assertSame($expected, $compiler->compile($node)->getSource());
}

View File

@ -66,6 +66,10 @@ class FormThemeTest extends \PHPUnit_Framework_TestCase
protected function getVariableGetter($name)
{
if (PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? null)', $name, $name);
}
if (PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}

View File

@ -263,6 +263,10 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase
protected function getVariableGetter($name)
{
if (PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? null)', $name, $name);
}
if (PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}

View File

@ -39,6 +39,10 @@ class TransNodeTest extends \PHPUnit_Framework_TestCase
protected function getVariableGetterWithoutStrictCheck($name)
{
if (PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? null)', $name, $name);
}
if (PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}
@ -48,10 +52,14 @@ class TransNodeTest extends \PHPUnit_Framework_TestCase
protected function getVariableGetterWithStrictCheck($name)
{
if (version_compare(\Twig_Environment::VERSION, '2.0.0-DEV', '>=')) {
if (\Twig_Environment::MAJOR_VERSION >= 2) {
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : $this->notFound("%s", 0))', $name, $name, $name, $name);
}
if (PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
}
if (PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
}

View File

@ -17,7 +17,7 @@
],
"require": {
"php": ">=5.3.9",
"twig/twig": "~1.27|~2.0"
"twig/twig": "~1.28|~2.0"
},
"require-dev": {
"symfony/asset": "~2.7",