|
24 | 24 |
|
25 | 25 | static $phpunitConfig = null;
|
26 | 26 | if (null === $phpunitConfig) {
|
27 |
| - $opt = min(array_search('-c', $opts = array_reverse($argv), true) ?: INF, array_search('--configuration', $opts, true) ?: INF); |
28 | 27 | $phpunitConfigFilename = null;
|
29 |
| - if (INF !== $opt && isset($opts[$opt - 1])) { |
30 |
| - $phpunitConfigFilename = $opts[$opt - 1]; |
31 |
| - } elseif (file_exists('phpunit.xml')) { |
32 |
| - $phpunitConfigFilename = 'phpunit.xml'; |
33 |
| - } elseif (file_exists('phpunit.xml.dist')) { |
34 |
| - $phpunitConfigFilename = 'phpunit.xml.dist'; |
| 28 | + $getPhpUnitConfig = function ($probableConfig) use (&$getPhpUnitConfig) { |
| 29 | + if (!$probableConfig) { |
| 30 | + return null; |
| 31 | + } |
| 32 | + if (is_dir($probableConfig)) { |
| 33 | + return $getPhpUnitConfig($probableConfig.DIRECTORY_SEPARATOR.'phpunit.xml'); |
| 34 | + } |
| 35 | + |
| 36 | + if (file_exists($probableConfig)) { |
| 37 | + return $probableConfig; |
| 38 | + } |
| 39 | + if (file_exists($probableConfig.'.dist')) { |
| 40 | + return $probableConfig.'.dist'; |
| 41 | + } |
| 42 | + |
| 43 | + return null; |
| 44 | + }; |
| 45 | + |
| 46 | + foreach ($argv as $cliArgumentIndex => $cliArgument) { |
| 47 | + if ('--' === $cliArgument) { |
| 48 | + break; |
| 49 | + } |
| 50 | + // long option |
| 51 | + if ('--configuration' === $cliArgument && array_key_exists($cliArgumentIndex + 1, $argv)) { |
| 52 | + $phpunitConfigFilename = $getPhpUnitConfig($argv[$cliArgumentIndex + 1]); |
| 53 | + break; |
| 54 | + } |
| 55 | + // short option |
| 56 | + if (0 === strpos($cliArgument, '-c')) { |
| 57 | + if ('-c' === $cliArgument && array_key_exists($cliArgumentIndex + 1, $argv)) { |
| 58 | + $phpunitConfigFilename = $getPhpUnitConfig($argv[$cliArgumentIndex + 1]); |
| 59 | + } else { |
| 60 | + $phpunitConfigFilename = $getPhpUnitConfig(substr($cliArgument, 2)); |
| 61 | + } |
| 62 | + break; |
| 63 | + } |
35 | 64 | }
|
| 65 | + |
| 66 | + $phpunitConfigFilename = $phpunitConfigFilename ?: $getPhpUnitConfig('phpunit.xml'); |
| 67 | + |
36 | 68 | if ($phpunitConfigFilename) {
|
37 | 69 | $phpunitConfig = new DomDocument();
|
38 | 70 | $phpunitConfig->load($phpunitConfigFilename);
|
|
0 commit comments