Skip to content

Commit c8a34c1

Browse files
committed
Fix compatibility issues
1 parent 46023de commit c8a34c1

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

src/Framework/Constraint.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ protected function matches($other)
8181
*
8282
* @since Method available since Release 3.4.0
8383
*/
84+
#[\ReturnTypeWillChange]
8485
public function count()
8586
{
8687
return 1;

src/Util/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected function __construct($filename)
162162
/**
163163
* @since Method available since Release 3.4.0
164164
*/
165-
final private function __clone()
165+
private function __clone()
166166
{
167167
}
168168

@@ -516,7 +516,7 @@ public function handlePHPConfiguration()
516516
// See https://github.com/sebastianbergmann/phpunit/issues/277
517517
switch ($array) {
518518
case 'var':
519-
$target = &$GLOBALS;
519+
// $target = &$GLOBALS;
520520
break;
521521

522522
case 'server':

src/Util/Getopt.php

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function getopt(array $args, $short_options, $long_options = null)
2121
return array(array(), array());
2222
}
2323

24-
$opts = array();
24+
$opts = array();
2525
$non_opts = array();
2626

2727
if ($long_options) {
@@ -35,7 +35,10 @@ public static function getopt(array $args, $short_options, $long_options = null)
3535
reset($args);
3636
array_map('trim', $args);
3737

38-
while (list($i, $arg) = each($args)) {
38+
39+
for ($i = 0; $i < count($args); $i++) {
40+
$arg = $args[$i];
41+
3942
if ($arg == '') {
4043
continue;
4144
}
@@ -45,24 +48,30 @@ public static function getopt(array $args, $short_options, $long_options = null)
4548
break;
4649
}
4750

51+
$nextArg = isset($args[$i]) ? $args[$i] : null;
52+
4853
if ($arg[0] != '-' ||
4954
(strlen($arg) > 1 && $arg[1] == '-' && !$long_options)) {
5055
$non_opts[] = $args[$i];
5156
continue;
5257
} elseif (strlen($arg) > 1 && $arg[1] == '-') {
53-
self::parseLongOption(
58+
if (self::parseLongOption(
5459
substr($arg, 2),
5560
$long_options,
5661
$opts,
57-
$args
58-
);
62+
$nextArg
63+
)) {
64+
$i++;
65+
}
5966
} else {
60-
self::parseShortOption(
67+
if (self::parseShortOption(
6168
substr($arg, 1),
6269
$short_options,
6370
$opts,
64-
$args
65-
);
71+
$nextArg
72+
)) {
73+
$i++;
74+
}
6675
}
6776
}
6877

@@ -74,7 +83,7 @@ protected static function parseShortOption($arg, $short_options, &$opts, &$args)
7483
$argLen = strlen($arg);
7584

7685
for ($i = 0; $i < $argLen; $i++) {
77-
$opt = $arg[$i];
86+
$opt = $arg[$i];
7887
$opt_arg = null;
7988

8089
if (($spec = strstr($short_options, $opt)) === false ||
@@ -107,11 +116,11 @@ protected static function parseShortOption($arg, $short_options, &$opts, &$args)
107116
}
108117
}
109118

110-
protected static function parseLongOption($arg, $long_options, &$opts, &$args)
119+
protected static function parseLongOption($arg, $long_options, &$opts, $nextArg)
111120
{
112-
$count = count($long_options);
113-
$list = explode('=', $arg);
114-
$opt = $list[0];
121+
$count = count($long_options);
122+
$list = explode('=', $arg);
123+
$opt = $list[0];
115124
$opt_arg = null;
116125

117126
if (count($list) > 1) {
@@ -121,7 +130,7 @@ protected static function parseLongOption($arg, $long_options, &$opts, &$args)
121130
$opt_len = strlen($opt);
122131

123132
for ($i = 0; $i < $count; $i++) {
124-
$long_opt = $long_options[$i];
133+
$long_opt = $long_options[$i];
125134
$opt_start = substr($long_opt, 0, $opt_len);
126135

127136
if ($opt_start != $opt) {
@@ -131,20 +140,24 @@ protected static function parseLongOption($arg, $long_options, &$opts, &$args)
131140
$opt_rest = substr($long_opt, $opt_len);
132141

133142
if ($opt_rest != '' && $opt[0] != '=' && $i + 1 < $count &&
134-
$opt == substr($long_options[$i+1], 0, $opt_len)) {
143+
$opt == substr($long_options[$i + 1], 0, $opt_len)) {
135144
throw new PHPUnit_Framework_Exception(
136145
"option --$opt is ambiguous"
137146
);
138147
}
139148

149+
$ret = false;
150+
140151
if (substr($long_opt, -1) == '=') {
141152
if (substr($long_opt, -2) != '==') {
142-
if (!strlen($opt_arg) &&
143-
!(list(, $opt_arg) = each($args))) {
153+
if (empty($opt_arg) &&
154+
empty($nextArg) /*false*/) {
144155
throw new PHPUnit_Framework_Exception(
145156
"option --$opt requires an argument"
146157
);
147158
}
159+
160+
$ret = true;
148161
}
149162
} elseif ($opt_arg) {
150163
throw new PHPUnit_Framework_Exception(
@@ -153,9 +166,9 @@ protected static function parseLongOption($arg, $long_options, &$opts, &$args)
153166
}
154167

155168
$full_option = '--' . preg_replace('/={1,2}$/', '', $long_opt);
156-
$opts[] = array($full_option, $opt_arg);
169+
$opts[] = array($full_option, $opt_arg);
157170

158-
return;
171+
return $ret;
159172
}
160173

161174
throw new PHPUnit_Framework_Exception("unrecognized option --$opt");

0 commit comments

Comments
 (0)