Skip to content

Commit b9e4bc6

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: (23 commits) fix tests using Twig 3.12 skip tests requiring the intl extension if it's not installed 🐛 throw ParseException on invalid date fix permitted data type of the default choice [ExpressionLanguage] Improve test coverage Fix invalid phpdoc in ContainerBuilder [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon [Form] NumberType: Fix parsing of numbers in exponential notation with negative exponent [Security] consistent singular/plural translation in Dutch reset the validation context after validating nested constraints do not duplicate directory separators fix handling empty data in ValueToDuplicatesTransformer fix compatibility with redis extension 6.0.3+ synchronize unsupported scheme tests [String] Fixed Quorum plural, that was inflected to be only "Quora" and never "Quorums" Fix symfony/kaz-info-teh-notifier package [Validator] review latvian translations [Validator] Add Dutch translation for `WordCount` constraint allow more unicode characters in URL paths [String][EnglishInflector] Fix words ending in 'le', e.g., articles ...
2 parents 463cb95 + 564e109 commit b9e4bc6

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

Tests/ExpressionLanguageTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,11 @@ function (ExpressionLanguage $el) {
496496
],
497497
];
498498
}
499+
500+
public function testParseAlreadyParsedExpressionReturnsSameObject()
501+
{
502+
$el = new ExpressionLanguage();
503+
$parsed = $el->parse('1 + 1', []);
504+
$this->assertSame($parsed, $el->parse($parsed, []));
505+
}
499506
}

Tests/Node/BinaryNodeTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,26 @@ public function testCompileMatchesWithInvalidRegexpAsExpression()
215215
eval('$regexp = "this is not a regexp"; '.$compiler->getSource().';');
216216
}
217217

218+
public function testDivisionByZero()
219+
{
220+
$node = new BinaryNode('/', new ConstantNode(1), new ConstantNode(0));
221+
222+
$this->expectException(\DivisionByZeroError::class);
223+
$this->expectExceptionMessage('Division by zero.');
224+
225+
$node->evaluate([], []);
226+
}
227+
228+
public function testModuloByZero()
229+
{
230+
$node = new BinaryNode('%', new ConstantNode(1), new ConstantNode(0));
231+
232+
$this->expectException(\DivisionByZeroError::class);
233+
$this->expectExceptionMessage('Modulo by zero.');
234+
235+
$node->evaluate([], []);
236+
}
237+
218238
/**
219239
* @testWith [1]
220240
* ["true"]

Tests/Node/NodeTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\ExpressionLanguage\Tests\Node;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\ExpressionLanguage\Compiler;
1516
use Symfony\Component\ExpressionLanguage\Node\ConstantNode;
1617
use Symfony\Component\ExpressionLanguage\Node\Node;
1718

@@ -38,4 +39,33 @@ public function testSerialization()
3839

3940
$this->assertEquals($node, $unserializedNode);
4041
}
42+
43+
public function testCompileActuallyCompilesAllNodes()
44+
{
45+
$nodes = [];
46+
foreach (range(1, 10) as $ignored) {
47+
$node = $this->createMock(Node::class);
48+
$node->expects($this->once())->method('compile');
49+
50+
$nodes[] = $node;
51+
}
52+
53+
$node = new Node($nodes);
54+
$node->compile($this->createMock(Compiler::class));
55+
}
56+
57+
public function testEvaluateActuallyEvaluatesAllNodes()
58+
{
59+
$nodes = [];
60+
foreach (range(1, 3) as $i) {
61+
$node = $this->createMock(Node::class);
62+
$node->expects($this->once())->method('evaluate')
63+
->willReturn($i);
64+
65+
$nodes[] = $node;
66+
}
67+
68+
$node = new Node($nodes);
69+
$this->assertSame([1, 2, 3], $node->evaluate([], []));
70+
}
4171
}

Tests/ParserTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ public function testParseWithZeroInNames()
3737
$parser->parse($lexer->tokenize('foo'), [0]);
3838
}
3939

40+
public function testParsePrimaryExpressionWithUnknownFunctionThrows()
41+
{
42+
$parser = new Parser([]);
43+
$stream = (new Lexer())->tokenize('foo()');
44+
45+
$this->expectException(SyntaxError::class);
46+
$this->expectExceptionMessage('The function "foo" does not exist around position 1 for expression `foo()`.');
47+
48+
$parser->parse($stream);
49+
}
50+
4051
public function testParseUnknownFunction()
4152
{
4253
$parser = new Parser([]);

0 commit comments

Comments
 (0)