PHPackages                             jchook/phpunit-assert-throws - 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. jchook/phpunit-assert-throws

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

jchook/phpunit-assert-throws
============================

Exception assertions for PHPUnit

v1.0.3(7y ago)111.7M↓18.9%316MITPHP

Since Apr 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/jchook/phpunit-assert-throws)[ Packagist](https://packagist.org/packages/jchook/phpunit-assert-throws)[ RSS](/packages/jchook-phpunit-assert-throws/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (5)Used By (16)

PHPUnit `assertThrows()`
========================

[](#phpunit-assertthrows)

Industry standard, lambda-based exception testing assertions for PHPUnit.

Installation
------------

[](#installation)

Easily install it with composer:

```
composer require --dev jchook/phpunit-assert-throws
```

Or, alternatively [copy the tiny gist](https://raw.githubusercontent.com/jchook/phpunit-assert-throws/master/src/AssertThrows.php) and add it to you project. No attribution is requried. True artists steal.

Rationale
---------

[](#rationale)

To enable lambda-based exception testing syntax to [PHPUnit](https://docs.phpunit.de/en/10.4/writing-tests-for-phpunit.html#expecting-exceptions).

- Throw multiple errors per test
- Examine and test errors after they are caught
- Copy-paste usage examples
- Use standard `assert*` syntax
- Test more than just `message`, `code`, and `class`
- Write simple happy-path tests with `assertNotThrows`

Example
-------

[](#example)

Just to illustrate the spirit behind the syntax:

```

```

Notes
-----

[](#notes)

Yes, `assertNotThrows()` feels grammatically… odd. However, it conforms with the PHPUnit naming conventions, such as [`assertNotContains()`](https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertContains). Additionally, the PHPUnit team suggests [we may not need this inverse assertion](https://github.com/sebastianbergmann/phpunit-documentation/issues/171).

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 95.5% 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 ~124 days

Total

4

Last Release

2638d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/047da3410a118e06b8f9e170318c1c1197a6dbd5ceebe1a43ee91251d49c7632?d=identicon)[jchook](/maintainers/jchook)

---

Top Contributors

[![jchook](https://avatars.githubusercontent.com/u/193530?v=4)](https://github.com/jchook "jchook (21 commits)")[![jean-beguin](https://avatars.githubusercontent.com/u/39402471?v=4)](https://github.com/jean-beguin "jean-beguin (1 commits)")

### Embed Badge

![Health badge](/badges/jchook-phpunit-assert-throws/health.svg)

```
[![Health](https://phpackages.com/badges/jchook-phpunit-assert-throws/health.svg)](https://phpackages.com/packages/jchook-phpunit-assert-throws)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k136.1M986](/packages/brianium-paratest)[drupal/core-dev

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

2022.6M342](/packages/drupal-core-dev)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

30314.4k7](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

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