@@ -308,25 +308,19 @@ protected function handleArguments(array $argv): void
308
308
$ this ->arguments ['loader ' ] = $ this ->handleLoader ($ this ->arguments ['loader ' ]);
309
309
}
310
310
311
- if (isset ($ this ->arguments ['configuration ' ]) && is_dir ($ this ->arguments ['configuration ' ])) {
312
- $ configurationFile = $ this ->arguments ['configuration ' ] . '/phpunit.xml ' ;
311
+ if (isset ($ this ->arguments ['configuration ' ])) {
312
+ if (is_dir ($ this ->arguments ['configuration ' ])) {
313
+ $ candidate = $ this ->configurationFileInDirectory ($ this ->arguments ['configuration ' ]);
313
314
314
- if (file_exists ($ configurationFile )) {
315
- $ this ->arguments ['configuration ' ] = realpath (
316
- $ configurationFile
317
- );
318
- } elseif (file_exists ($ configurationFile . '.dist ' )) {
319
- $ this ->arguments ['configuration ' ] = realpath (
320
- $ configurationFile . '.dist '
321
- );
315
+ if ($ candidate !== null ) {
316
+ $ this ->arguments ['configuration ' ] = $ candidate ;
317
+ }
322
318
}
323
- } elseif (!isset ($ this ->arguments ['configuration ' ]) && $ this ->arguments ['useDefaultConfiguration ' ]) {
324
- if (file_exists ('phpunit.xml ' )) {
325
- $ this ->arguments ['configuration ' ] = realpath ('phpunit.xml ' );
326
- } elseif (file_exists ('phpunit.xml.dist ' )) {
327
- $ this ->arguments ['configuration ' ] = realpath (
328
- 'phpunit.xml.dist '
329
- );
319
+ } elseif ($ this ->arguments ['useDefaultConfiguration ' ]) {
320
+ $ candidate = $ this ->configurationFileInDirectory (getcwd ());
321
+
322
+ if ($ candidate !== null ) {
323
+ $ this ->arguments ['configuration ' ] = $ candidate ;
330
324
}
331
325
}
332
326
@@ -890,4 +884,20 @@ private function handleWarmCoverageCache(XmlConfiguration\Configuration $configu
890
884
891
885
exit (TestRunner::SUCCESS_EXIT );
892
886
}
887
+
888
+ private function configurationFileInDirectory (string $ directory ): ?string
889
+ {
890
+ $ candidates = [
891
+ $ directory . '/phpunit.xml ' ,
892
+ $ directory . '/phpunit.xml.dist ' ,
893
+ ];
894
+
895
+ foreach ($ candidates as $ candidate ) {
896
+ if (file_exists ($ candidate )) {
897
+ return realpath ($ candidate );
898
+ }
899
+ }
900
+
901
+ return null ;
902
+ }
893
903
}
0 commit comments