File tree 4 files changed +68
-0
lines changed
Filter options
4 files changed +68
-0
lines changed
Original file line number Diff line number Diff line change @@ -287,4 +287,11 @@ function (ExpressionLanguage $el) {
287
287
],
288
288
];
289
289
}
290
+
291
+ public function testParseAlreadyParsedExpressionReturnsSameObject ()
292
+ {
293
+ $ el = new ExpressionLanguage ();
294
+ $ parsed = $ el ->parse ('1 + 1 ' , []);
295
+ $ this ->assertSame ($ parsed , $ el ->parse ($ parsed , []));
296
+ }
290
297
}
Original file line number Diff line number Diff line change @@ -207,4 +207,24 @@ public function testCompileMatchesWithInvalidRegexpAsExpression()
207
207
$ node ->compile ($ compiler );
208
208
eval ('$regexp = "this is not a regexp"; ' .$ compiler ->getSource ().'; ' );
209
209
}
210
+
211
+ public function testDivisionByZero ()
212
+ {
213
+ $ node = new BinaryNode ('/ ' , new ConstantNode (1 ), new ConstantNode (0 ));
214
+
215
+ $ this ->expectException (\DivisionByZeroError::class);
216
+ $ this ->expectExceptionMessage ('Division by zero. ' );
217
+
218
+ $ node ->evaluate ([], []);
219
+ }
220
+
221
+ public function testModuloByZero ()
222
+ {
223
+ $ node = new BinaryNode ('% ' , new ConstantNode (1 ), new ConstantNode (0 ));
224
+
225
+ $ this ->expectException (\DivisionByZeroError::class);
226
+ $ this ->expectExceptionMessage ('Modulo by zero. ' );
227
+
228
+ $ node ->evaluate ([], []);
229
+ }
210
230
}
Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \ExpressionLanguage \Tests \Node ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \ExpressionLanguage \Compiler ;
15
16
use Symfony \Component \ExpressionLanguage \Node \ConstantNode ;
16
17
use Symfony \Component \ExpressionLanguage \Node \Node ;
17
18
@@ -38,4 +39,33 @@ public function testSerialization()
38
39
39
40
$ this ->assertEquals ($ node , $ unserializedNode );
40
41
}
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
+ }
41
71
}
Original file line number Diff line number Diff line change @@ -37,6 +37,17 @@ public function testParseWithZeroInNames()
37
37
$ parser ->parse ($ lexer ->tokenize ('foo ' ), [0 ]);
38
38
}
39
39
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
+
40
51
/**
41
52
* @dataProvider getParseData
42
53
*/
You can’t perform that action at this time.
0 commit comments