@@ -26,7 +26,7 @@ class MathTest extends TestCase
26
26
/**
27
27
* @dataProvider providerExpressions
28
28
*/
29
- public function testCalculating ($ expression ) : void
29
+ public function testCalculating (string $ expression ) : void
30
30
{
31
31
$ calculator = new MathExecutor ();
32
32
@@ -250,18 +250,47 @@ public function providerExpressions()
250
250
];
251
251
}
252
252
253
- public function testUnknownFunctionException () : void
253
+ /**
254
+ * @dataProvider incorrectExpressions
255
+ */
256
+ public function testIncorrectExpressionException (string $ expression ) : void
254
257
{
255
258
$ calculator = new MathExecutor ();
256
- $ this ->expectException (UnknownFunctionException::class);
257
- $ calculator ->execute ('1 * fred("wilma") + 3 ' );
259
+ $ calculator ->setVars (['a ' => 12 , 'b ' => 24 ]);
260
+ $ this ->expectException (IncorrectExpressionException::class);
261
+ $ calculator ->execute ($ expression );
262
+ }
263
+
264
+ /**
265
+ * Incorrect Expressions data provider
266
+ *
267
+ * These expressions should not pass validation
268
+ */
269
+ public function incorrectExpressions ()
270
+ {
271
+ return [
272
+ ['1 * + ' ],
273
+ [' 2 3 ' ],
274
+ ['2 3 ' ],
275
+ [' 2 4 3 ' ],
276
+ ['$a $b ' ],
277
+ ['$a [3, 4, 5] ' ],
278
+ ['$a (3 + 4) ' ],
279
+ ['$a "string" ' ],
280
+ ['5 "string" ' ],
281
+ ['"string" $a ' ],
282
+ ['$a round(12.345) ' ],
283
+ ['round(12.345) $a ' ],
284
+ ['4 round(12.345) ' ],
285
+ ['round(12.345) 4 ' ],
286
+ ];
258
287
}
259
288
260
- public function testIncorrectExpressionException () : void
289
+ public function testUnknownFunctionException () : void
261
290
{
262
291
$ calculator = new MathExecutor ();
263
- $ this ->expectException (IncorrectExpressionException ::class);
264
- $ calculator ->execute ('1 * + ' );
292
+ $ this ->expectException (UnknownFunctionException ::class);
293
+ $ calculator ->execute ('1 * fred("wilma") + 3 ' );
265
294
}
266
295
267
296
public function testZeroDivision () : void
0 commit comments