8000 [TwigBridge] fix tests · symfony/symfony@1f15395 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f15395

Browse files
committed
[TwigBridge] fix tests
Adapt tests for null coalescing support from twigphp/Twig#2238.
1 parent 6648615 commit 1f15395

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ public function testOneVar()
8080
}
8181

8282
EOTXT;
83-
$expected = preg_replace('/%(.*?)%/', PHP_VERSION_ID >= 50400 ? '(isset($context["$1"]) ? $context["$1"] : null)' : '$this->getContext($context, "$1")', $expected);
83+
if (PHP_VERSION_ID >= 70000) {
84+
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
85+
} elseif (PHP_VERSION_ID >= 50400) {
86+
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
87+
} else {
88+
$expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected);
89+
}
8490

8591
$this->assertSame($expected, $compiler->compile($node)->getSource());
8692
}
@@ -106,7 +112,14 @@ public function testMultiVars()
106112
}
107113

108114
EOTXT;
109-
$expected = preg_replace('/%(.*?)%/', PHP_VERSION_ID >= 50400 ? '(isset($context["$1"]) ? $context["$1"] : null)' : '$this->getContext($context, "$1")', $expected);
115+
116+
if (PHP_VERSION_ID >= 70000) {
117+
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
118+
} elseif (PHP_VERSION_ID >= 50400) {
119+
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
120+
} else {
121+
$expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected);
122+
}
110123

111124
$this->assertSame($expected, $compiler->compile($node)->getSource());
112125
}

src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public function testCompile()
6666

6767
protected function getVariableGetter($name)
6868
{
69+
if (PHP_VERSION_ID >= 70000) {
70+
return sprintf('($context["%s"] ?? null)', $name, $name);
71+
}
72+
6973
if (PHP_VERSION_ID >= 50400) {
7074
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
7175
}

src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
263263

264264
protected function getVariableGetter($name)
265265
{
266+
if (PHP_VERSION_ID >= 70000) {
267+
return sprintf('($context["%s"] ?? null)', $name, $name);
268+
}
269+
266270
if (PHP_VERSION_ID >= 50400) {
267271
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
268272
}

src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public function testCompileStrict()
3939

4040
protected function getVariableGetterWithoutStrictCheck($name)
4141
{
42+
if (PHP_VERSION_ID >= 70000) {
43+
return sprintf('($context["%s"] ?? null)', $name, $name);
44+
}
45+
4246
if (PHP_VERSION_ID >= 50400) {
4347
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
4448
}
@@ -48,10 +52,14 @@ protected function getVariableGetterWithoutStrictCheck($name)
4852

4953
protected function getVariableGetterWithStrictCheck($name)
5054
{
51-
if (version_compare(\Twig_Environment::VERSION, '2.0.0-DEV', '>=')) {
55+
if (\Twig_Environment::MAJOR_VERSION >= 2) {
5256
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : $this->notFound("%s", 0))', $name, $name, $name, $name);
5357
}
5458

59+
if (PHP_VERSION_ID >= 70000) {
60+
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
61+
}
62+
5563
if (PHP_VERSION_ID >= 50400) {
5664
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
5765
}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20-
"twig/twig": "~1.27|~2.0"
20+
"twig/twig": "~1.28|~2.0"
2121
},
2222
"require-dev": {
2323
"symfony/asset": "~2.7",

0 commit comments

Comments
 (0)
0