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(7mo ago)01154MITPHPPHP ^8.1|^8.2

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

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

42

—

FairBetter than 89% of packages

Maintenance66

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

235d 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

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.0k](/packages/orchestra-testbench)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M54](/packages/timacdonald-log-fake)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M774](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)

PHPackages © 2026

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