From 54eeec215ad6324e25005d8639f17e1708c6f0c4 Mon Sep 17 00:00:00 2001 From: rawsrc Date: Wed, 27 Oct 2021 09:47:04 +0200 Subject: [PATCH] Add 2 new helpers: - assertIsNotInstanceOf() - assertNotException() --- Pilot.php | 2 ++ README.md | 8 +++----- stdExacodisHelpers.php | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Pilot.php b/Pilot.php index 1bc9a91..c237f3e 100644 --- a/Pilot.php +++ b/Pilot.php @@ -28,6 +28,8 @@ * @method assertIsString() * @method assertIsInstanceOf(object|string $class) * @method assertException(object|string $class = 'Exception') + * @method assertIsNotInstanceOf(object|string $class) + * @method assertNotException(object|string $class = 'Exception') * @method assertNotEqual(mixed $to) * @method assertNotIn(array $values) * @method assertNotInStrict(array $values) diff --git a/README.md b/README.md index 79bfc8c..dfa1dff 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # **Exacodis** -`2021-10-22` `PHP 8.0+` `v.1.1.0` +`2021-10-27` `PHP 8.0+` `v.1.1.1` ## **A PHP TEST ENGINE** @@ -23,10 +23,8 @@ override a test run or a result nor a resource.
If you do, then the code will fail with an `Exception` until you fix the code. **CHANGELOG** -1. Code improvements -2. Better report data -3. Does not break the compatibility with the previous version -4. Add a new method `assert()` to the `Pilot` class that simplifies the writing of totally dynamic tests +1. Add 2 new helpers : `assertIsNotInstanceOf()` and `assertNotException()` +2. Does not break the compatibility with the previous version **HOW TO USE** diff --git a/stdExacodisHelpers.php b/stdExacodisHelpers.php index 1c1ff85..c020871 100644 --- a/stdExacodisHelpers.php +++ b/stdExacodisHelpers.php @@ -151,6 +151,31 @@ $helpers['assertException'] = $exception; //endregion +//region not is instance of +$not_iof = function(object|string $class, string $test_name = 'notInstanceOf') { + /** @var Pilot $this */ + if (is_string($class)) { + if (is_a($this->current_runner->getResult(), $class)) { + $this->addFailure(expected: $test_name.': '.$class); + } else { + $this->addSuccess($test_name); + } + } elseif ($this->current_runner->getResult() instanceof $class) { + $this->addFailure(expected: $test_name.': '.$class::class); + } else { + $this->addSuccess($test_name); + } +}; +$helpers['assertIsNotInstanceOf'] = $not_iof; +//endregion + +//region not an exception +$not_an_exception = function(object|string $class = 'Exception') use ($not_iof) { + $not_iof($class, 'notException'); +}; +$helpers['assertNotException'] = $not_an_exception; +//endregion + //region in $in = function(array $values) { /** @var Pilot $this */