ergebnis / phpunit-agent-reporter
Provides an extension for reporting phpunit/phpunit test execution details to agents.
Package info
github.com/ergebnis/phpunit-agent-reporter
pkg:composer/ergebnis/phpunit-agent-reporter
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
- ergebnis/agent-detector: ^1.0.1
- phpunit/phpunit: ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.50.0
- ergebnis/license: ^2.7.0
- ergebnis/php-cs-fixer-config: ^6.60.2
- ergebnis/phpstan-rules: ^2.13.1
- ergebnis/rector-rules: ^1.16.0
- fakerphp/faker: ^1.24.1
- infection/infection: ~0.27.11
- justinrainbow/json-schema: ^5.0.0 || ^6.0.0
- phpstan/phpstan: ^2.1.46
- phpstan/phpstan-deprecation-rules: ^2.0.4
- phpstan/phpstan-phpunit: ^2.0.16
- phpstan/phpstan-strict-rules: ^2.0.10
- rector/rector: ^2.4.1
This package is auto-updated.
Last update: 2026-04-22 05:19:36 UTC
README
This project provides a composer package and a Phar archive with an extension for reporting phpunit/phpunit test execution details to agents.
Example
After installing and bootstrapping the extension, when running your tests with phpunit/phpunit, the extension will detect whether an agent is running the tests and replace the default output with test execution details that are easier for agents to consume.
When tests pass, the extension outputs:
{
"result": "success",
"summary": {
"assertions": 5,
"errors": 0,
"failures": 0,
"tests": 5,
"warnings": 0
}
}
When tests fail (exit code 1), the extension outputs:
{
"result": "failure",
"summary": {
"assertions": 5,
"errors": 0,
"failures": 2,
"tests": 5,
"warnings": 0
},
"details": {
"failures": [
{
"file": "/path/to/ExampleTest.php",
"line": 27,
"message": "Failed asserting that false is true.",
"test": "Namespace\\ExampleTest::testFailing"
},
{
"actual": "bar",
"diff": "--- Expected\n+++ Actual\n@@ @@\n-'foo'\n+'bar'\n",
"expected": "foo",
"file": "/path/to/ExampleTest.php",
"line": 34,
"message": "Failed asserting that two strings are identical.",
"test": "Namespace\\ExampleTest::testComparisonFailing"
}
]
}
}
When tests fail with comparison assertions, the actual, diff, and expected fields provide details about the mismatch. These fields are only present for comparison failures.
When tests error (exit code 2), the extension outputs:
{
"result": "exception",
"summary": {
"assertions": 5,
"errors": 1,
"failures": 2,
"tests": 5,
"warnings": 0
},
"details": {
"errors": [
{
"file": "/path/to/ExampleTest.php",
"line": 32,
"message": "Something went wrong.",
"test": "Namespace\\ExampleTest::testErroring"
}
],
"failures": [
{
"file": "/path/to/ExampleTest.php",
"line": 27,
"message": "Failed asserting that false is true.",
"test": "Namespace\\ExampleTest::testFailing"
},
{
"actual": "bar",
"diff": "--- Expected\n+++ Actual\n@@ @@\n-'foo'\n+'bar'\n",
"expected": "foo",
"file": "/path/to/ExampleTest.php",
"line": 34,
"message": "Failed asserting that two strings are identical.",
"test": "Namespace\\ExampleTest::testComparisonFailing"
}
]
}
}
The JSON output conforms to the JSON schema included in this package.
Agent Detection
The extension uses ergebnis/agent-detector to detect the presence of agents.
Compatibility
The extension is compatible with the following versions of phpunit/phpunit:
Installation
Installation with composer
Run
composer require --dev ergebnis/phpunit-agent-reporter
to install ergebnis/phpunit-agent-reporter as a composer package.
Installation as Phar
Download phpunit-agent-reporter.phar from the latest release.
Usage
Bootstrapping the extension
Before the extension can report test execution details in phpunit/phpunit, you need to bootstrap it.
Bootstrapping the extension as a composer package
To bootstrap the extension as a composer package when using
phpunit/phpunit:^13.0.0phpunit/phpunit:^12.0.0phpunit/phpunit:^11.0.0phpunit/phpunit:^10.0.0
adjust your phpunit.xml configuration file and configure the
extensionselement onphpunit/phpunit:^13.0.0extensionselement onphpunit/phpunit:^12.0.0extensionselement onphpunit/phpunit:^11.0.0extensionselement onphpunit/phpunit:^10.0.0
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
>
+ <extensions>
+ <bootstrap class="Ergebnis\PHPUnit\AgentReporter\Extension"/>
+ </extensions>
<testsuites>
<testsuite name="unit">
<directory>test/Unit/</directory>
</testsuite>
</testsuites>
</phpunit>
Bootstrapping the extension as a PHAR
To bootstrap the extension as a PHAR when using
phpunit/phpunit:^13.0.0phpunit/phpunit:^12.0.0phpunit/phpunit:^11.0.0phpunit/phpunit:^10.0.0
adjust your phpunit.xml configuration file and configure the
extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^13.0.0extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^12.0.0extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^11.0.0extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^10.0.0
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
+ extensionsDirectory="directory/where/you/saved/the/extension/phars"
>
+ <extensions>
+ <bootstrap class="Ergebnis\PHPUnit\AgentReporter\Extension"/>
+ </extensions>
<testsuites>
<testsuite name="unit">
<directory>test/Unit/</directory>
</testsuite>
</testsuites>
</phpunit>
Changelog
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this project provide limited support.
You can support the maintenance of this project by sponsoring @ergebnis.
PHP Version Support Policy
This project currently supports the following PHP versions:
The maintainers of this project add support for a PHP version following its initial release and may drop support for a PHP version when it has reached its end of life.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Credits
This package is inspired by nunomaduro/pao, originally licensed under MIT by Nuno Maduro.
Social
Follow @localheinz and @ergebnis on Twitter.