1<?php 2 3/* 4 * This file is part of Twig. 5 * 6 * (c) Fabien Potencier 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12use Twig\Node\Expression\ConstantExpression; 13use Twig\Node\Expression\NameExpression; 14use Twig\Node\Expression\NullCoalesceExpression; 15use Twig\Test\NodeTestCase; 16 17class Twig_Tests_Node_Expression_NullCoalesceTest extends NodeTestCase 18{ 19 public function getTests() 20 { 21 $tests = []; 22 23 $left = new NameExpression('foo', 1); 24 $right = new ConstantExpression(2, 1); 25 $node = new NullCoalesceExpression($left, $right, 1); 26 if (PHP_VERSION_ID >= 70000) { 27 $tests[] = [$node, "((// line 1\n\$context[\"foo\"]) ?? (2))"]; 28 } elseif (PHP_VERSION_ID >= 50400) { 29 $tests[] = [$node, "(((// line 1\n(isset(\$context[\"foo\"]) || array_key_exists(\"foo\", \$context)) && !(null === (isset(\$context[\"foo\"]) ? \$context[\"foo\"] : null)))) ? ((isset(\$context[\"foo\"]) ? \$context[\"foo\"] : null)) : (2))"]; 30 } else { 31 $tests[] = [$node, "(((// line 1\n(isset(\$context[\"foo\"]) || array_key_exists(\"foo\", \$context)) && !(null === \$this->getContext(\$context, \"foo\")))) ? (\$this->getContext(\$context, \"foo\")) : (2))"]; 32 } 33 34 return $tests; 35 } 36} 37