From ef82911187771e56c8987af5bf03d331cc533fde Mon Sep 17 00:00:00 2001 From: Matthijs Meulenbrug Date: Mon, 25 Apr 2022 16:50:51 +0200 Subject: Add a custom variable validator + protected props (#98) --- tests/MathTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') 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(); -- cgit v1.2.3