@@ -26,7 +26,7 @@ class MathTest extends TestCase
2626 /**
2727 * @dataProvider providerExpressions
2828 */
29- public function testCalculating ($ expression ) : void
29+ public function testCalculating (string $ expression ) : void
3030 {
3131 $ calculator = new MathExecutor ();
3232
@@ -250,18 +250,47 @@ public function providerExpressions()
250250 ];
251251 }
252252
253- public function testUnknownFunctionException () : void
253+ /**
254+ * @dataProvider incorrectExpressions
255+ */
256+ public function testIncorrectExpressionException (string $ expression ) : void
254257 {
255258 $ 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+ ];
258287 }
259288
260- public function testIncorrectExpressionException () : void
289+ public function testUnknownFunctionException () : void
261290 {
262291 $ calculator = new MathExecutor ();
263- $ this ->expectException (IncorrectExpressionException ::class);
264- $ calculator ->execute ('1 * + ' );
292+ $ this ->expectException (UnknownFunctionException ::class);
293+ $ calculator ->execute ('1 * fred("wilma") + 3 ' );
265294 }
266295
267296 public function testZeroDivision () : void
0 commit comments