]> granicus.if.org Git - php/commitdiff
Add test case for bug #78883
authorChristoph M. Becker <cmbecker69@gmx.de>
Thu, 2 Jan 2020 18:25:31 +0000 (19:25 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Thu, 2 Jan 2020 18:28:10 +0000 (19:28 +0100)
The original test has been provided by divinity76.

ext/standard/tests/streams/bug78883.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/streams/bug78883.phpt b/ext/standard/tests/streams/bug78883.phpt
new file mode 100644 (file)
index 0000000..2dc1bc7
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--\r
+Bug #78883 (fgets(STDIN) fails on Windows)\r
+--SKIPIF--\r
+<?php\r
+if (PHP_OS_FAMILY !== 'Windows') die('skip this test is for Windows platforms only');\r
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");\r
+?>\r
+--FILE--\r
+<?php\r
+$descriptorspec = array(\r
+   0 => array("pipe", "rb"),\r
+   1 => array("pipe", "wb"),\r
+   //2 => array("file", "stderr.txt", "ab")\r
+);\r
+$pipes = [];\r
+$cmd = 'cmd.exe "/c START ^"^" /WAIT ' . PHP_BINARY . ' -r ^"var_dump(fgets(STDIN));"';\r
+$proc = proc_open($cmd, $descriptorspec, $pipes);\r
+var_dump(is_resource($proc));\r
+$pid = proc_get_status($proc)['pid'];\r
+sleep(1);\r
+$bug_is_present = !proc_get_status($proc)['running'];\r
+if (!$bug_is_present) {\r
+       // if the bug is not present, it will hang waiting for stdin,\r
+       // thus cmd is still running and we should kill it\r
+       shell_exec("taskkill /T /F /PID {$pid}");\r
+}\r
+fclose($pipes[0]);\r
+fclose($pipes[1]);\r
+proc_close($proc);\r
+var_dump($bug_is_present);\r
+?>\r
+--EXPECT--\r
+bool(true)\r
+bool(false)\r