Skip to content

Commit dd44a93

Browse files
committed
Fix test bug60120.phpt
The process cmd was broken. We're now also checking that the process output is actually what we expect. Closes GH-11064
1 parent 884eb4b commit dd44a93

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

ext/standard/tests/file/bug60120.phpt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ $php = getenv('TEST_PHP_EXECUTABLE');
66
if (!$php) {
77
die("skip No php executable defined\n");
88
}
9+
if (PHP_OS_FAMILY === 'Windows') die('skip not for Windows');
910
?>
1011
--FILE--
1112
<?php
@@ -16,7 +17,7 @@ $php = getenv('TEST_PHP_EXECUTABLE');
1617
if (!$php) {
1718
die("No php executable defined\n");
1819
}
19-
$cmd = 'php -r "fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);"';
20+
$cmd = $php . ' -r "\$in = file_get_contents(\'php://stdin\'); fwrite(STDOUT, \$in); fwrite(STDERR, \$in);"';
2021
$descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
2122
$stdin = str_repeat('*', 2049 );
2223

@@ -32,6 +33,7 @@ $stdinOffset = 0;
3233

3334
unset($pipes[0]);
3435

36+
$procOutput = [];
3537
while ($pipes || $writePipes) {
3638
$r = $pipes;
3739
$w = $writePipes;
@@ -48,6 +50,8 @@ while ($pipes || $writePipes) {
4850
$written = fwrite($writePipes[0], substr($stdin, $stdinOffset), 8192);
4951
if (false !== $written) {
5052
$stdinOffset += $written;
53+
} else {
54+
die('Failed to write to pipe');
5155
}
5256
if ($stdinOffset >= $stdinLen) {
5357
fclose($writePipes[0]);
@@ -58,12 +62,21 @@ while ($pipes || $writePipes) {
5862
foreach ($r as $pipe) {
5963
$type = array_search($pipe, $pipes);
6064
$data = fread($pipe, 8192);
61-
if (false === $data || feof($pipe)) {
65+
if (feof($pipe)) {
6266
fclose($pipe);
6367
unset($pipes[$type]);
68+
} elseif (false === $data) {
69+
die('Failed to read from pipe');
70+
} else {
71+
$procOutput[$type] = ($procOutput[$type] ?? '') . $data;
6472
}
6573
}
6674
}
75+
foreach ($procOutput as $output) {
76+
if ($output !== $stdin) {
77+
die('Output does not match input: ' . $output);
78+
}
79+
}
6780
echo "OK.";
6881
?>
6982
--EXPECT--

0 commit comments

Comments
 (0)