aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruce Wells <brucekwells@gmail.com>2022-03-21 19:52:25 +0300
committerGitHub <noreply@github.com>2022-03-21 19:52:25 +0300
commita0ff7a79af8c3bc5e9c5decee24cbefb5d80e93b (patch)
tree9432edb4d427293952ed99f48968b8ad32f6633a /tests
parent6ebe4849ff7448d5903914d2f8980af5c9fd8d34 (diff)
Adding varExists method and support for undefined var handler in getVar (#96)V2.1.112.0.4
* Added varExists method * getVar now respects VarNotFoundHandler setting * Use local version of PHP-CS-Fixer Instead of hard coded version from github actions * Fixing actions * Fixing actions * Dropping testing for 7.3, as it is no longer supported
Diffstat (limited to 'tests')
-rw-r--r--tests/MathTest.php45
1 files changed, 30 insertions, 15 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index 426e514..3eca351 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -58,17 +58,17 @@ class MathTest extends TestCase
['(4*2) - 5'],
['4*-5'],
['4 * -5'],
- ['+5'],
- ['+(3+2)'],
- ['+(+3+2)'],
- ['+(-3+2)'],
- ['-5'],
- ['-(-5)'],
- ['-(+5)'],
- ['+(-5)'],
- ['+(+5)'],
- ['-(3+2)'],
- ['-(-3+-2)'],
+ ['+5'],
+ ['+(3+2)'],
+ ['+(+3+2)'],
+ ['+(-3+2)'],
+ ['-5'],
+ ['-(-5)'],
+ ['-(+5)'],
+ ['+(-5)'],
+ ['+(+5)'],
+ ['-(3+2)'],
+ ['-(-3+-2)'],
['abs(1.5)'],
['acos(0.15)'],
@@ -499,6 +499,15 @@ class MathTest extends TestCase
}
);
$this->assertEquals(15, $calculator->execute('5 * undefined'));
+ $this->assertEquals(3, $calculator->getVar('undefined'));
+ $this->assertNull($calculator->getVar('Lucy'));
+ }
+
+ public function testGetVarException()
+ {
+ $calculator = new MathExecutor();
+ $this->expectException(UnknownVariableException::class);
+ $this->assertNull($calculator->getVar('Lucy'));
}
public function testMinusZero()
@@ -580,6 +589,15 @@ class MathTest extends TestCase
$calculator->setVar('resource', tmpfile());
}
+ public function testVarExists()
+ {
+ $calculator = new MathExecutor();
+ $varName = 'Eythel';
+ $calculator->setVar($varName, 1);
+ $this->assertTrue($calculator->varExists($varName));
+ $this->assertFalse($calculator->varExists('Lucy'));
+ }
+
/**
* @dataProvider providerExpressionValues
*/
@@ -662,8 +680,5 @@ class MathTest extends TestCase
$this->assertEquals(2048, $calculator->execute('2 ^ 11', false));
$this->assertEquals(0, count($calculator->getCache()));
-
-
}
-
-} \ No newline at end of file
+}