Skip to content

Commit

Permalink
Improved unit tests (#74)
Browse files Browse the repository at this point in the history
* Variable fixes (#67)

* Reproduce if throws UnknownOperatorException

* Fix variable detection

* Adding IncorrectNumberOfFunctionParametersException

* Removing tabs

* Better exception message text

* Handler for not found variables (#68)

* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic

* Release prep (#69)

* String comparison unit tests

* getVars and getFunctions sanity checks

* Add dynamic variable documentation

* Better setVar error message (#70)

Additional unit tests
Readme update

* Improved support for null variables (#72)

* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic

* Better support for null variables

* Better support for null variables

* Better support for null variables

* Allow null values in `setVar` method (#73)

* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic

* Better support for null variables

* Better support for null variables

* Better support for null variables

* Allow null values in `setVar` method

* Better unit testing

Co-authored-by: Javier Marín <[email protected]>
  • Loading branch information
phpfui and javiermarinros authored Sep 16, 2020
1 parent 8aa6674 commit d9eb39e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tests/MathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testCalculating($expression)
*
* Most tests can go in here. The idea is that each expression will be evaluated by MathExecutor and by PHP with eval.
* The results should be the same. If they are not, then the test fails. No need to add extra test unless you are doing
* something more complete and not a simple mathmatical expression.
* something more complex and not a simple mathmatical expression.
*/
public function providerExpressions()
{
Expand Down Expand Up @@ -501,25 +501,25 @@ public function testSetVarsAcceptsAllScalars()
$calculator->setVar('boolTrue', true);
$calculator->setVar('boolFalse', false);
$calculator->setVar('int', 1);
$calculator->setVar('null', null);
$calculator->setVar('float', 1.1);
$calculator->setVar('string', 'string');
$this->assertEquals(7, count($calculator->getVars()));
$this->assertEquals(8, count($calculator->getVars()));
$this->assertEquals(true, $calculator->getVar('boolTrue'));
$this->assertEquals(false, $calculator->getVar('boolFalse'));
$this->assertEquals(1, $calculator->getVar('int'));
$this->assertEquals(null, $calculator->getVar('null'));
$this->assertEquals(1.1, $calculator->getVar('float'));
$this->assertEquals('string', $calculator->getVar('string'));
}

public function testSetVarsDoesNoAcceptObject()
public function testSetVarsDoesNotAcceptObject()
{
$calculator = new MathExecutor();
$this->expectException(MathExecutorException::class);
$calculator->setVar('object', $this);
}

public function testSetVarsDoesNotAcceptNull()
{
$calculator = new MathExecutor();
$this->expectException(MathExecutorException::class);
$calculator->setVar('null', null);
}

public function testSetVarsDoesNotAcceptResource()
{
$calculator = new MathExecutor();
Expand Down

0 comments on commit d9eb39e

Please sign in to comment.