Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

Readme.md

AssertThrows

Build Status

Handle exceptions inside a test without a stop!


Assertions for exceptions. Works with PHPUnit and Codeception.

Usage

Catch exception thrown inside a code block.

<?php
$this->assertThrows(NotFoundException::class, function() {
	$this->userController->show(999);
});

// alternatively
$this->assertThrows(new NotFoundException, function() {
	$this->userController->show(999);
});
?>

You can optionally test the exception message:

<?php
$this->assertThrowsWithMessage(NotFoundException::class, 'my error message', function() {
	throw new NotFoundException('my error message');
});
?>

Installation

composer require codeception/assert-throws --dev

Include AssertThrows trait it to a TestCase:

<?php
class MyTest extends PHPUnit\Framework\TestCase
{
    use Codeception\AssertThrows;

} 

License MIT

About

Assert exception handling without stopping a test. For PHPUnit 6+

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.