Skip to content

Commit

Permalink
(feature) changed exception to throwable to be more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
troublete committed Feb 8, 2018
1 parent 8796506 commit aaf8132
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ $assertions->predictException(function () {

#### `predictException($capture, $exceptionClass)`

Method to check if a given piece of code throws an Exception of the expected type.
Method to check if a given piece of code throws an Throwable of the expected type.

##### Arguments

| Arguments | Type | Description |
|---|---|---|
| $capture | `callable` | Closure in which the Exception shall be thrown. |
| $exceptionClass | `string` | Class of the Exception that is expected to be thrown. |
| $capture | `callable` | Closure in which the Throwable shall be thrown. |
| $exceptionClass | `string` | Class of the Throwable that is expected to be thrown. |

## License

Expand Down
2 changes: 1 addition & 1 deletion src/PredictExceptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function predictException(callable $capture, string $exceptionClass)
try {
call_user_func($capture);
throw new PredictExceptionFailure("Capture was expected to throw '$exceptionClass' but did not.");
} catch (\Exception $ex) {
} catch (\Throwable $ex) {
$actualExceptionClass = get_class($ex);

if ($actualExceptionClass === PredictExceptionFailure::class) {
Expand Down
8 changes: 8 additions & 0 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
trigger_error('test failed', E_USER_ERROR);
}

try {
$executionClass->predictException(function () {
throw new TypeError('something happened');
}, \TypeError::class);
} catch (\Exception $ex) {
trigger_error('test failed', E_USER_ERROR);
}

try {
$executionClass->predictException(function () {
throw new Exception('something happened');
Expand Down

0 comments on commit aaf8132

Please sign in to comment.