From 9538001a42988507a29aa55eef7f59f0462665ab Mon Sep 17 00:00:00 2001 From: madman-81 <50033071+madman-81@users.noreply.github.com> Date: Thu, 4 Aug 2022 14:07:41 +0200 Subject: Throw an IncorrectNumberOfFunctionParametersException if a function gets more arguments than it supports (#117) * Throw an IncorrectNumberOfFunctionParametersException if a function gets more arguments than it supports * Update CustomFunction.php Code Style Co-authored-by: Bruce Wells --- tests/MathTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/MathTest.php') diff --git a/tests/MathTest.php b/tests/MathTest.php index 94a14d4..59ce207 100644 --- a/tests/MathTest.php +++ b/tests/MathTest.php @@ -674,6 +674,16 @@ class MathTest extends TestCase $calculator->execute('myfunc(1)'); } + public function testFunctionIncorrectNumberOfParametersTooMany() : void + { + $calculator = new MathExecutor(); + $this->expectException(IncorrectNumberOfFunctionParametersException::class); + $calculator->addFunction('myfunc', static function($arg1, $arg2) { + return $arg1 + $arg2; + }); + $calculator->execute('myfunc(1,2,3)'); + } + public function testFunctionIf() : void { $calculator = new MathExecutor(); -- cgit v1.2.3