Skip to content

Commit

Permalink
bug #34808 [PhpUnitBridge] Properly handle phpunit arguments for conf…
Browse files Browse the repository at this point in the history
…iguration file (biozshock)

This PR was merged into the 4.3 branch.

Discussion
----------

[PhpUnitBridge] Properly handle phpunit arguments for configuration file

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| License       | MIT

PhpUnitBridge should properly parse cli arguments for configuration file.
After fixing #34300 the PhpUnitBridge stopped recognizing short `-c` option.
Also original PHPUnit allows to pass a directory as configuration parameter and read from either phpunit.xml or phpunit.xml.dist

Commits
-------

a7a5885661 Properly handle phpunit arguments for configuration file
  • Loading branch information
fabpot committed Jan 30, 2020
2 parents 60539d9 + 1adfbac commit e7a22bc
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions bin/simple-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,47 @@

static $phpunitConfig = null;
if (null === $phpunitConfig) {
$opt = min(array_search('-c', $opts = array_reverse($argv), true) ?: INF, array_search('--configuration', $opts, true) ?: INF);
$phpunitConfigFilename = null;
if (INF !== $opt && isset($opts[$opt - 1])) {
$phpunitConfigFilename = $opts[$opt - 1];
} elseif (file_exists('phpunit.xml')) {
$phpunitConfigFilename = 'phpunit.xml';
} elseif (file_exists('phpunit.xml.dist')) {
$phpunitConfigFilename = 'phpunit.xml.dist';
$getPhpUnitConfig = function ($probableConfig) use (&$getPhpUnitConfig) {
if (!$probableConfig) {
return null;
}
if (is_dir($probableConfig)) {
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) {
$phpunitConfig = new DomDocument();
$phpunitConfig->load($phpunitConfigFilename);
Expand Down

0 comments on commit e7a22bc

Please sign in to comment.