PHPackages                             appeltaert/phpunit-assertion-message - 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. appeltaert/phpunit-assertion-message

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

appeltaert/phpunit-assertion-message
====================================

Enhanced PHPUnit Assertion Messages - Debug assertions without creating a mess.

v1.0.0(8y ago)076MITPHPPHP &gt;=5.6

Since Feb 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/appeltaert/phpunit-assertion-message)[ Packagist](https://packagist.org/packages/appeltaert/phpunit-assertion-message)[ RSS](/packages/appeltaert-phpunit-assertion-message/feed)WikiDiscussions master Synced 4d ago

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

PHPUnit Assertion Message [![Build Status](https://camo.githubusercontent.com/ca43dee1e45c042cebbc4081584c33d842a70b951ac7ab1ca8d6e01678c9c640/68747470733a2f2f7472617669732d63692e6f72672f617070656c74616572742f706870756e69742d617373657274696f6e2d6d6573736167652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/appeltaert/phpunit-assertion-message)[![SensioLabsInsight](https://camo.githubusercontent.com/908292aad73bde1698f0280c7b81b31d9dbc1bac12def5ed49c80e8292483b56/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33663432666434302d653164642d343232632d626338342d3362386234373639646463322f6d696e692e706e67)](https://insight.sensiolabs.com/projects/3f42fd40-e1dd-422c-bc84-3b8b4769ddc2)
=========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#phpunit-assertion-message-)

```
composer require --dev appeltaert/phpunit-assertion-message

```

### Usage

[](#usage)

1. Simply wrap whatever message you normally pass to assertions in a `new PAM(string $message, [mixed $context,...])` instance.
2. Run `phpunit` with **--debug**

`$context` can be basically be anything, for now there's only explicit support for Symfony `Response` and `Request` objects, but as a final resort a var flattening processor will take over to basically make anything readable if no processor can handle your context.

#### Before

[](#before)

This will turn this occasional mess while debugging.

```
$client->enableProfiler();
$response = $client->getResponse();

$this->assertTrue($response->isSuccessful(), "My message");
```

```
There was 1 failure:

1) Tests\AppBundle\Controller\DefaultControllerTest::testIndex
My message

// wtf is going on
// $this->assertTrue($client->getResponse()->isSuccessful())
// $collector = $profiler->getCollector()..
// var_dump($collector->...);
// echo $response->getContent();
// var_dump($response->headers->all();
// die.. die.. die..

```

#### After

[](#after)

Into this.

```
$client->enableProfiler();
$response = $client->getResponse();

$this->assertTrue($response->isSuccessful(),
    new PAM("My message", [$response, $profiler->getCollector('request')]));
```

```
There was 1 failure:

1) Tests\AppBundle\Controller\DefaultControllerTest::testIndex
My message

HTTP response:         Code: 200
               Content-type: text/html; charset=UTF-8
                    Cookies: 0: qwer=qewrqwer; path=/; httponly

Request profile:      Format: html
                  StatusText: OK
                       Route: app_router_index
                  StatusCode: 200
                 ContentType: text/html; charset=UTF-8
                    PathInfo: /router/

```

How it works
------------

[](#how-it-works)

### Processors

[](#processors)

All context passed is handled by a chain of `Processors`. The first one to accept the context wins. The processors are then printed by a `Printer`. The default printer `Plain` dumps everything into human-readable blocks.

**Symfony Response object**

```
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful(), new PAM("My message", [$response]));
```

```
HTTP response:      Code: 500
                 Headers:  content-type: ["text\/html; charset=UTF-8"]
                          cache-control: ["no-cache, private"]
                                   date: ["Fri, 23 Feb 2018 21:12:32 GMT"]
                          x-debug-token: ["771d20"]
               Exception: qewr (500 Internal Server Error)

```

**Symfony request profiler**

```
$this->assertSame(
    Response::HTTP_OK,
    $client->getResponse()->getStatusCode(),
    new PAM(sprintf('The %s public URL loads correctly.', $url), [$client->getProfile()->getCollector('request')])
);
```

```
Request profile:            Format: html
                             Route: blog_index
                        StatusText: Internal Server Error
                        StatusCode: 500
                       ContentType: text/html; charset=UTF-8
                          PathInfo: /en/blog/
                            Method: GET
                            Locale: en
                       RouteParams:    page: 1
                                    _format: html
                                    _locale: en
                 SessionAttributes: key: val
                   SessionMetaData:   Created: Fri, 23 Feb 18 22:12:31 +0100
                                    Last used: Fri, 23 Feb 18 22:12:31 +0100
                                     Lifetime: 0
                            Action: AppBundle\Controller\BlogController::indexAction

```

**Array**

```
$someArray = [];
$this->assertArrayHasKey("test", $array, new PAM("My message", [
    'qwerqwer' => 'qwerqewr', ['qwerqewr', 'qwerqwer']
]));
```

```
Array: qwerqwer: qwerqewr
              0: 0: qwerqewr
                 1: qwerqwer

```

### Config

[](#config)

#### Printer

[](#printer)

At the moment there is only one printer, `Plain`.

#### Statically set all options

[](#statically-set-all-options)

```
PAM::setDefaults($processors, $printer, $env);
```

#### Overriding the environment

[](#overriding-the-environment)

```
$env = new Env($debug = null, $verbose = null, $supportsColors = null);
PAM::setDefaults([], null, $env);

```

### roadmap

[](#roadmap)

#### v1.1

[](#v11)

**processors**

- more symfony
- move them to separate suggested repos
- make them pluggable

**printer**

- distinctive dumps based on env, more info --verbose, less without
- detect interactive terminal(for colored output f.e.), also check ansi arguments.
- posix\_isatty, XTERM check?

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3003d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/40e4ed65d7211d4e9ff688cc92c508f8701e8747d07fe36589773b6f1a21a8a5?d=identicon)[pbijl](/maintainers/pbijl)

---

Top Contributors

[![appeltaert](https://avatars.githubusercontent.com/u/8100221?v=4)](https://github.com/appeltaert "appeltaert (15 commits)")

---

Tags

testingphpunit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/appeltaert-phpunit-assertion-message/health.svg)

```
[![Health](https://phpackages.com/badges/appeltaert-phpunit-assertion-message/health.svg)](https://phpackages.com/packages/appeltaert-phpunit-assertion-message)
```

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k910.7M134.8k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[codedungeon/phpunit-result-printer

PHPUnit Pretty Result Printer

1.2k8.8M397](/packages/codedungeon-phpunit-result-printer)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69417.9M510](/packages/spatie-phpunit-snapshot-assertions)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

56426.3M456](/packages/dg-bypass-finals)[phpunit/phpunit-selenium

Selenium Server integration for PHPUnit

59610.9M150](/packages/phpunit-phpunit-selenium)

PHPackages © 2026

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