aboutsummaryrefslogtreecommitdiff
path: root/tests/MathTest.php
diff options
context:
space:
mode:
authorMatthijs Meulenbrug <mrm@users.noreply.github.com>2022-04-25 17:50:51 +0300
committerGitHub <noreply@github.com>2022-04-25 17:50:51 +0300
commitef82911187771e56c8987af5bf03d331cc533fde (patch)
treec1f0454c302b23bbe17f497c8ff75966686d1d59 /tests/MathTest.php
parenta0ff7a79af8c3bc5e9c5decee24cbefb5d80e93b (diff)
Add a custom variable validator + protected props (#98)
Diffstat (limited to 'tests/MathTest.php')
-rw-r--r--tests/MathTest.php15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index 3eca351..14de2bf 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -589,6 +589,21 @@ class MathTest extends TestCase
$calculator->setVar('resource', tmpfile());
}
+ public function testSetCustomVarValidator()
+ {
+ $calculator = new MathExecutor();
+ $calculator->setVarValidationHandler(function ($name, $variable) {
+ if ($name === 'invalidVar' && $variable === 'invalid') {
+ throw new MathExecutorException("Invalid variable");
+ }
+ });
+
+ $calculator->setVar('valid', $this);
+
+ $this->expectException(MathExecutorException::class);
+ $calculator->setVar('invalidVar', 'invalid');
+ }
+
public function testVarExists()
{
$calculator = new MathExecutor();