minor #20511 [TwigBridge] fix tests (xabbuh)
This PR was merged into the 2.7 branch.
Discussion
----------
[TwigBridge] fix tests
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Adapt tests for null coalescing support from twigphp/Twig#2238.
Commits
-------
1f15395
[TwigBridge] fix tests
This commit is contained in:
commit
9a66470116
@ -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());
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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",
|
||||
|
Reference in New Issue
Block a user