adachsoft/phpunit-runner-tool
Composer 安装命令:
composer require adachsoft/phpunit-runner-tool
包简介
Flexible PHPUnit runner tool for adachsoft/ai-tool-call (SPI tool for running tests with filters, coverage and safe paths)
README 文档
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.
⚠️ Breaking Changes in v0.2.0
Configuration keys changed from camelCase to snake_case to comply with adachsoft/ai-tool-call 2.0.0 standards:
basePath→base_pathphpunitPath→phpunit_pathdefaultCoverage→default_coveragedefaultMaxErrors→default_max_errorsdefaultTimeout→default_timeout
Installation
composer require adachsoft/phpunit-runner-tool
Quick Start
Register the tool with adachsoft/ai-tool-call:
use AdachSoft\AiToolCall\AiToolCallFacadeBuilder;
use AdachSoft\AiToolCall\SPI\Collection\ConfigMap;
use AdachSoft\PhpUnitRunnerTool\Tool\PhpUnitRunnerToolFactory;
$facade = (new AiToolCallFacadeBuilder())
->withSpiFactories([new PhpUnitRunnerToolFactory()])
->withToolConfigs([
'phpunit_runner' => new ConfigMap([
'base_path' => '/path/to/your/project',
'phpunit_path' => 'vendor/bin/phpunit',
]),
])
->build();
Usage Examples
Run All Tests
$result = $facade->callTool('phpunit_runner', []);
// Runs all tests with default configuration
// Internally, PHPUnit is invoked with flags like --display-phpunit-notices,
// --display-phpunit-deprecations and --display-skipped by default.
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',
'phpunit_xml' => 'custom-phpunit.xml',
'filter' => 'testUserCreation',
'coverage' => false,
'max_errors' => 3,
'timeout' => 60,
]);
Configuration Options
| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | null | Path to test file or directory (relative to base_path or absolute). Empty string is treated as null and runs all tests. |
phpunit_xml | string | null | Custom PHPUnit configuration file (relative to base_path or absolute). |
filter | string | null | Test method name or pattern filter. |
coverage | bool | true | Enable code coverage. |
max_errors | int | 5 | Maximum detailed errors to return. |
timeout | int | null | Execution timeout in seconds for this call. Cannot exceed configured max_timeout (if set). |
Configuration in ToolFactory
When registering the tool, you can configure:
new ConfigMap([
'base_path' => '/absolute/path/to/project',
'phpunit_path' => 'vendor/bin/phpunit', // Relative to base_path or absolute
'default_coverage' => true,
'default_max_errors' => 5,
'default_timeout' => null, // Default timeout when per-call timeout is not provided
'max_timeout' => null, // Optional hard cap for per-call timeout (int > 0 or null for no limit)
'display_notices' => false, // Display notices during test execution (adds --display-notices)
'display_warnings' => false, // Display warnings during test execution (adds --display-warnings)
'display_deprecations' => false, // Display deprecations during test execution (adds --display-deprecations)
'display_phpunit_notices' => true, // Display PHPUnit framework notices (adds --display-phpunit-notices)
'display_phpunit_deprecations' => true, // Display PHPUnit framework deprecations (adds --display-phpunit-deprecations)
])
By default, the underlying runner always passes --display-phpunit-notices,
--display-phpunit-deprecations and --display-skipped to PHPUnit so that
framework-level notices, deprecations and skipped tests are visible without
additional configuration.
Response Format
The tool returns an array with:
[
'stdout' => 'PHPUnit output...',
'stderr' => 'Error output...',
'exit_code' => 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
Additionally, the tool throws InvalidArgumentException when:
pathpoints to an excluded folder configured viaexcluded_folderstimeoutormax_errorsparameters are of invalid typestimeoutexceeds the configuredmax_timeoutlimit when such a limit is set
Static Analysis & Code Style
This project uses the shared adachsoft/php-code-style configuration for:
- PHP-CS-Fixer ruleset (imported via
.php-cs-fixer.php→vendor/adachsoft/php-code-style/.php-cs-fixer.dist.php), - PHPStan configuration (via
phpstan.neonincludingvendor/adachsoft/php-code-style/phpstan.neon.dist), - Rector base config (imported via
rector.php→vendor/adachsoft/php-code-style/rector.dist.php).
Recommended Composer scripts:
"scripts": {
"cs:check": "php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.php",
"cs:fix": "php-cs-fixer fix --config=.php-cs-fixer.php",
"stan": "phpstan analyse",
"rector": "rector"
}
Run tools via:
composer cs:check # check coding style
composer cs:fix # auto-fix coding style
composer stan # run PHPStan analysis
composer rector # run Rector refactoring
Requirements
- PHP >= 8.3
- PHPUnit installed in target project
- adachsoft/ai-tool-call ^2.0.0
- adachsoft/command-executor-lib ^2.0
License
MIT
adachsoft/phpunit-runner-tool 适用场景与选型建议
adachsoft/phpunit-runner-tool 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cli」 「phpunit」 「tool」 「runner」 「ai-tool-call」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adachsoft/phpunit-runner-tool 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adachsoft/phpunit-runner-tool 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adachsoft/phpunit-runner-tool 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HiDev plugin for PHPUnit
Backend Google Sign On for Magento 2
Testing Suite For Lumen like Laravel does.
A cli tool which generates unit tests.
An app setting manager tool for laravel nova
The Message Submission Agent Diagnostics tool (msadiag) facilitates testing the compatibility of third party message submission agents.
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-02