https://github.com/codeception/assertthrows
Assert exception handling without stopping a test. For PHPUnit 6+
https://github.com/codeception/assertthrows
Last synced: 6 months ago
JSON representation
Assert exception handling without stopping a test. For PHPUnit 6+
- Host: GitHub
- URL: https://github.com/codeception/assertthrows
- Owner: Codeception
- License: mit
- Created: 2017-11-20T21:10:28.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-04-07T15:59:34.000Z (9 months ago)
- Last Synced: 2025-06-27T12:23:32.735Z (6 months ago)
- Language: PHP
- Size: 23.4 KB
- Stars: 19
- Watchers: 7
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# AssertThrows
Handle exceptions inside a test without a stop! Works with **PHPUnit** and Codeception.
[](https://github.com/Codeception/AssertThrows/actions)
[](https://github.com/Codeception/AssertThrows/releases)
[](https://packagist.org/packages/codeception/Assert-Throws)
[](/LICENSE)
## Installation
```
composer require "codeception/assert-throws" --dev
```
Include `AssertThrows` trait it to a TestCase:
```php
assertThrows(NotFoundException::class, function() {
$this->userController->show(99);
});
// alternatively
$this->assertThrows(new NotFoundException(), function() {
$this->userController->show(99);
});
// you can also assert that an exception is not throw
$this->assertDoesNotThrow(NotFoundException::class, function() {
$this->userController->show(99);
});
```
You can optionally test the exception message:
```php
assertThrowsWithMessage(
NotFoundException::class, 'my error message', function() {
throw new NotFoundException('my error message');
}
);
```
## License
`Codeception AssertThrows` is open-sourced software licensed under the [MIT](/LICENSE) License.
© Codeception PHP Testing Framework