Skip to content

Commit af0e12d

Browse files
Refactor
1 parent 2b8ffc1 commit af0e12d

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/TextUI/Command.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,25 +308,19 @@ protected function handleArguments(array $argv): void
308308
$this->arguments['loader'] = $this->handleLoader($this->arguments['loader']);
309309
}
310310

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']);
313314

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+
}
322318
}
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;
330324
}
331325
}
332326

@@ -890,4 +884,20 @@ private function handleWarmCoverageCache(XmlConfiguration\Configuration $configu
890884

891885
exit(TestRunner::SUCCESS_EXIT);
892886
}
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+
}
893903
}

0 commit comments

Comments
 (0)