如何在我的测试类中获取phpunit CLI选项
在我的测试类中,是否有一种方法可以检查特定选项是否传递给phpunit CLI,尤其是选项如何在我的测试类中获取phpunit CLI选项,phpunit,symfony,Phpunit,Symfony,在我的测试类中,是否有一种方法可以检查特定选项是否传递给phpunit CLI,尤其是选项--debug 原因是,无论是否启用调试模式,都可以创建symfony内核 public function setUp() { self::bootKernel(["debug" => true|false]); } 我通过使用$\u服务器['argv'] 我在symfony代码库KernelTestCase::getPhpUnitCliConfigArgument /** * Finds
--debug
原因是,无论是否启用调试模式,都可以创建symfony内核
public function setUp()
{
self::bootKernel(["debug" => true|false]);
}
我通过使用
$\u服务器['argv']
我在symfony代码库KernelTestCase::getPhpUnitCliConfigArgument
/**
* Finds the value of the CLI configuration option.
*
* PHPUnit will use the last configuration argument on the command line, so this only returns
* the last configuration argument.
*
* @return string The value of the PHPUnit CLI configuration option
*/
private static function getPhpUnitCliConfigArgument()
{
$dir = null;
$reversedArgs = array_reverse($_SERVER['argv']);
foreach ($reversedArgs as $argIndex => $testArg) {
if (preg_match('/^-[^ \-]*c$/', $testArg) || $testArg === '--configuration') {
$dir = realpath($reversedArgs[$argIndex - 1]);
break;
} elseif (0 === strpos($testArg, '--configuration=')) {
$argPath = substr($testArg, strlen('--configuration='));
$dir = realpath($argPath);
break;
} elseif (0 === strpos($testArg, '-c')) {
$argPath = substr($testArg, strlen('-c'));
$dir = realpath($argPath);
break;
}
}
return $dir;
}