PHPackages                             devlop/phpunit-exception-assertions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. devlop/phpunit-exception-assertions

ActiveLibrary[Testing &amp; Quality](/categories/testing)

devlop/phpunit-exception-assertions
===================================

PHPUnit assertions for exceptions.

1.1.2(6mo ago)01154MITPHPPHP ^8.1|^8.2

Since Feb 22Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/devlop/phpunit-exception-assertions)[ Packagist](https://packagist.org/packages/devlop/phpunit-exception-assertions)[ RSS](/packages/devlop-phpunit-exception-assertions/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (2)Versions (6)Used By (4)

 [![Latest Stable Version](https://camo.githubusercontent.com/04b296e306782afa64523a17e5c3df05257f626f27295cd8ee4d6135f80e2e80/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465766c6f702f706870756e69742d657863657074696f6e2d617373657274696f6e73)](https://packagist.org/packages/devlop/phpunit-exception-assertions) [![License](https://camo.githubusercontent.com/b5ccf3a6b815374314954678e0255ec91896b3d3447973f72c245b2ce6207038/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465766c6f702f706870756e69742d657863657074696f6e2d617373657274696f6e73)](https://github.com/devlop/phpunit-exception-assertions/blob/master/LICENSE.md)

PHPUnit Exception Assertions
============================

[](#phpunit-exception-assertions)

Trait containing assertions for easier testing of thrown (or not thrown) exceptions.

Installation
============

[](#installation)

```
composer require --dev devlop/phpunit-exception-assertions
```

Usage
=====

[](#usage)

Include the trait to get access to the assertions.

```
use Devlop\PHPUnit\ExceptionAssertions;

class YourTest extends TestCase
{
    use ExceptionAssertions;
}
```

Available Assertions
====================

[](#available-assertions)

assertExceptionThrown
---------------------

[](#assertexceptionthrown)

Asserts that a specific exception was thrown during the execution of the callback, if the callback finishes without the exception being thrown, the assertion fails.

To check for any exception, use `\Throwable::class` as first argument since all exceptions inherits from [`\Throwable`](https://www.php.net/manual/en/class.throwable.php).

```
$this->assertExceptionThrown(\InvalidArgumentException::class, function () : void {
    // code that should throw the expected exception
});
```

assertExceptionNotThrown
------------------------

[](#assertexceptionnotthrown)

Asserts that a specific exception was not thrown during the execution of the callback, if the specified exception was thrown during execution the assertion fails.

**use with caution** - this will only assert that a specific exception was not thrown and the assertion will pass for any other exceptions thrown, intentional or accidental. In most cases it is probably better to `assertNoExceptionsThrown` instead.

```
$this->assertExceptionNotThrown(\InvalidArgumentException::class, function () : void {
    // code that should not throw the exception
});
```

assertNoExceptionsThrown
------------------------

[](#assertnoexceptionsthrown)

Asserts that no exceptions was thrown during the execution of the callback, if any exceptions was thrown during the execution the assertion fails.

```
$this->assertNoExceptionsThrown(function () : void {
    // code that should not throw any exceptions
});
```

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance68

Regular maintenance activity

Popularity11

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~417 days

Total

5

Last Release

186d ago

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0

1.1.2PHP ^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/caa865d4467587eecd242fadf805f15ce436c9d7efa7786b49b69a193c158aaf?d=identicon)[johanrosenson](/maintainers/johanrosenson)

---

Top Contributors

[![johanrosenson](https://avatars.githubusercontent.com/u/10432296?v=4)](https://github.com/johanrosenson "johanrosenson (7 commits)")

---

Tags

phpunitphpunit-assertions

### Embed Badge

![Health badge](/badges/devlop-phpunit-exception-assertions/health.svg)

```
[![Health](https://phpackages.com/badges/devlop-phpunit-exception-assertions/health.svg)](https://phpackages.com/packages/devlop-phpunit-exception-assertions)
```

###  Alternatives

[codeception/codeception

All-in-one PHP Testing Framework

4.9k84.8M2.7k](/packages/codeception-codeception)[codeception/lib-asserts

Assertion methods used by Codeception core and Asserts module

10456.8M14](/packages/codeception-lib-asserts)[lastzero/test-tools

Increases testing productivity by adding a service container and self-initializing fakes to PHPUnit

2244.0k13](/packages/lastzero-test-tools)[frozzare/wp-test-suite

Run WordPress test easy

2225.3k20](/packages/frozzare-wp-test-suite)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
