PHPackages                             rasuvaeff/understudy-phpunit - 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. rasuvaeff/understudy-phpunit

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

rasuvaeff/understudy-phpunit
============================

PHPUnit adapter for the understudy test double library: automatic verification and cleanup after every test

v0.1.0(today)01↑2900%BSD-3-ClausePHPPHP 8.3 - 8.5CI passing

Since Aug 25Pushed todayCompare

[ Source](https://github.com/rasuvaeff/understudy-phpunit)[ Packagist](https://packagist.org/packages/rasuvaeff/understudy-phpunit)[ Docs](https://github.com/rasuvaeff/understudy-phpunit)[ RSS](/packages/rasuvaeff-understudy-phpunit/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (12)Versions (2)Used By (0)

rasuvaeff/understudy-phpunit
============================

[](#rasuvaeffunderstudy-phpunit)

[![Latest Stable Version](https://camo.githubusercontent.com/afa4e9fada1cf6b54b26dd0b01b18499292efa247a1dd083f91b1cd30372f6e0/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f756e64657273747564792d706870756e69742f76)](https://packagist.org/packages/rasuvaeff/understudy-phpunit)[![Total Downloads](https://camo.githubusercontent.com/28a972062c317e47216743fcad939ca78514af99c3291a6b6899bd8b43a9cb9f/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f756e64657273747564792d706870756e69742f646f776e6c6f616473)](https://packagist.org/packages/rasuvaeff/understudy-phpunit)[![Build](https://github.com/rasuvaeff/understudy-phpunit/actions/workflows/build.yml/badge.svg)](https://github.com/rasuvaeff/understudy-phpunit/actions/workflows/build.yml)[![Static analysis](https://github.com/rasuvaeff/understudy-phpunit/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/rasuvaeff/understudy-phpunit/actions/workflows/static-analysis.yml)[![Psalm level](https://camo.githubusercontent.com/68f7f31799f2b93c710b14ba3877072e7fe07ec9d7cee3fdf67e14beab3e1b6f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7073616c6d2d6c6576656c5f312d626c75652e737667)](https://github.com/rasuvaeff/understudy-phpunit/actions/workflows/static-analysis.yml)[![PHP](https://camo.githubusercontent.com/688cc251421dfc97780a8453d9efd185343a9cc47cd2a14894f8cbdf0ae4d0fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f7261737576616566662f756e64657273747564792d706870756e69742f706870)](https://packagist.org/packages/rasuvaeff/understudy-phpunit)[![License](https://camo.githubusercontent.com/6cb285b57819f8de0acfb34923298f4f569f962544e8fe35331da2d163f4e485/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253442d2d332d2d436c617573652d626c75652e737667)](LICENSE.md)[Русская версия](README.ru.md)

PHPUnit adapter for [rasuvaeff/understudy](https://github.com/rasuvaeff/understudy) — a test double library where a configured call is a real call: `when(fn () => $repo->find(123))->returns($book)`.

The trait ends every test with understudy's own bookkeeping done for you:

- **verify after success** — after a body that reaches `assertPostConditions()`, every `expect()` is checked. An expectation the code never fulfilled fails the test as an assertion failure;
- **original failure wins** — after a failing body nothing is verified, so the adapter can never mask the error that actually happened;
- **reset always** — an `#[After]` hook drops the context unconditionally. One test can never leak a double into the next;
- **early guard** — an `#[Before]` hook refuses to start over a context some earlier test left behind, which is what broken integration looks like.

> Using an AI coding assistant? [llms.txt](llms.txt) is a compact API reference it can load instead of guessing.

Requirements
------------

[](#requirements)

- PHP 8.3 – 8.5
- `phpunit/phpunit` (`^11.5 || ^12.0 || ^13.0`)
- `rasuvaeff/understudy` (`^0.1`)

Pest works too — it runs on PHPUnit, so the same trait applies through `uses()`. Proven against Pest 4; see the Pest section below.

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

[](#installation)

```
composer require --dev rasuvaeff/understudy-phpunit
```

Usage
-----

[](#usage)

```
