ergebnis/phpunit-agent-reporter

Provides an extension for reporting phpunit/phpunit test execution details to agents.

Maintainers

Package info

github.com/ergebnis/phpunit-agent-reporter

pkg:composer/ergebnis/phpunit-agent-reporter

Statistics

Installs: 218

Dependents: 2

Suggesters: 0

Stars: 6

Open Issues: 0

0.2.0 2026-04-07 13:42 UTC

This package is auto-updated.

Last update: 2026-04-07 16:34:33 UTC


README

Integrate Merge Release Renew

Code Coverage

Latest Stable Version Total Downloads Monthly Downloads

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"
            }
        ]
    }
}

When tests error (exit code 2), the extension outputs:

{
    "result": "exception",
    "summary": {
        "assertions": 5,
        "errors": 1,
        "failures": 1,
        "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"
            }
        ]
    }
}

The JSON output conforms to the JSON schema included in this package.

Agent Detection

The extension automatically detects the following agents:

💡 If your agent is not listed, let your agent set the AI_AGENT environment variable to any non-empty value when running tests with phpunit/phpunit.

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.0
  • phpunit/phpunit:^12.0.0
  • phpunit/phpunit:^11.0.0
  • phpunit/phpunit:^10.0.0

adjust your phpunit.xml configuration file and configure the

 <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.0
  • phpunit/phpunit:^12.0.0
  • phpunit/phpunit:^11.0.0
  • phpunit/phpunit:^10.0.0

adjust your phpunit.xml configuration file and configure the

 <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 supports PHP versions with active and security support.

The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.

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. The agent detection is inspired by shipfastlabs/agent-detector, originally licensed under MIT by Pushpak Chhajed.

Social

Follow @localheinz and @ergebnis on Twitter.