Properly handle phpunit arguments for configuration file
This commit is contained in:
parent
477e843790
commit
a7a5885661
@ -24,15 +24,47 @@ $getEnvVar = function ($name, $default = false) use ($argv) {
|
|||||||
|
|
||||||
static $phpunitConfig = null;
|
static $phpunitConfig = null;
|
||||||
if (null === $phpunitConfig) {
|
if (null === $phpunitConfig) {
|
||||||
$opt = min(array_search('-c', $opts = array_reverse($argv), true) ?: INF, array_search('--configuration', $opts, true) ?: INF);
|
|
||||||
$phpunitConfigFilename = null;
|
$phpunitConfigFilename = null;
|
||||||
if (INF !== $opt && isset($opts[$opt - 1])) {
|
$getPhpUnitConfig = function ($probableConfig) use (&$getPhpUnitConfig) {
|
||||||
$phpunitConfigFilename = $opts[$opt - 1];
|
if (!$probableConfig) {
|
||||||
} elseif (file_exists('phpunit.xml')) {
|
return null;
|
||||||
$phpunitConfigFilename = 'phpunit.xml';
|
}
|
||||||
} elseif (file_exists('phpunit.xml.dist')) {
|
if (is_dir($probableConfig)) {
|
||||||
$phpunitConfigFilename = 'phpunit.xml.dist';
|
return $getPhpUnitConfig($probableConfig.DIRECTORY_SEPARATOR.'phpunit.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_exists($probableConfig)) {
|
||||||
|
return $probableConfig;
|
||||||
|
}
|
||||||
|
if (file_exists($probableConfig.'.dist')) {
|
||||||
|
return $probableConfig.'.dist';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach ($argv as $cliArgumentIndex => $cliArgument) {
|
||||||
|
if ('--' === $cliArgument) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// long option
|
||||||
|
if ('--configuration' === $cliArgument && array_key_exists($cliArgumentIndex + 1, $argv)) {
|
||||||
|
$phpunitConfigFilename = $getPhpUnitConfig($argv[$cliArgumentIndex + 1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// short option
|
||||||
|
if (0 === strpos($cliArgument, '-c')) {
|
||||||
|
if ('-c' === $cliArgument && array_key_exists($cliArgumentIndex + 1, $argv)) {
|
||||||
|
$phpunitConfigFilename = $getPhpUnitConfig($argv[$cliArgumentIndex + 1]);
|
||||||
|
} else {
|
||||||
|
$phpunitConfigFilename = $getPhpUnitConfig(substr($cliArgument, 2));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$phpunitConfigFilename = $phpunitConfigFilename ?: $getPhpUnitConfig('phpunit.xml');
|
||||||
|
|
||||||
if ($phpunitConfigFilename) {
|
if ($phpunitConfigFilename) {
|
||||||
$phpunitConfig = new DomDocument();
|
$phpunitConfig = new DomDocument();
|
||||||
$phpunitConfig->load($phpunitConfigFilename);
|
$phpunitConfig->load($phpunitConfigFilename);
|
||||||
|
Reference in New Issue
Block a user