https://github.com/try-php/predict-exception
Simplified predictions if a piece of codes throws an Exception
https://github.com/try-php/predict-exception
php7 test testing tryphp
Last synced: about 1 month ago
JSON representation
Simplified predictions if a piece of codes throws an Exception
- Host: GitHub
- URL: https://github.com/try-php/predict-exception
- Owner: try-php
- License: gpl-2.0
- Created: 2017-10-25T18:49:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-08T21:49:28.000Z (over 8 years ago)
- Last Synced: 2025-07-30T13:06:27.525Z (11 months ago)
- Topics: php7, test, testing, tryphp
- Language: PHP
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# predict-exception
> Simplified predictions if a piece of codes throws an Exception
[](https://travis-ci.org/try-php/predict-exception)
## Install
```bash
$ composer require try/predict-exception
```
## Usage
```php
predictException(function () {
throw new \RuntimeException('Oooops. Something broke.')
}, \RuntimeException::class); // won't throw an exception
$assertions->predictException(function () {
}, \Exception::class); // will throw an exception
$assertions->predictException(function () {
throw new \RuntimeException('something else happened.');
}, \Exception::class); // will throw an exception
```
## API
### Methods
#### `predictException($capture, $exceptionClass)`
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 Throwable shall be thrown. |
| $exceptionClass | `string` | Class of the Throwable that is expected to be thrown. |
## License
GPL-2.0 © Willi Eßer