Skip to content

Commit

Permalink
minor #20511 [TwigBridge] fix tests (xabbuh)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Nov 14, 2016
2 parents 6648615 + 1f15395 commit 9a66470
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ public function testOneVar()
}

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());
}
Expand All @@ -106,7 +112,14 @@ public function testMultiVars()
}

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());
}
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public function testCompile()

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()

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);
}
Expand Down
10 changes: 9 additions & 1 deletion src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function testCompileStrict()

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);
}
Expand All @@ -48,10 +52,14 @@ protected function getVariableGetterWithoutStrictCheck($name)

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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9a66470

Please sign in to comment.