PHPackages                             matesofmate/phpunit-extension - 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. matesofmate/phpunit-extension

ActiveSymfony-ai-mate[Testing &amp; Quality](/categories/testing)

matesofmate/phpunit-extension
=============================

PHPUnit extension for symfony/ai-mate providing token-optimized test execution tools

0.1.0(3mo ago)1813↓36.1%1[2 issues](https://github.com/MatesOfMate/phpunit-extension/issues)MITPHPPHP &gt;=8.2CI failing

Since Jan 26Pushed 3mo agoCompare

[ Source](https://github.com/MatesOfMate/phpunit-extension)[ Packagist](https://packagist.org/packages/matesofmate/phpunit-extension)[ RSS](/packages/matesofmate-phpunit-extension/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (10)Versions (2)Used By (0)

PHPUnit Extension for Symfony AI Mate
=====================================

[](#phpunit-extension-for-symfony-ai-mate)

Token-optimized PHPUnit testing tools for AI assistants. This extension provides MCP (Model Context Protocol) tools that execute PHPUnit tests and return results in TOON (Token-Oriented Object Notation) format, achieving 40-50% token reduction compared to raw PHPUnit output.

Features
--------

[](#features)

- **Run tests efficiently** - Execute entire suite, specific files, or single methods
- **TOON format output** - 40-50% token reduction vs. raw PHPUnit output using [helgesverre/toon](https://github.com/HelgeSverre/toon-php)
- **Test discovery** - List all available tests in your project
- **Auto-configuration** - Automatically detects `phpunit.xml` configuration
- **Fast execution** - Direct Symfony Process integration with current PHP binary
- **JUnit XML parsing** - Structured test result extraction

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

[](#installation)

```
composer require --dev matesofmate/phpunit-extension
```

The extension is automatically discovered by Symfony AI Mate.

Available Tools
---------------

[](#available-tools)

### `phpunit_run_suite`

[](#phpunit_run_suite)

Run the entire PHPUnit test suite.

**Parameters:**

- `configuration` (optional): Path to phpunit.xml configuration file
- `filter` (optional): Filter pattern for test names
- `stopOnFailure` (optional): Stop execution on first failure

**Examples:**

```
// Run all tests
phpunit_run_suite()

// Run with filter
phpunit_run_suite(filter: "UserTest")

// Stop on first failure
phpunit_run_suite(stopOnFailure: true)

// Custom configuration
phpunit_run_suite(configuration: "phpunit.custom.xml")
```

### `phpunit_run_file`

[](#phpunit_run_file)

Run PHPUnit tests from a specific file.

**Parameters:**

- `file` (required): Path to test file
- `filter` (optional): Filter pattern for method names
- `stopOnFailure` (optional): Stop execution on first failure

**Examples:**

```
// Run all tests in file
phpunit_run_file("tests/Service/UserServiceTest.php")

// Run specific method in file
phpunit_run_file("tests/Api/AuthTest.php", filter: "testLogin")

// Stop on first failure
phpunit_run_file("tests/Unit/CalculatorTest.php", stopOnFailure: true)
```

### `phpunit_run_method`

[](#phpunit_run_method)

Run a single PHPUnit test method.

**Parameters:**

- `class` (required): Fully qualified class name
- `method` (required): Test method name

**Examples:**

```
// Run specific test method
phpunit_run_method("App\\Tests\\UserServiceTest", "testCreateUser")

// Run another test
phpunit_run_method("App\\Tests\\Api\\AuthTest", "testLoginWithValidCredentials")
```

### `phpunit_list_tests`

[](#phpunit_list_tests)

List all available PHPUnit tests in the project.

**Parameters:**

- `directory` (optional): Specific directory to scan (defaults to configured test directories)

**Examples:**

```
// List all tests
phpunit_list_tests()

// List tests in specific directory
phpunit_list_tests(directory: "tests/Unit")
```

Output Format (TOON)
--------------------

[](#output-format-toon)

TOON (Token-Oriented Object Notation) provides minimal token usage while maintaining readability:

**Successful run:**

```
summary{tests,passed,failed,errors,warnings,skipped,time}:
42|42|0|0|0|0|1.234s

status:OK

```

**Failed run:**

```
summary{tests,passed,failed,errors,warnings,skipped,time}:
156|152|3|1|0|0|4.892s

failures[3]{class,method,message,file,line}:
UserServiceTest|testCreateUser|Expected 200 got 401|UserServiceTest.php|45
OrderTest|testCalculateTotal|99.99 !== 100.00|OrderTest.php|112
PaymentTest|testRefund|Null returned|PaymentTest.php|78

errors[1]{class,method,exception,file,line}:
DatabaseTest|testConnection|PDOException: Connection refused|DatabaseTest.php|23

status:FAILED

```

**Test listing:**

```
tests[4]{file,class,method}:
tests/UserTest.php|App\Tests\UserTest|testCreate
tests/UserTest.php|App\Tests\UserTest|testUpdate
tests/UserTest.php|App\Tests\UserTest|testDelete
tests/OrderTest.php|App\Tests\OrderTest|testCalculateTotal

```

### Token Efficiency

[](#token-efficiency)

Compared to standard JSON output:

**JSON (186 tokens):**

```
{
  "tests": 42,
  "passed": 39,
  "failed": 2,
  "time": "1.234s",
  "failures": [
    {"class": "UserTest", "method": "testCreate", "message": "Expected 200"}
  ]
}
```

**TOON (~110 tokens - 41% reduction):**

```
summary{tests,passed,failed,time}:
42|39|2|1.234s

failures[1]{class,method,message}:
UserTest|testCreate|Expected 200

```

How It Works
------------

[](#how-it-works)

### Architecture

[](#architecture)

The extension uses a layered architecture:

1. **Runner Layer** - Executes PHPUnit via Symfony Process (uses current PHP binary)
2. **Parser Layer** - Extracts structured data from JUnit XML output
3. **Formatter Layer** - Converts results to TOON format using helgesverre/toon
4. **Tools Layer** - MCP tools with `#[McpTool]` attributes

### Process Flow

[](#process-flow)

```
User Request
    ↓
MCP Tool (RunSuiteTool, RunFileTool, etc.)
    ↓
PhpunitRunner (Symfony Process with current PHP binary + PHPUnit)
    ↓
JUnit XML Output
    ↓
JunitXmlParser (Extract failures, errors, summary)
    ↓
ToonFormatter (Convert to TOON format)
    ↓
Return to AI Assistant

```

### PHP Binary Detection

[](#php-binary-detection)

The extension automatically uses the same PHP binary that's currently running (`PHP_BINARY`), ensuring consistency between your environment and test execution.

Development
-----------

[](#development)

### Quality Commands

[](#quality-commands)

```
# Run tests
composer test

# Check code quality (PHPStan level 8, PHP CS Fixer, Rector)
composer lint

# Auto-fix code style and apply refactorings
composer fix
```

### Testing

[](#testing)

The extension includes comprehensive tests:

- Unit tests for all core components
- Integration tests for tool execution
- PHPStan level 8 compliance
- PHP CS Fixer code style enforcement
- Rector PHP 8.2+ modernization

### CI/CD

[](#cicd)

GitHub Actions automatically runs on every push and pull request:

- **Lint**: Validates composer.json, runs Rector, PHP CS Fixer, PHPStan
- **Test**: Runs PHPUnit on PHP 8.2 and 8.3

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

[](#requirements)

- PHP 8.2 or higher
- PHPUnit 10.0 or higher (installed in your project)
- Symfony AI Mate 0.1 or higher

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) file for details.

Resources
---------

[](#resources)

- [Symfony AI Mate Documentation](https://symfony.com/doc/current/ai/components/mate.html)
- [TOON Format Specification](https://github.com/HelgeSverre/toon-php)
- [MatesOfMate Organization](https://github.com/matesofmate)

---

*"Because every Mate needs Mates"*

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance59

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e43a10984e8ee1687abaac86c26311c6a607b9560e8a3cc3193f8245751618bc?d=identicon)[wachterjohannes](/maintainers/wachterjohannes)

---

Top Contributors

[![wachterjohannes](https://avatars.githubusercontent.com/u/1464615?v=4)](https://github.com/wachterjohannes "wachterjohannes (10 commits)")

---

Tags

testingphpunitsymfonymcpaitoontest-automationai-mate

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/matesofmate-phpunit-extension/health.svg)

```
[![Health](https://phpackages.com/badges/matesofmate-phpunit-extension/health.svg)](https://phpackages.com/packages/matesofmate-phpunit-extension)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[infection/infection

Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the effectiveness of a test set in terms of its ability to detect faults.

2.2k26.2M1.8k](/packages/infection-infection)[phpbench/phpbench

PHP Benchmarking Framework

2.0k13.0M627](/packages/phpbench-phpbench)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)[matthiasnoback/symfony-config-test

Library for testing user classes related to the Symfony Config Component

1679.8M395](/packages/matthiasnoback-symfony-config-test)[lmc/steward

Steward - makes Selenium WebDriver + PHPUnit testing easy and robust

222163.1k1](/packages/lmc-steward)

PHPackages © 2026

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