Files
tcpserver-flow/phpunit-ide.php
T
2026-03-08 22:58:56 +08:00

38 lines
858 B
PHP

<?php
/**
* IDE 兼容的 PHPUnit 测试运行器
* 解决 IDE 内置 PHPUnit 与项目版本不兼容的问题
*/
require_once __DIR__ . '/vendor/autoload.php';
// 检查 PHPUnit 版本
if (!class_exists('PHPUnit\TextUI\Command')) {
echo "Error: PHPUnit not found. Please run: composer install\n";
exit(1);
}
// 获取命令行参数
$args = $_SERVER['argv'];
// 移除脚本名
array_shift($args);
// 构建 PHPUnit 命令
$phpunitCmd = [PHP_BINARY, 'vendor/bin/phpunit'];
// 添加配置文件
if (!in_array('--configuration', $args) && !in_array('-c', $args)) {
$phpunitCmd[] = '--configuration';
$phpunitCmd[] = 'phpunit.xml';
}
// 合并参数
$phpunitCmd = array_merge($phpunitCmd, $args);
// 执行 PHPUnit
$command = implode(' ', array_map('escapeshellarg', $phpunitCmd));
passthru($command, $exitCode);
exit($exitCode);