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.3(1mo ago)01384MITPHPPHP ^8.1|^8.2

Since Feb 22Pushed 1mo 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 3w ago

READMEChangelog (6)Dependencies (4)Versions (7)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

50

—

FairBetter than 95% of packages

Maintenance93

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity70

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 ~382 days

Recently: every ~478 days

Total

6

Last Release

34d ago

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

1.1.2PHP ^8.1|^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10432296?v=4)[Johan Rosenson](/maintainers/johanrosenson)[@johanrosenson](https://github.com/johanrosenson)

---

Top Contributors

[![johanrosenson](https://avatars.githubusercontent.com/u/10432296?v=4)](https://github.com/johanrosenson "johanrosenson (8 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

[brianium/paratest

Parallel testing for PHP

2.5k129.9M910](/packages/brianium-paratest)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k41.3M38.7k](/packages/orchestra-testbench)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.0M321](/packages/drupal-core-dev)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

30300.1k6](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

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