Skip to content

Commit

Permalink
Backport fix for #2472 (this does not mean that PHPUnit 5.7 is suppor…
Browse files Browse the repository at this point in the history
…ted on PHP 7.2)
  • Loading branch information
sebastianbergmann committed Dec 15, 2017
1 parent b21e0cf commit 4e9b1b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions ChangeLog-5.7.md
Expand Up @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 5.7 release series are documented in this fil

### Fixed

* Fixed [#2472](https://github.com/sebastianbergmann/phpunit/issues/2472): `PHPUnit\Util\Getopt` uses deprecated `each()` function
* Fixed [#2833](https://github.com/sebastianbergmann/phpunit/issues/2833): Test class loaded during data provider execution is not discovered

## [5.7.25] - 2017-11-14
Expand Down
39 changes: 23 additions & 16 deletions src/Util/Getopt.php
Expand Up @@ -32,18 +32,24 @@ public static function getopt(array $args, $short_options, $long_options = null)

reset($args);

while (list($i, $arg) = @each($args)) {
$args = array_map('trim', $args);

while (false !== $arg = current($args)) {
$i = key($args);
next($args);
if ($arg == '') {
continue;
}

if ($arg == '--') {
$non_opts = array_merge($non_opts, array_slice($args, $i + 1));

break;
}

if ($arg[0] != '-' || (strlen($arg) > 1 && $arg[1] == '-' && !$long_options)) {
$non_opts[] = $args[$i];

continue;
} elseif (strlen($arg) > 1 && $arg[1] == '-') {
self::parseLongOption(
Expand Down Expand Up @@ -80,21 +86,18 @@ protected static function parseShortOption($arg, $short_options, &$opts, &$args)
}

if (strlen($spec) > 1 && $spec[1] == ':') {
if (strlen($spec) > 2 && $spec[2] == ':') {
if ($i + 1 < $argLen) {
$opts[] = [$opt, substr($arg, $i + 1)];
break;
}
} else {
if ($i + 1 < $argLen) {
$opts[] = [$opt, substr($arg, $i + 1)];
break;
} elseif (list(, $opt_arg) = @each($args)) {
} else {
if ($i + 1 < $argLen) {
$opts[] = [$opt, substr($arg, $i + 1)];

break;
}
if (!(strlen($spec) > 2 && $spec[2] == ':')) {
if (false === $opt_arg = current($args)) {
throw new PHPUnit_Framework_Exception(
"option requires an argument -- $opt"
);
}
next($args);
}
}

Expand Down Expand Up @@ -134,10 +137,13 @@ protected static function parseLongOption($arg, $long_options, &$opts, &$args)

if (substr($long_opt, -1) == '=') {
if (substr($long_opt, -2) != '==') {
if (!strlen($opt_arg) && !(list(, $opt_arg) = @each($args))) {
throw new PHPUnit_Framework_Exception(
"option --$opt requires an argument"
);
if (!strlen($opt_arg)) {
if (false === $opt_arg = current($args)) {
throw new PHPUnit_Framework_Exception(
"option --$opt requires an argument"
);
}
next($args);
}
}
} elseif ($opt_arg) {
Expand All @@ -155,3 +161,4 @@ protected static function parseLongOption($arg, $long_options, &$opts, &$args)
throw new PHPUnit_Framework_Exception("unrecognized option --$opt");
}
}

0 comments on commit 4e9b1b2

Please sign in to comment.