aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/NXP/MathExecutor.php2
-rw-r--r--tests/MathTest.php10
2 files changed, 11 insertions, 1 deletions
diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php
index 7eaa914..f348355 100644
--- a/src/NXP/MathExecutor.php
+++ b/src/NXP/MathExecutor.php
@@ -164,7 +164,7 @@ class MathExecutor
* @param int $places Count of arguments
* @return MathExecutor
*/
- public function addFunction($name, callable $function = null, $places = 1)
+ public function addFunction($name, $function = null, $places = 1)
{
$this->tokenFactory->addFunction($name, $function, $places);
diff --git a/tests/MathTest.php b/tests/MathTest.php
index 1b96ee2..2b2727f 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -62,4 +62,14 @@ class MathTest extends \PHPUnit_Framework_TestCase
array('100500 * 3.5E-5')
);
}
+
+ public function testFunction()
+ {
+ $calculator = new MathExecutor();
+
+ $calculator->addFunction('round', function ($arg) { return round($arg); }, 1);
+ /** @var float $phpResult */
+ eval('$phpResult = round(100/30);');
+ $this->assertEquals($calculator->execute('round(100/30)'), $phpResult);
+ }
} \ No newline at end of file