有没有办法在我的测试类中检查是否将特定选项传递给phpunit CLI,尤其是选项view.frame.size.height - randomButton.frame.size.height/2 - randomButton.frame.origin.y
。
原因是能够在启用或不启用调试模式的情况下创建symfony内核。
--debug
答案 0 :(得分:0)
我使用$_SERVER['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;
}