Skip to content

Commit b4d7387

Browse files
committed
Make setcookie() test more robust against the passage of time
1 parent 07f6c61 commit b4d7387

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

ext/standard/tests/network/setcookie.phpt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,18 @@ if (($i = count($expected)) > count($headers))
4444
return;
4545
}
4646

47-
do
48-
{
49-
if (strncmp(current($headers), 'Set-Cookie:', 11) !== 0)
50-
{
47+
do {
48+
$header = current($headers);
49+
if (strncmp($header, 'Set-Cookie:', 11) !== 0) {
5150
continue;
5251
}
5352

54-
if (current($headers) === current($expected))
55-
{
53+
// If the second rolls over between the time() call and the internal time determination by
54+
// setcookie(), we might get Max-Age=4 instead of Max-Age=5.
55+
$header = str_replace('Max-Age=4', 'Max-Age=5', $header);
56+
if ($header === current($expected)) {
5657
$i--;
57-
}
58-
else
59-
{
58+
} else {
6059
echo "Header mismatch:\n\tExpected: "
6160
.current($expected)
6261
."\n\tReceived: ".current($headers)."\n";

0 commit comments

Comments
 (0)