Fixed function parameter order

Corrected $places default value for addFunction to match TokenFactory
Added function order test and put expected order first in assertEquals
If else blocks in calculator
Updated docs
This commit is contained in:
Bruce Wells 2019-01-15 18:36:10 -05:00
parent 0437f808f2
commit 265cff175e

View file

@ -138,7 +138,11 @@ class MathTest extends \PHPUnit_Framework_TestCase
{
$calculator = new MathExecutor();
$calculator->addFunction('concat', function ($arg1, $arg2) {return $arg1.$arg2;});
$calculator->addFunction('concat', function ($arg1, $arg2)
{
return $arg1.$arg2;
}
);
$this->assertEquals('testing', $calculator->execute('concat("test","ing")'));
$this->assertEquals('testing', $calculator->execute("concat('test','ing')"));
}
@ -147,19 +151,19 @@ class MathTest extends \PHPUnit_Framework_TestCase
{
$calculator = new MathExecutor();
$calculator->addFunction('round', function ($arg) {return round($arg);});
/** @var float $phpResult */
eval('$phpResult = round(100/30);');
$this->assertEquals($phpResult, $calculator->execute('round(100/30)'));
$this->assertEquals(round(100/30), $calculator->execute('round(100/30)'));
}
public function testQuotes()
{
$calculator = new MathExecutor();
$testString = "some, long. arg; with: different-separators!";
$calculator->addFunction('test', function ($arg) use ($testString) {
$this->assertEquals($testString, $arg);
return 0;}
);
$calculator->addFunction('test', function ($arg) use ($testString)
{
$this->assertEquals($testString, $arg);
return 0;
}
);
$calculator->execute('test("' . $testString . '")'); // single quotes
$calculator->execute("test('" . $testString . "')"); // double quotes
}