Skip to content

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

License

Notifications You must be signed in to change notification settings

Mystael/AssertThrows

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%