adachsoft/phpunit-runner-tool

Flexible PHPUnit runner tool for adachsoft/ai-tool-call (SPI tool for running tests with filters, coverage and safe paths)

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/adachsoft/phpunit-runner-tool

v0.1.1 2025-12-02 07:05 UTC

This package is not auto-updated.

Last update: 2025-12-03 01:30:17 UTC


README

Flexible PHPUnit runner tool for adachsoft/ai-tool-call. This library provides a single, versatile tool to run PHPUnit tests in various project configurations.

Installation

composer require adachsoft/phpunit-runner-tool

Quick Start

Register the tool with adachsoft/ai-tool-call:

use AdachSoft\AiToolCall\AiToolCallFacadeBuilder;
use AdachSoft\PhpUnitRunnerTool\Tool\PhpUnitRunnerToolFactory;

$facade = (new AiToolCallFacadeBuilder())
    ->withSpiFactories([new PhpUnitRunnerToolFactory()])
    ->withToolConfigs([
        'phpunit_runner' => new ConfigMap([
            'basePath' => '/path/to/your/project',
            'phpunitPath' => 'vendor/bin/phpunit'
        ])
    ])
    ->build();

Usage Examples

Run All Tests

$result = $facade->callTool('phpunit_runner', []);
// Runs all tests with default configuration

Run Single Test File

$result = $facade->callTool('phpunit_runner', [
    'path' => 'tests/Unit/UserServiceTest.php'
]);

Run Tests in Directory

$result = $facade->callTool('phpunit_runner', [
    'path' => 'tests/Integration'
]);

With Custom Configuration

$result = $facade->callTool('phpunit_runner', [
    'path' => 'tests/Unit',
    'phpunitXml' => 'custom-phpunit.xml',
    'filter' => 'testUserCreation',
    'coverage' => false,
    'maxErrors' => 3,
    'timeout' => 60
]);

Configuration Options

ParameterTypeDefaultDescription
pathstringnullPath to test file or directory
phpunitXmlstringnullCustom PHPUnit configuration file
filterstringnullTest method name or pattern filter
coveragebooltrueEnable code coverage
maxErrorsint5Maximum detailed errors to return
timeoutintnullExecution timeout in seconds

Configuration in ToolFactory

When registering the tool, you can configure:

new ConfigMap([
    'basePath' => '/absolute/path/to/project',
    'phpunitPath' => 'vendor/bin/phpunit', // Relative to basePath or absolute
    'defaultCoverage' => true,
    'defaultMaxErrors' => 5,
    'defaultTimeout' => null
])

Response Format

The tool returns an array with:

[
    'stdout' => 'PHPUnit output...',
    'stderr' => 'Error output...',
    'exitCode' => 0, // 0 for success, >0 for failure
    'success' => true // Boolean based on exit code
]

Error Handling

The tool throws ToolExecutionException for:

  • Non-existent test paths
  • Invalid PHPUnit configuration
  • Command execution failures
  • Timeout errors
  • Permission issues

Requirements

  • PHP >= 8.3
  • PHPUnit installed in target project
  • adachsoft/ai-tool-call ^1.0
  • adachsoft/command-executor-lib ^1.0

License

MIT