Skip to content

Commit

Permalink
Add 2 new helpers:
Browse files Browse the repository at this point in the history
- assertIsNotInstanceOf()
- assertNotException()
  • Loading branch information
rawsrc committed Oct 27, 2021
1 parent c78e401 commit 54eeec2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Pilot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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**

Expand All @@ -23,10 +23,8 @@ override a test run or a result nor a resource.<br>
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**

Expand Down
25 changes: 25 additions & 0 deletions stdExacodisHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 54eeec2

Please sign in to comment.