summaryrefslogtreecommitdiff
path: root/ext/standard/tests/streams
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/tests/streams')
-rw-r--r--ext/standard/tests/streams/bug40459.phpt103
-rw-r--r--ext/standard/tests/streams/bug44712.phpt10
-rw-r--r--ext/standard/tests/streams/bug44818.phpt37
-rw-r--r--ext/standard/tests/streams/bug46024.phpt46
-rw-r--r--ext/standard/tests/streams/bug46426.phpt34
-rw-r--r--ext/standard/tests/streams/bug47997.phpt15
-rw-r--r--ext/standard/tests/streams/bug48309.phpt33
-rw-r--r--ext/standard/tests/streams/bug49936.phpt21
-rw-r--r--ext/standard/tests/streams/bug49936_win32.phpt30
-rw-r--r--ext/standard/tests/streams/bug53427.phpt27
-rw-r--r--ext/standard/tests/streams/bug53903.phpt32
-rw-r--r--ext/standard/tests/streams/bug54623.phpt17
-rw-r--r--ext/standard/tests/streams/bug54946.phpt39
-rw-r--r--ext/standard/tests/streams/bug60106.phpt23
-rw-r--r--ext/standard/tests/streams/bug60455_01.phpt21
-rw-r--r--ext/standard/tests/streams/bug60455_02.phpt31
-rw-r--r--ext/standard/tests/streams/bug60455_03.phpt55
-rw-r--r--ext/standard/tests/streams/bug60455_04.phpt32
-rw-r--r--ext/standard/tests/streams/bug60817.phpt36
-rw-r--r--ext/standard/tests/streams/bug61115-1.phpt17
-rw-r--r--ext/standard/tests/streams/bug61115-2.phpt10
-rw-r--r--ext/standard/tests/streams/bug61115.phpt13
-rw-r--r--ext/standard/tests/streams/bug61371-win.phpt45
-rw-r--r--ext/standard/tests/streams/bug61371.phpt45
-rw-r--r--ext/standard/tests/streams/bug63240.phpt17
-rw-r--r--ext/standard/tests/streams/stream_context_get_params_001.phpt121
-rw-r--r--ext/standard/tests/streams/stream_context_set_option_basic.phpt37
-rw-r--r--ext/standard/tests/streams/stream_context_set_option_error_001.phpt21
-rw-r--r--ext/standard/tests/streams/stream_context_set_option_error_002.phpt18
-rw-r--r--ext/standard/tests/streams/stream_copy_to_stream_socket.phpt30
-rw-r--r--ext/standard/tests/streams/stream_get_contents_001.phpt22
-rw-r--r--ext/standard/tests/streams/stream_get_contents_002.phpt18
-rw-r--r--ext/standard/tests/streams/stream_get_line_NUL_delimiter.phpt27
-rw-r--r--ext/standard/tests/streams/stream_get_line_nb.phpt66
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_dir_basic.phpt50
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_file_basic.phpt33
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_file_error.phpt57
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_file_variation1.phpt510
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_file_variation2.phpt135
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_file_variation4.phpt71
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_file_variation5.phpt77
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_process_basic.phpt36
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_socket_basic.phpt27
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_socket_variation1.phpt113
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_socket_variation2.phpt111
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_socket_variation3.phpt89
-rw-r--r--ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt92
-rw-r--r--ext/standard/tests/streams/stream_is_local.phpt17
-rw-r--r--ext/standard/tests/streams/stream_resolve_include_path.phpt37
-rw-r--r--ext/standard/tests/streams/stream_set_chunk_size.phpt93
-rw-r--r--ext/standard/tests/streams/stream_set_timeout_error.phpt74
-rw-r--r--ext/standard/tests/streams/stream_socket_pair.phpt19
52 files changed, 2790 insertions, 0 deletions
diff --git a/ext/standard/tests/streams/bug40459.phpt b/ext/standard/tests/streams/bug40459.phpt
new file mode 100644
index 0000000..8ee4363
--- /dev/null
+++ b/ext/standard/tests/streams/bug40459.phpt
@@ -0,0 +1,103 @@
+--TEST--
+bug 40459 - Test whether the constructor of the user-space stream wrapper is called when stream functions are called
+--FILE--
+<?php
+// Test whether the constructor of the user-space stream wrapper is called when stream functions are called
+class testwrapper {
+ private $constructorCalled = false;
+ function __construct() {
+ $this->constructorCalled = true;
+ }
+
+ function stream_open($path, $mode, $options, &$opened_path)
+ {
+ echo $this->constructorCalled ? 'yes' : 'no';
+ return true;
+ }
+
+ function url_stat($url, $flags)
+ {
+ echo $this->constructorCalled ? 'yes' : 'no';
+ return array();
+ }
+
+ function unlink($url)
+ {
+ echo $this->constructorCalled ? 'yes' : 'no';
+ }
+
+ function rename($from, $to)
+ {
+ echo $this->constructorCalled ? 'yes' : 'no';
+ }
+
+ function mkdir($dir, $mode, $options)
+ {
+ echo $this->constructorCalled ? 'yes' : 'no';
+ }
+
+ function rmdir($dir, $options)
+ {
+ echo $this->constructorCalled ? 'yes' : 'no';
+ }
+
+ function dir_opendir($url, $options)
+ {
+ echo $this->constructorCalled ? 'yes' : 'no';
+ return TRUE;
+ }
+ function stream_metadata()
+ {
+ echo $this->constructorCalled ? 'yes' : 'no';
+ return TRUE;
+ }
+}
+
+stream_wrapper_register('test', 'testwrapper', STREAM_IS_URL);
+
+echo 'stream_open: ';
+fopen('test://test', 'r');
+echo "\n";
+
+echo 'url_stat: ';
+stat('test://test');
+echo "\n";
+
+echo 'dir_opendir: ';
+opendir('test://test');
+echo "\n";
+
+echo 'rmdir: ';
+rmdir('test://test');
+echo "\n";
+
+echo 'mkdir: ';
+mkdir('test://test');
+echo "\n";
+
+echo 'rename: ';
+rename('test://test', 'test://test2');
+echo "\n";
+
+echo 'unlink: ';
+unlink('test://test');
+echo "\n";
+
+echo 'touch: ';
+touch('test://test', time());
+echo "\n";
+
+
+
+?>
+==DONE==
+--EXPECT--
+stream_open: yes
+url_stat: yes
+dir_opendir: yes
+rmdir: yes
+mkdir: yes
+rename: yes
+unlink: yes
+touch: yes
+==DONE==
diff --git a/ext/standard/tests/streams/bug44712.phpt b/ext/standard/tests/streams/bug44712.phpt
new file mode 100644
index 0000000..9dfb260
--- /dev/null
+++ b/ext/standard/tests/streams/bug44712.phpt
@@ -0,0 +1,10 @@
+--TEST--
+bug#44712 (stream_context_set_params segfaults on invalid arguments)
+--FILE--
+<?php
+$ctx = stream_context_get_default();
+stream_context_set_params($ctx, array("options" => 1));
+?>
+--EXPECTF--
+Warning: stream_context_set_params(): Invalid stream/context parameter in %sbug44712.php on line %s
+
diff --git a/ext/standard/tests/streams/bug44818.phpt b/ext/standard/tests/streams/bug44818.phpt
new file mode 100644
index 0000000..628f64e
--- /dev/null
+++ b/ext/standard/tests/streams/bug44818.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Bug #44818 (php://memory writeable when opened read only)
+--FILE--
+<?php
+function test($url, $mode) {
+ echo "$url, $mode\n";
+ $fd = fopen($url, $mode);
+ var_dump($fd, fwrite($fd, b"foo"));
+ var_dump(fseek($fd, 0, SEEK_SET), fread($fd, 3));
+ fclose($fd);
+}
+test("php://memory","r");
+test("php://memory","r+");
+test("php://temp","r");
+test("php://temp","w");
+?>
+--EXPECTF--
+php://memory, r
+resource(%d) of type (stream)
+int(0)
+int(0)
+string(0) ""
+php://memory, r+
+resource(%d) of type (stream)
+int(3)
+int(0)
+string(3) "foo"
+php://temp, r
+resource(%d) of type (stream)
+int(0)
+int(0)
+string(0) ""
+php://temp, w
+resource(%d) of type (stream)
+int(3)
+int(0)
+string(3) "foo"
diff --git a/ext/standard/tests/streams/bug46024.phpt b/ext/standard/tests/streams/bug46024.phpt
new file mode 100644
index 0000000..fdfd03e
--- /dev/null
+++ b/ext/standard/tests/streams/bug46024.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Bug #46024 stream_select() doesn't return the correct number
+--SKIPIF--
+<?php if (!getenv('TEST_PHP_EXECUTABLE')) die("skip TEST_PHP_EXECUTABLE not defined"); ?>
+--FILE--
+<?php
+$php = realpath(getenv('TEST_PHP_EXECUTABLE'));
+$pipes = array();
+$proc = proc_open(
+ "$php -n -i"
+ ,array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'))
+ ,$pipes, dirname(__FILE__), array(), array('binary_pipes' => true)
+);
+var_dump($proc);
+if (!$proc) {
+ exit(1);
+}
+$r = array($pipes[1]);
+$w = array($pipes[0]);
+$e = null;
+$ret = stream_select($r, $w, $e, 1);
+var_dump($ret === (count($r) + count($w)));
+fread($pipes[1], 1);
+
+$r = array($pipes[1]);
+$w = array($pipes[0]);
+$e = null;
+$ret = stream_select($r, $w, $e, 1);
+var_dump($ret === (count($r) + count($w)));
+
+
+foreach($pipes as $pipe) {
+ fclose($pipe);
+}
+proc_terminate($proc);
+if (defined('SIGKILL')) {
+ proc_terminate($proc, SIGKILL);
+} else {
+ proc_terminate($proc);
+}
+proc_close($proc);
+?>
+--EXPECTF--
+resource(%d) of type (process)
+bool(true)
+bool(true)
diff --git a/ext/standard/tests/streams/bug46426.phpt b/ext/standard/tests/streams/bug46426.phpt
new file mode 100644
index 0000000..80dbcde
--- /dev/null
+++ b/ext/standard/tests/streams/bug46426.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Bug #46426 (3rd parameter offset of stream_get_contents not works for "0")
+--FILE--
+<?php
+
+$tmp = tmpfile();
+
+fwrite($tmp, b"12345");
+
+echo stream_get_contents($tmp, 2, 1);
+echo "\n";
+echo stream_get_contents($tmp, -1);
+echo "\n";
+echo stream_get_contents($tmp, -1, 0);
+echo "\n";
+echo stream_get_contents($tmp, -1, 2);
+echo "\n";
+echo stream_get_contents($tmp, 0, 0);
+echo "\n";
+echo stream_get_contents($tmp, 1, 0);
+echo "\n";
+echo stream_get_contents($tmp, -1);
+
+@unlink($tmp);
+
+?>
+--EXPECT--
+23
+45
+12345
+345
+
+1
+2345
diff --git a/ext/standard/tests/streams/bug47997.phpt b/ext/standard/tests/streams/bug47997.phpt
new file mode 100644
index 0000000..f13a19d
--- /dev/null
+++ b/ext/standard/tests/streams/bug47997.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #47997 (stream_copy_to_stream returns 1 on empty streams)
+--INI--
+allow_url_fopen=1
+--FILE--
+<?php
+
+$in = fopen('data://text/plain,', 'rb+');
+$out = fopen('php://memory', 'wb+');
+
+var_dump(stream_copy_to_stream($in, $out));
+
+?>
+--EXPECT--
+int(0)
diff --git a/ext/standard/tests/streams/bug48309.phpt b/ext/standard/tests/streams/bug48309.phpt
new file mode 100644
index 0000000..d347cc3
--- /dev/null
+++ b/ext/standard/tests/streams/bug48309.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Bug #48309 (stream_copy_to_stream() and fpasstru() do not update stream position)
+--FILE--
+<?php
+
+$tmp = tmpfile();
+fwrite($tmp, b'test');
+fseek($tmp, 0, SEEK_SET);
+
+echo "-- stream_copy_to_stream() --\n";
+
+fseek($tmp, 0, SEEK_SET);
+stream_copy_to_stream($tmp, STDOUT, 2);
+
+echo "\n";
+var_dump(stream_get_contents($tmp));
+
+echo "-- fpassthru() --\n";
+
+fseek($tmp, 0, SEEK_SET);
+fpassthru($tmp);
+
+echo "\n";
+var_dump(stream_get_contents($tmp));
+
+?>
+--EXPECTF--
+-- stream_copy_to_stream() --
+te
+string(2) "st"
+-- fpassthru() --
+test
+string(0) ""
diff --git a/ext/standard/tests/streams/bug49936.phpt b/ext/standard/tests/streams/bug49936.phpt
new file mode 100644
index 0000000..d98db1d
--- /dev/null
+++ b/ext/standard/tests/streams/bug49936.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #49936 (crash with ftp stream in php_stream_context_get_option())
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) == "WIN" )
+ die("skip. Do not run on Windows");
+?>
+--FILE--
+<?php
+
+$dir = 'ftp://your:self@localhost/';
+
+var_dump(@opendir($dir));
+var_dump(@opendir($dir));
+
+?>
+===DONE===
+--EXPECTF--
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/standard/tests/streams/bug49936_win32.phpt b/ext/standard/tests/streams/bug49936_win32.phpt
new file mode 100644
index 0000000..4db4a50
--- /dev/null
+++ b/ext/standard/tests/streams/bug49936_win32.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Bug #49936 (crash with ftp stream in php_stream_context_get_option())
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) != "WIN" )
+ die("skip. Do run on Windows only");
+?>
+--INI--
+default_socket_timeout=2
+--FILE--
+<?php
+
+$dir = 'ftp://your:self@localhost/';
+
+var_dump(opendir($dir));
+var_dump(opendir($dir));
+
+?>
+--EXPECTF--
+Warning: opendir(): connect() failed: %s
+ in %s on line %d
+
+Warning: opendir(ftp://...@localhost/): failed to open dir: operation failed in %s on line %d
+bool(false)
+
+Warning: opendir(): connect() failed: %s
+ in %s on line %d
+
+Warning: opendir(ftp://...@localhost/): failed to open dir: operation failed in %s on line %d
+bool(false)
diff --git a/ext/standard/tests/streams/bug53427.phpt b/ext/standard/tests/streams/bug53427.phpt
new file mode 100644
index 0000000..9e2e037
--- /dev/null
+++ b/ext/standard/tests/streams/bug53427.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #53427 (stream_select does not preserve keys)
+--FILE--
+<?php
+$read[1] = fopen(__FILE__, "r");
+$read["myindex"] = reset($read);
+$write = NULL;
+$except = NULL;
+
+var_dump($read);
+
+stream_select($read, $write, $except, 0);
+
+var_dump($read);
+--EXPECTF--
+array(2) {
+ [1]=>
+ resource(%d) of type (stream)
+ ["myindex"]=>
+ resource(%d) of type (stream)
+}
+array(2) {
+ [1]=>
+ resource(%d) of type (stream)
+ ["myindex"]=>
+ resource(%d) of type (stream)
+}
diff --git a/ext/standard/tests/streams/bug53903.phpt b/ext/standard/tests/streams/bug53903.phpt
new file mode 100644
index 0000000..3b61635
--- /dev/null
+++ b/ext/standard/tests/streams/bug53903.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Bug #53903 streamwrapper/stream_stat causes problems
+--FILE--
+<?php
+
+class sw {
+
+ public function stream_open($path, $mode, $options, &$opened_path) {
+ return true;
+ }
+
+ public function stream_stat() {
+ return array(
+ 'atime' => $this->undefined,
+ );
+ }
+
+}
+stream_wrapper_register('sx', 'sw') or die('failed');
+
+fstat(fopen('sx://test', 'r'));
+
+$s[] = 1; // Cannot use a scalar value as an array
+
+print_r($s);
+--EXPECTF--
+Notice: Undefined property: sw::$undefined in %s on line %d
+Array
+(
+ [0] => 1
+)
+
diff --git a/ext/standard/tests/streams/bug54623.phpt b/ext/standard/tests/streams/bug54623.phpt
new file mode 100644
index 0000000..43bcb09
--- /dev/null
+++ b/ext/standard/tests/streams/bug54623.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #54623: Segfault when when writing to a persistent socket after closing a copy of the socket
+--FILE--
+<?php
+$sock = pfsockopen('udp://127.0.0.1', '63844');
+var_dump((int)$sock);
+@fwrite($sock, "1");
+$sock2 = pfsockopen('udp://127.0.0.1', '63844');
+var_dump((int)$sock2);
+@fwrite($sock2, "2");
+fclose($sock2);
+fwrite($sock, "3");
+--EXPECTF--
+int(%d)
+int(%d)
+
+Warning: fwrite(): %d is not a valid stream resource in %s on line %d
diff --git a/ext/standard/tests/streams/bug54946.phpt b/ext/standard/tests/streams/bug54946.phpt
new file mode 100644
index 0000000..b51d593
--- /dev/null
+++ b/ext/standard/tests/streams/bug54946.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Bug#54946 stream_get_contents infinite loop
+--FILE--
+<?php
+$filename = tempnam(__DIR__, "phpbug");
+$stream = fopen($filename, "w"); // w or a
+$retval = stream_get_contents($stream, 1, 1);
+fclose($stream);
+var_dump($retval);
+unlink($filename);
+
+
+
+$filename = tempnam(__DIR__, "phpbug2");
+
+$stream = fopen($filename, "a");
+$retval = stream_get_contents($stream, 1, 1);
+var_dump($retval);
+fclose($stream);
+unlink($filename);
+
+
+
+$filename = tempnam(__DIR__, "phpbug3");
+
+$stream = fopen($filename, "a");
+fseek($stream, 1);
+$retval = stream_get_contents($stream, 1);
+var_dump($retval);
+fclose($stream);
+unlink($filename);
+?>
+===DONE===
+--EXPECT--
+string(0) ""
+string(0) ""
+string(0) ""
+===DONE===
+
diff --git a/ext/standard/tests/streams/bug60106.phpt b/ext/standard/tests/streams/bug60106.phpt
new file mode 100644
index 0000000..1b36af1
--- /dev/null
+++ b/ext/standard/tests/streams/bug60106.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug#60106 (stream_socket_server silently truncates long unix socket paths)
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) == "WIN" )
+ die("skip. Do not run on Windows");
+?>
+--FILE--
+<?php
+error_reporting(E_ALL | E_NOTICE);
+$socket_file = "/tmp/" . str_repeat("a", 512);
+function get_truncated_socket_filename($errno, $errmsg, $file, $line) {
+ global $socket_file;
+ print_r ($errmsg);
+ preg_match("#maximum allowed length of (\d+) bytes#", $errmsg, $matches);
+ $socket_file = substr($socket_file, 0, intval($matches[1]) - 1);
+}
+set_error_handler("get_truncated_socket_filename", E_NOTICE);
+stream_socket_server("unix://" . $socket_file);
+unlink($socket_file);
+?>
+--EXPECTF--
+stream_socket_server(): socket path exceeded the maximum allowed length of %d bytes and was truncated
diff --git a/ext/standard/tests/streams/bug60455_01.phpt b/ext/standard/tests/streams/bug60455_01.phpt
new file mode 100644
index 0000000..4669982
--- /dev/null
+++ b/ext/standard/tests/streams/bug60455_01.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #60455: stream_get_line and 1-line noeol input
+--FILE--
+<?php
+
+//It's critical the read on the stream returns the input but doesn't set EOF
+//flag the first time. This is why we need to use sockets.
+
+$domain = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' ? STREAM_PF_INET : STREAM_PF_UNIX);
+$sockets = stream_socket_pair($domain, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP)
+ or die("stream_socket_pair");
+fwrite($sockets[0], "a");
+stream_socket_shutdown($sockets[0], STREAM_SHUT_RDWR);
+
+$f = $sockets[1];
+while (!feof($f)) {
+ $line = stream_get_line($f, 99, "\n");
+ var_dump($line);
+}
+--EXPECT--
+string(1) "a"
diff --git a/ext/standard/tests/streams/bug60455_02.phpt b/ext/standard/tests/streams/bug60455_02.phpt
new file mode 100644
index 0000000..0ddf346
--- /dev/null
+++ b/ext/standard/tests/streams/bug60455_02.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Bug #60455: stream_get_line and 1-line followed by eol input
+--FILE--
+<?php
+class TestStream {
+ private $s = 0;
+ function stream_open($path, $mode, $options, &$opened_path) {
+ return true;
+ }
+ function stream_read($count) {
+ if ($this->s++ == 0)
+ return "a\n";
+
+ return "";
+ }
+ function stream_eof() {
+ return $this->s >= 2;
+ }
+
+}
+
+stream_wrapper_register("test", "TestStream");
+
+$f = fopen("test://", "r");
+while (!feof($f)) {
+ $line = stream_get_line($f, 99, "\n");
+ var_dump($line);
+}
+--EXPECT--
+string(1) "a"
+bool(false)
diff --git a/ext/standard/tests/streams/bug60455_03.phpt b/ext/standard/tests/streams/bug60455_03.phpt
new file mode 100644
index 0000000..2429d31
--- /dev/null
+++ b/ext/standard/tests/streams/bug60455_03.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Bug #60455: stream_get_line and 2 lines, one possibly empty
+--FILE--
+<?php
+class TestStream {
+ private $lines = array();
+ private $s = 0;
+ private $eofth = 3;
+ function stream_open($path, $mode, $options, &$opened_path) {
+ $this->lines[] = "a\n";
+ $this->lines[] = ($path == "test://nonempty2nd" ? "b\n" : "\n");
+ if ($path == "test://eofafter2nd")
+ $this->eofth = 2;
+ return true;
+ }
+ function stream_read($count) {
+ if (key_exists($this->s++, $this->lines))
+ return $this->lines[$this->s - 1];
+
+ return "";
+ }
+ function stream_eof() {
+ return $this->s >= $this->eofth;
+ }
+
+}
+
+stream_wrapper_register("test", "TestStream");
+
+$f = fopen("test://nonempty2nd", "r");
+while (!feof($f)) {
+ $line = stream_get_line($f, 99, "\n");
+ var_dump($line);
+}
+$f = fopen("test://", "r");
+while (!feof($f)) {
+ $line = stream_get_line($f, 99, "\n");
+ var_dump($line);
+}
+$f = fopen("test://eofafter2nd", "r");
+while (!feof($f)) {
+ $line = stream_get_line($f, 99, "\n");
+ var_dump($line);
+}
+
+
+--EXPECT--
+string(1) "a"
+string(1) "b"
+bool(false)
+string(1) "a"
+string(0) ""
+bool(false)
+string(1) "a"
+string(0) ""
diff --git a/ext/standard/tests/streams/bug60455_04.phpt b/ext/standard/tests/streams/bug60455_04.phpt
new file mode 100644
index 0000000..3a82298
--- /dev/null
+++ b/ext/standard/tests/streams/bug60455_04.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Bug #60455: stream_get_line and 1-line with maxlen size followed by 0-length
+read with EOL indication
+--FILE--
+<?php
+class TestStream {
+ private $s = 0;
+ function stream_open($path, $mode, $options, &$opened_path) {
+ return true;
+ }
+ function stream_read($count) {
+ if ($this->s++ == 0)
+ return "a\n";
+
+ return "";
+ }
+ function stream_eof() {
+ return $this->s >= 2;
+ }
+
+}
+
+stream_wrapper_register("test", "TestStream");
+
+$f = fopen("test://", "r");
+while (!feof($f)) {
+ $line = stream_get_line($f, 2, "\n");
+ var_dump($line);
+}
+--EXPECT--
+string(1) "a"
+bool(false)
diff --git a/ext/standard/tests/streams/bug60817.phpt b/ext/standard/tests/streams/bug60817.phpt
new file mode 100644
index 0000000..2d4cf26
--- /dev/null
+++ b/ext/standard/tests/streams/bug60817.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Bug #60817: stream_get_line() reads from stream even when there is already sufficient data buffered
+--FILE--
+<?php
+class TestStream { //data, empty data, empty data + eof
+ private $s = 0;
+ function stream_open($path, $mode, $options, &$opened_path) {
+ return true;
+ }
+ function stream_read($count) {
+ echo "Read done\n";
+ if ($this->s++ == 0)
+ return "a\nbb\ncc";
+
+ return "";
+ }
+ function stream_eof() {
+ return $this->s >= 2;
+ }
+
+}
+
+stream_wrapper_register("test", "TestStream");
+
+$f = fopen("test://", "r");
+while (!feof($f)) {
+ $line = stream_get_line($f, 99, "\n");
+ var_dump($line);
+}
+
+--EXPECT--
+Read done
+string(1) "a"
+string(2) "bb"
+Read done
+string(2) "cc"
diff --git a/ext/standard/tests/streams/bug61115-1.phpt b/ext/standard/tests/streams/bug61115-1.phpt
new file mode 100644
index 0000000..99e2f79
--- /dev/null
+++ b/ext/standard/tests/streams/bug61115-1.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #61115: Stream related segfault on fatal error in php_stream_context_del_link - variation 1
+--SKIPIF--
+<?php
+if (getenv("USE_ZEND_ALLOC") === "0") {
+ die("skip Zend MM disabled");
+}
+?>
+--FILE--
+<?php
+
+$fileResourceTemp = fopen('php://temp', 'wr');
+stream_context_get_options($fileResourceTemp);
+ftruncate($fileResourceTemp, PHP_INT_MAX);
+?>
+--EXPECTF--
+Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d
diff --git a/ext/standard/tests/streams/bug61115-2.phpt b/ext/standard/tests/streams/bug61115-2.phpt
new file mode 100644
index 0000000..260b836
--- /dev/null
+++ b/ext/standard/tests/streams/bug61115-2.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Bug #61115: Stream related segfault on fatal error in php_stream_context_del_link - variation 2
+--FILE--
+<?php
+stream_socket_client('abc', $var, $var, 0, STREAM_CLIENT_PERSISTENT);
+
+?>
+==DONE==
+--EXPECT--
+==DONE==
diff --git a/ext/standard/tests/streams/bug61115.phpt b/ext/standard/tests/streams/bug61115.phpt
new file mode 100644
index 0000000..29dc7c1
--- /dev/null
+++ b/ext/standard/tests/streams/bug61115.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Bug #61115: Stream related segfault on fatal error in php_stream_context_del_link.
+--FILE--
+<?php
+
+$arrayLarge = array_fill(0, 113663, '*');
+
+$resourceFileTemp = fopen('php://temp', 'r+');
+stream_context_set_params($resourceFileTemp, array());
+preg_replace('', function() {}, $resourceFileTemp);
+?>
+--EXPECTF--
+Catchable fatal error: Object of class Closure could not be converted to string in %s on line %d
diff --git a/ext/standard/tests/streams/bug61371-win.phpt b/ext/standard/tests/streams/bug61371-win.phpt
new file mode 100644
index 0000000..dc70530
--- /dev/null
+++ b/ext/standard/tests/streams/bug61371-win.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #61371: stream_context_create() causes memory leaks on use streams_socket_create
+--SKIPIF--
+<?php
+if(substr(PHP_OS, 0, 3) != 'WIN' ) {
+ die('skip windows only test');
+}
+--FILE--
+<?php
+function test($doFclose) {
+$previous = null;
+$current = null;
+for($test=1;$test<=3;$test++) {
+ $current = memory_get_usage(true);
+ if (!is_null($previous)) {
+ var_dump($previous == $current);
+ }
+ $previous = $current;
+ echo 'memory: '.round($current / 1024, 0)."kb\n";
+ for($i=0;$i<=100;$i++) {
+ $context = stream_context_create(array());
+ $stream = stream_socket_client('udp://127.0.0.1:80', $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context);
+ if ($doFclose) fclose($stream);
+ unset($context);
+ unset($stream);
+ unset($errno);
+ unset($errstr);
+ }
+}
+}
+
+test(true);
+test(false);
+?>
+--EXPECTF--
+memory: %dkb
+bool(true)
+memory: %dkb
+bool(true)
+memory: %dkb
+memory: %dkb
+bool(true)
+memory: %dkb
+bool(true)
+memory: %dkb
diff --git a/ext/standard/tests/streams/bug61371.phpt b/ext/standard/tests/streams/bug61371.phpt
new file mode 100644
index 0000000..7c64d1d
--- /dev/null
+++ b/ext/standard/tests/streams/bug61371.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #61371: stream_context_create() causes memory leaks on use streams_socket_create
+--SKIPIF--
+<?php
+if(substr(PHP_OS, 0, 3) == 'WIN' ) {
+ die('skip non windows test');
+}
+--FILE--
+<?php
+function test($doFclose) {
+$previous = null;
+$current = null;
+for($test=1;$test<=3;$test++) {
+ $current = memory_get_usage(true);
+ if (!is_null($previous)) {
+ var_dump($previous == $current);
+ }
+ $previous = $current;
+ echo 'memory: '.round($current / 1024, 0)."kb\n";
+ for($i=0;$i<=100;$i++) {
+ $context = stream_context_create(array());
+ $stream = stream_socket_client('udp://0.0.0.0:80', $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context);
+ if ($doFclose) fclose($stream);
+ unset($context);
+ unset($stream);
+ unset($errno);
+ unset($errstr);
+ }
+}
+}
+
+test(true);
+test(false);
+?>
+--EXPECTF--
+memory: %dkb
+bool(true)
+memory: %dkb
+bool(true)
+memory: %dkb
+memory: %dkb
+bool(true)
+memory: %dkb
+bool(true)
+memory: %dkb
diff --git a/ext/standard/tests/streams/bug63240.phpt b/ext/standard/tests/streams/bug63240.phpt
new file mode 100644
index 0000000..7612c43
--- /dev/null
+++ b/ext/standard/tests/streams/bug63240.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #63240: stream_get_line() return contains delimiter string
+--FILE--
+<?php
+$fd = fopen('php://temp', 'r+');
+$delimiter = 'MM';
+$str = str_repeat('.', 8191) . $delimiter . "rest";
+fwrite($fd, $str);
+rewind($fd);
+$line = stream_get_line($fd, 9000, $delimiter);
+var_dump(strlen($line));
+$line = stream_get_line($fd, 9000, $delimiter);
+var_dump($line);
+?>
+--EXPECT--
+int(8191)
+string(4) "rest"
diff --git a/ext/standard/tests/streams/stream_context_get_params_001.phpt b/ext/standard/tests/streams/stream_context_get_params_001.phpt
new file mode 100644
index 0000000..d946184
--- /dev/null
+++ b/ext/standard/tests/streams/stream_context_get_params_001.phpt
@@ -0,0 +1,121 @@
+--TEST--
+stream_context_get_params()
+--FILE--
+<?php
+
+$ctx = stream_context_create();
+var_dump($ctx);
+var_dump(stream_context_get_params($ctx));
+
+var_dump(stream_context_set_option($ctx, "foo","bar","baz"));
+var_dump(stream_context_get_params($ctx));
+
+var_dump(stream_context_set_params($ctx, array("notification" => "stream_notification_callback")));
+var_dump(stream_context_get_params($ctx));
+
+var_dump(stream_context_set_params($ctx, array("notification" => array("stream","notification_callback"))));
+var_dump(stream_context_get_params($ctx));
+
+var_dump(stream_context_get_params($ctx));
+var_dump(stream_context_get_options($ctx));
+var_dump(stream_context_get_params($ctx));
+var_dump(stream_context_get_options($ctx));
+
+?>
+--EXPECTF--
+resource(%d) of type (stream-context)
+array(1) {
+ [%u|b%"options"]=>
+ array(0) {
+ }
+}
+bool(true)
+array(1) {
+ [%u|b%"options"]=>
+ array(1) {
+ [%u|b%"foo"]=>
+ array(1) {
+ [%u|b%"bar"]=>
+ %unicode|string%(3) "baz"
+ }
+ }
+}
+bool(true)
+array(2) {
+ [%u|b%"notification"]=>
+ %unicode|string%(28) "stream_notification_callback"
+ [%u|b%"options"]=>
+ array(1) {
+ [%u|b%"foo"]=>
+ array(1) {
+ [%u|b%"bar"]=>
+ %unicode|string%(3) "baz"
+ }
+ }
+}
+bool(true)
+array(2) {
+ [%u|b%"notification"]=>
+ array(2) {
+ [0]=>
+ %unicode|string%(6) "stream"
+ [1]=>
+ %unicode|string%(21) "notification_callback"
+ }
+ [%u|b%"options"]=>
+ array(1) {
+ [%u|b%"foo"]=>
+ array(1) {
+ [%u|b%"bar"]=>
+ %unicode|string%(3) "baz"
+ }
+ }
+}
+array(2) {
+ [%u|b%"notification"]=>
+ array(2) {
+ [0]=>
+ %unicode|string%(6) "stream"
+ [1]=>
+ %unicode|string%(21) "notification_callback"
+ }
+ [%u|b%"options"]=>
+ array(1) {
+ [%u|b%"foo"]=>
+ array(1) {
+ [%u|b%"bar"]=>
+ %unicode|string%(3) "baz"
+ }
+ }
+}
+array(1) {
+ [%u|b%"foo"]=>
+ array(1) {
+ [%u|b%"bar"]=>
+ %unicode|string%(3) "baz"
+ }
+}
+array(2) {
+ [%u|b%"notification"]=>
+ array(2) {
+ [0]=>
+ %unicode|string%(6) "stream"
+ [1]=>
+ %unicode|string%(21) "notification_callback"
+ }
+ [%u|b%"options"]=>
+ array(1) {
+ [%u|b%"foo"]=>
+ array(1) {
+ [%u|b%"bar"]=>
+ %unicode|string%(3) "baz"
+ }
+ }
+}
+array(1) {
+ [%u|b%"foo"]=>
+ array(1) {
+ [%u|b%"bar"]=>
+ %unicode|string%(3) "baz"
+ }
+}
diff --git a/ext/standard/tests/streams/stream_context_set_option_basic.phpt b/ext/standard/tests/streams/stream_context_set_option_basic.phpt
new file mode 100644
index 0000000..63730ee
--- /dev/null
+++ b/ext/standard/tests/streams/stream_context_set_option_basic.phpt
@@ -0,0 +1,37 @@
+--TEST--
+stream_context_set_option() function - basic test for stream_context_set_option()
+--CREDITS--
+Jean-Marc Fontaine <jean-marc.fontaine@alterway.fr>
+# Alter Way Contribution Day 2011
+--FILE--
+<?php
+$context = stream_context_create();
+
+// Single option
+var_dump(stream_context_set_option($context, 'http', 'method', 'POST'));
+
+// Array of options
+$options = array(
+ 'http' => array(
+ 'protocol_version' => 1.1,
+ 'user_agent' => 'PHPT Agent',
+ ),
+);
+var_dump(stream_context_set_option($context, $options));
+
+var_dump(stream_context_get_options($context));
+?>
+--EXPECT--
+bool(true)
+bool(true)
+array(1) {
+ ["http"]=>
+ array(3) {
+ ["method"]=>
+ string(4) "POST"
+ ["protocol_version"]=>
+ float(1.1)
+ ["user_agent"]=>
+ string(10) "PHPT Agent"
+ }
+}
diff --git a/ext/standard/tests/streams/stream_context_set_option_error_001.phpt b/ext/standard/tests/streams/stream_context_set_option_error_001.phpt
new file mode 100644
index 0000000..04b37ca
--- /dev/null
+++ b/ext/standard/tests/streams/stream_context_set_option_error_001.phpt
@@ -0,0 +1,21 @@
+--TEST--
+stream_context_set_option() function - error : invalid argument
+--CREDITS--
+Jean-Marc Fontaine <jean-marc.fontaine@alterway.fr>
+# Alter Way Contribution Day 2011
+--FILE--
+<?php
+$context = stream_context_create();
+
+// Single option
+var_dump(stream_context_set_option($context, 'http'));
+
+// Array of options
+var_dump(stream_context_set_option($context, array(), 'foo', 'bar'));
+?>
+--EXPECTF--
+Warning: stream_context_set_option(): called with wrong number or type of parameters; please RTM in %s on line %d
+bool(false)
+
+Warning: stream_context_set_option(): called with wrong number or type of parameters; please RTM in %s on line %d
+bool(false)
diff --git a/ext/standard/tests/streams/stream_context_set_option_error_002.phpt b/ext/standard/tests/streams/stream_context_set_option_error_002.phpt
new file mode 100644
index 0000000..e80fd39
--- /dev/null
+++ b/ext/standard/tests/streams/stream_context_set_option_error_002.phpt
@@ -0,0 +1,18 @@
+--TEST--
+stream_context_set_option() function - error : missing argument
+--CREDITS--
+Jean-Marc Fontaine <jean-marc.fontaine@alterway.fr>
+# Alter Way Contribution Day 2011
+--FILE--
+<?php
+var_dump(stream_context_set_option());
+
+$context = stream_context_create();
+var_dump(stream_context_set_option($context));
+?>
+--EXPECTF--
+Warning: stream_context_set_option(): called with wrong number or type of parameters; please RTM in %s on line %d
+bool(false)
+
+Warning: stream_context_set_option(): called with wrong number or type of parameters; please RTM in %s on line %d
+bool(false)
diff --git a/ext/standard/tests/streams/stream_copy_to_stream_socket.phpt b/ext/standard/tests/streams/stream_copy_to_stream_socket.phpt
new file mode 100644
index 0000000..7e304b1
--- /dev/null
+++ b/ext/standard/tests/streams/stream_copy_to_stream_socket.phpt
@@ -0,0 +1,30 @@
+--TEST--
+stream_copy_to_stream() with socket as $source
+--SKIPIF--
+<?php
+$sockets = @stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+if (!$sockets) die("skip stream_socket_pair");
+?>
+--FILE--
+<?php
+
+$sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+$tmp = tmpfile();
+
+fwrite($sockets[0], b"a");
+stream_socket_shutdown($sockets[0], STREAM_SHUT_WR);
+stream_copy_to_stream($sockets[1], $tmp);
+
+fseek($tmp, 0, SEEK_SET);
+var_dump(stream_get_contents($tmp));
+
+stream_copy_to_stream($sockets[1], $tmp);
+
+fseek($tmp, 0, SEEK_SET);
+var_dump(stream_get_contents($tmp));
+
+
+?>
+--EXPECT--
+string(1) "a"
+string(1) "a"
diff --git a/ext/standard/tests/streams/stream_get_contents_001.phpt b/ext/standard/tests/streams/stream_get_contents_001.phpt
new file mode 100644
index 0000000..e8e1c3d
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_contents_001.phpt
@@ -0,0 +1,22 @@
+--TEST--
+stream_get_contents() - Testing offset out of range
+--FILE--
+<?php
+
+$tmp = tmpfile();
+
+fwrite($tmp, b"12345");
+
+echo stream_get_contents($tmp, 2, 5), "--\n";
+echo stream_get_contents($tmp, 2), "--\n";
+echo stream_get_contents($tmp, 2, 3), "--\n";
+echo stream_get_contents($tmp, 2, -1), "--\n";
+
+@unlink($tmp);
+
+?>
+--EXPECT--
+--
+--
+45--
+--
diff --git a/ext/standard/tests/streams/stream_get_contents_002.phpt b/ext/standard/tests/streams/stream_get_contents_002.phpt
new file mode 100644
index 0000000..66ff3fb
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_contents_002.phpt
@@ -0,0 +1,18 @@
+--TEST--
+stream_get_contents() - Testing on socket with $maxlength
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') die("skip: non windows test");
+?>
+--FILE--
+<?php
+$sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+
+stream_set_timeout($sockets[1], 6000);
+
+fwrite($sockets[0], b"foo");
+var_dump(stream_get_contents($sockets[1], 3));
+
+?>
+--EXPECT--
+string(3) "foo"
diff --git a/ext/standard/tests/streams/stream_get_line_NUL_delimiter.phpt b/ext/standard/tests/streams/stream_get_line_NUL_delimiter.phpt
new file mode 100644
index 0000000..32756d7
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_line_NUL_delimiter.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #60455: stream_get_line and \0 as a delimiter
+--FILE--
+<?php
+class TestStream {
+ private $s = 0;
+ function stream_open($path, $mode, $options, &$opened_path) {
+ return true;
+ }
+ function stream_read($count) {
+ if ($this->s++ == 0)
+ return "a\0";
+
+ return "";
+ }
+ function stream_eof() {
+ return $this->s >= 2;
+ }
+
+}
+
+stream_wrapper_register("test", "TestStream");
+
+$f = fopen("test://", "r");
+var_dump(stream_get_line($f, 100, "\0"));
+--EXPECT--
+string(1) "a"
diff --git a/ext/standard/tests/streams/stream_get_line_nb.phpt b/ext/standard/tests/streams/stream_get_line_nb.phpt
new file mode 100644
index 0000000..ce98120
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_line_nb.phpt
@@ -0,0 +1,66 @@
+--TEST--
+stream_get_line() on non-blocking stream
+--SKIPIF--
+<?php
+$sockets = @stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+if (!$sockets) die("skip stream_socket_pair() should work");
+fclose($sockets[0]);
+fclose($sockets[1]);
+?>
+--FILE--
+<?php
+/**
+ * Tests that stream_get_line() behaves as documented on non-blocking streams:
+ * Never return incomplete lines, except on documented conditions:
+ * length bytes have been read, the string specified by ending is found, EOF.
+ */
+
+$sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+var_dump($sockets);
+
+stream_set_blocking($sockets[1], 0);
+
+$eol = b'<EOL>';
+
+fwrite($sockets[0], b"line start");
+var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
+var_dump(stream_get_line($sockets[1], 8192, $eol));
+fwrite($sockets[0], b", line end");
+fwrite($sockets[0], b", $eol");
+var_dump(stream_get_line($sockets[1], 8192, $eol)); // Returns full line (EOL found)
+var_dump(stream_get_line($sockets[1], 8192, $eol)); // Nothing to read
+var_dump(stream_get_line($sockets[1], 8192, $eol));
+
+fwrite($sockets[0], b"incomplete line");
+var_dump(stream_get_line($sockets[1], strlen(b"incomplete line"), $eol)); // EOL not found but $length has been read, return incomplete line
+
+fwrite($sockets[0], b"incomplete line");
+var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
+var_dump(fread($sockets[1], strlen(b"incomplete line"))); // Returns buffer readden by stream_get_line
+
+fwrite($sockets[0], b"end of file");
+var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
+
+fclose($sockets[0]);
+var_dump(stream_get_line($sockets[1], 8192, $eol)); // Returns incomplete line (End of file)
+
+fclose($sockets[1]);
+
+?>
+--EXPECTF--
+array(2) {
+ [0]=>
+ resource(%d) of type (stream)
+ [1]=>
+ resource(%d) of type (stream)
+}
+bool(false)
+bool(false)
+string(22) "line start, line end, "
+bool(false)
+bool(false)
+string(15) "incomplete line"
+bool(false)
+string(15) "incomplete line"
+bool(false)
+string(11) "end of file"
diff --git a/ext/standard/tests/streams/stream_get_meta_data_dir_basic.phpt b/ext/standard/tests/streams/stream_get_meta_data_dir_basic.phpt
new file mode 100644
index 0000000..f46c8fd
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_dir_basic.phpt
@@ -0,0 +1,50 @@
+--TEST--
+stream_get_meta_data() on directories
+--FILE--
+<?php
+
+$dir = opendir(dirname(__FILE__));
+var_dump(stream_get_meta_data($dir));
+closedir($dir);
+
+$dirObject = dir(dirname(__FILE__));
+var_dump(stream_get_meta_data($dirObject->handle));
+
+?>
+--EXPECT--
+array(8) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(3) "dir"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(8) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(3) "dir"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_basic.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_basic.phpt
new file mode 100644
index 0000000..4758c75
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_file_basic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+stream_get_meta_data() basic functionality
+--FILE--
+<?php
+
+$fp = fopen(__FILE__, "r");
+
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+?>
+--EXPECTF--
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%sstream_get_meta_data_file_basic.php"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_error.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_error.phpt
new file mode 100644
index 0000000..390694a
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_file_error.phpt
@@ -0,0 +1,57 @@
+--TEST--
+Test stream_get_meta_data() function : error conditions
+--FILE--
+<?php
+/* Prototype : proto array stream_get_meta_data(resource fp)
+ * Description: Retrieves header/meta data from streams/file pointers
+ * Source code: ext/standard/streamsfuncs.c
+ * Alias to functions: socket_get_status
+ */
+
+echo "*** Testing stream_get_meta_data() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing stream_get_meta_data() function with Zero arguments --\n";
+var_dump( stream_get_meta_data() );
+
+//Test stream_get_meta_data with one more than the expected number of arguments
+echo "\n-- Testing stream_get_meta_data() function with more than expected no. of arguments --\n";
+
+$fp = null;
+$extra_arg = 10;
+var_dump( stream_get_meta_data($fp, $extra_arg) );
+
+echo "\n-- Testing stream_get_meta_data() function with invalid stream resource --\n";
+$fp = null;
+var_dump(stream_get_meta_data($fp));
+
+echo "\n-- Testing stream_get_meta_data() function with closed stream resource --\n";
+$fp = fopen(__FILE__, 'r');
+fclose($fp);
+var_dump(stream_get_meta_data($fp));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing stream_get_meta_data() : error conditions ***
+
+-- Testing stream_get_meta_data() function with Zero arguments --
+
+Warning: stream_get_meta_data() expects exactly 1 parameter, 0 given in %s on line %i
+NULL
+
+-- Testing stream_get_meta_data() function with more than expected no. of arguments --
+
+Warning: stream_get_meta_data() expects exactly 1 parameter, 2 given in %s on line %i
+NULL
+
+-- Testing stream_get_meta_data() function with invalid stream resource --
+
+Warning: stream_get_meta_data() expects parameter 1 to be resource, null given in %s on line %i
+NULL
+
+-- Testing stream_get_meta_data() function with closed stream resource --
+
+Warning: stream_get_meta_data(): %i is not a valid stream resource in %s on line %i
+bool(false)
+Done
diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_variation1.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_variation1.phpt
new file mode 100644
index 0000000..572653e
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_file_variation1.phpt
@@ -0,0 +1,510 @@
+--TEST--
+stream_get_meta_data() with differing file access modes
+--FILE--
+<?php
+
+// array of all file access modes
+$filemodes = array('r', 'r+', 'w', 'w+', 'a', 'a+', 'x', 'x+',
+ 'rb', 'rb+', 'wb', 'wb+', 'ab', 'ab+', 'xb', 'xb+',
+ 'rt', 'rt+', 'wt', 'wt+', 'at', 'at+', 'xt', 'xt+');
+
+//create a file
+$filename = __FILE__ . '.tmp';
+$fp = fopen($filename, 'w+');
+fclose($fp);
+
+// open file in each access mode and get meta data
+foreach ($filemodes as $mode) {
+ if (strncmp($mode, 'x', 1) == 0) {
+ // x modes require that file does not exist
+ unlink($filename);
+ }
+ $fp = fopen($filename, $mode);
+ var_dump(stream_get_meta_data($fp));
+ fclose($fp);
+}
+
+unlink($filename);
+
+?>
+--EXPECTF--
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "w"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "a"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "a+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "x"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "x+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "rb"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "rb+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "wb"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "wb+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "ab"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "ab+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "xb"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "xb+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "rt"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "rt+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "wt"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "wt+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "at"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "at+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "xt"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "xt+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_variation2.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_variation2.phpt
new file mode 100644
index 0000000..d186cb7
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_file_variation2.phpt
@@ -0,0 +1,135 @@
+--TEST--
+Testing stream_get_meta_data() "unread_bytes" field
+--FILE--
+<?php
+
+$filename = __FILE__ . '.tmp';
+
+$fp = fopen($filename, "w+");
+
+echo "Write some data to the file:\n";
+$i = 0;
+while ($i++ < 20) {
+ fwrite($fp, "a line of data\n");
+}
+
+var_dump(stream_get_meta_data($fp));
+
+//seek to start of file
+rewind($fp);
+
+echo "\n\nRead a line of the file, causing data to be buffered:\n";
+var_dump(fgets($fp));
+
+var_dump(stream_get_meta_data($fp));
+
+echo "\n\nRead 20 bytes from the file:\n";
+fread($fp, 20);
+
+var_dump(stream_get_meta_data($fp));
+
+echo "\n\nRead entire file:\n";
+while(!feof($fp)) {
+ fread($fp, 1);
+}
+
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+unlink($filename);
+
+?>
+--EXPECTF--
+Write some data to the file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read a line of the file, causing data to be buffered:
+string(15) "a line of data
+"
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(285)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read 20 bytes from the file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(265)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read entire file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(true)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_variation4.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_variation4.phpt
new file mode 100644
index 0000000..c51d9bd
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_file_variation4.phpt
@@ -0,0 +1,71 @@
+--TEST--
+stream_get_meta_data() with a relative file path
+--FILE--
+<?php
+
+echo "Create a file:\n";
+$filename = __FILE__ . '.tmp';
+$fp = fopen('File://' . $filename, 'w+');
+
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+echo "\nChange to file's directory and open with a relative path:\n";
+
+$dirname = dirname($filename);
+chdir($dirname);
+$relative_filename = basename($filename);
+
+$fp = fopen($relative_filename, 'r');
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+unlink($filename);
+
+?>
+--EXPECTF--
+Create a file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "File://%sstream_get_meta_data_file_variation4.php.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+Change to file's directory and open with a relative path:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "stream_get_meta_data_file_variation4.php.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_variation5.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_variation5.phpt
new file mode 100644
index 0000000..386b92f
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_file_variation5.phpt
@@ -0,0 +1,77 @@
+--TEST--
+testing stream_get_meta_data() "eof" field for a file stream
+--FILE--
+<?php
+
+$filename = __FILE__ . '.tmp';
+
+$fp = fopen($filename, "w+");
+
+echo "Write some data to the file:\n";
+$i = 0;
+while ($i++ < 20) {
+ fwrite($fp, "a line of data\n");
+}
+
+var_dump(stream_get_meta_data($fp));
+
+//seek to start of file
+rewind($fp);
+
+echo "\n\nRead entire file:\n";
+while(!feof($fp)) {
+ fread($fp, 1);
+}
+
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+unlink($filename);
+
+?>
+--EXPECTF--
+Write some data to the file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read entire file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(true)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_process_basic.phpt b/ext/standard/tests/streams/stream_get_meta_data_process_basic.phpt
new file mode 100644
index 0000000..3f4dfbc
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_process_basic.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Testing stream_get_meta_data() on a process stream.
+--FILE--
+<?php
+
+$output_file = __FILE__.'.tmp';
+$cmd = "echo here is some output";
+$mode = 'rb';
+$handle = popen($cmd, $mode);
+$data = fread($handle, 100);
+
+var_dump(stream_get_meta_data($handle));
+
+pclose($handle);
+
+echo "Done";
+
+?>
+--EXPECT--
+array(7) {
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "rb"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+Done
diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_basic.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_basic.phpt
new file mode 100644
index 0000000..8605611
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_socket_basic.phpt
@@ -0,0 +1,27 @@
+--TEST--
+stream_get_meta_data() on a udp socket
+--FILE--
+<?php
+
+$tcp_socket = stream_socket_server('tcp://127.0.0.1:31337');
+var_dump(stream_get_meta_data($tcp_socket));
+fclose($tcp_socket);
+
+?>
+--EXPECTF--
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_variation1.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_variation1.phpt
new file mode 100644
index 0000000..16b38d9
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_socket_variation1.phpt
@@ -0,0 +1,113 @@
+--TEST--
+Testing stream_get_meta_data() "unread_bytes" field on a udp socket
+--FILE--
+<?php
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+if (!$client) {
+ die("Unable to create socket");
+}
+
+/* Accept that connection */
+$socket = stream_socket_accept($server);
+
+echo "Write some data:\n";
+fwrite($socket, "abcdefg\n1234567\nxyzxyz\n");
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nRead a line from the client, causing data to be buffered:\n";
+fgets($client);
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nRead 3 bytes of data from the client:\n";
+fread($client, 3);
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nClose the server side socket and read the remaining data from the client:\n";
+fclose($socket);
+fclose($server);
+while(!feof($client)) {
+ fread($client, 1);
+}
+var_dump(stream_get_meta_data($client));
+
+?>
+--EXPECTF--
+Write some data:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read a line from the client, causing data to be buffered:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(15)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read 3 bytes of data from the client:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(12)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Close the server side socket and read the remaining data from the client:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(true)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_variation2.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_variation2.phpt
new file mode 100644
index 0000000..d30fec7
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_socket_variation2.phpt
@@ -0,0 +1,111 @@
+--TEST--
+Testing stream_get_meta_data() "timed_out" field on a udp socket
+--FILE--
+<?php
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+if (!$client) {
+ die("Unable to create socket");
+}
+
+/* Accept that connection */
+$socket = stream_socket_accept($server);
+
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nSet a timeout on the client and attempt a read:\n";
+socket_set_timeout($client, 0, 1000);
+fread($client, 1);
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nWrite some data from the server:\n";
+fwrite($socket, "12345");
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nRead some data from the client:\n";
+fread($client, 5);
+var_dump(stream_get_meta_data($client));
+
+fclose($client);
+fclose($socket);
+fclose($server);
+
+?>
+--EXPECTF--
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Set a timeout on the client and attempt a read:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(true)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Write some data from the server:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(true)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read some data from the client:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_variation3.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_variation3.phpt
new file mode 100644
index 0000000..0b079cc
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_socket_variation3.phpt
@@ -0,0 +1,89 @@
+--TEST--
+Testing stream_get_meta_data() "blocked" field on a udp socket
+--FILE--
+<?php
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+if (!$client) {
+ die("Unable to create socket");
+}
+
+/* Accept that connection */
+$socket = stream_socket_accept($server);
+
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nSet blocking to false:\n";
+var_dump(socket_set_blocking($client, 0));
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nSet blocking to true:\n";
+var_dump(socket_set_blocking($client, 1));
+var_dump(stream_get_meta_data($client));
+
+fclose($client);
+fclose($socket);
+fclose($server);
+
+?>
+--EXPECTF--
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Set blocking to false:
+bool(true)
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(false)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Set blocking to true:
+bool(true)
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt
new file mode 100644
index 0000000..f9ef747
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt
@@ -0,0 +1,92 @@
+--TEST--
+Testing stream_get_meta_data() "eof" field on a udp socket
+--FILE--
+<?php
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+if (!$client) {
+ die("Unable to create socket");
+}
+
+/* Accept that connection */
+$socket = stream_socket_accept($server);
+
+echo "Write some data:\n";
+fwrite($socket, "abcdefg\n1234567\nxyzxyz\n");
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nRead a line from the client:\n";
+fgets($client);
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nClose the server side socket and read the remaining data from the client:\n";
+fclose($socket);
+fclose($server);
+while(!feof($client)) {
+ fread($client, 1);
+}
+var_dump(stream_get_meta_data($client));
+
+fclose($client);
+
+?>
+--EXPECTF--
+Write some data:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(%i)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read a line from the client:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(%i)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Close the server side socket and read the remaining data from the client:
+array(7) {
+ ["stream_type"]=>
+ string(%d) "tcp_socke%s"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(%i)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(true)
+}
diff --git a/ext/standard/tests/streams/stream_is_local.phpt b/ext/standard/tests/streams/stream_is_local.phpt
new file mode 100644
index 0000000..c90eb19
--- /dev/null
+++ b/ext/standard/tests/streams/stream_is_local.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Testing stream_is_local()
+--FILE--
+<?php
+
+$a = 1;
+$b = $a;
+var_dump(stream_is_local($b));
+var_dump($b);
+
+var_dump(stream_is_local(fopen(__FILE__, 'r')));
+
+?>
+--EXPECT--
+bool(true)
+int(1)
+bool(true)
diff --git a/ext/standard/tests/streams/stream_resolve_include_path.phpt b/ext/standard/tests/streams/stream_resolve_include_path.phpt
new file mode 100644
index 0000000..aea5cdd
--- /dev/null
+++ b/ext/standard/tests/streams/stream_resolve_include_path.phpt
@@ -0,0 +1,37 @@
+--TEST--
+stream_resolve_include_path(string path)
+--FILE--
+<?php
+$include_path = __DIR__ . '/test_path';
+$include_path_nested = $include_path . '/nested';
+
+$include_path_file = $include_path . DIRECTORY_SEPARATOR . 'file';
+$include_path_nested_file = $include_path_nested . DIRECTORY_SEPARATOR . 'file';
+
+mkdir($include_path);
+mkdir($include_path_nested);
+
+file_put_contents($include_path_file, 'include_path');
+file_put_contents($include_path_nested_file, 'include_path');
+
+var_dump(stream_resolve_include_path());
+
+set_include_path($include_path . PATH_SEPARATOR . $include_path_nested);
+var_dump(stream_resolve_include_path('file-does-not-exist'));
+
+set_include_path($include_path . PATH_SEPARATOR . $include_path_nested);
+var_dump(stream_resolve_include_path('file'));
+set_include_path($include_path_nested . PATH_SEPARATOR . $include_path);
+var_dump(stream_resolve_include_path('file'));
+
+unlink($include_path_nested_file);
+rmdir($include_path_nested);
+unlink($include_path_file);
+rmdir($include_path);
+--EXPECTF--
+Warning: stream_resolve_include_path() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+bool(false)
+string(%d) "%stest_path%sfile"
+string(%d) "%stest_path%snested%sfile"
+
diff --git a/ext/standard/tests/streams/stream_set_chunk_size.phpt b/ext/standard/tests/streams/stream_set_chunk_size.phpt
new file mode 100644
index 0000000..193bc1a
--- /dev/null
+++ b/ext/standard/tests/streams/stream_set_chunk_size.phpt
@@ -0,0 +1,93 @@
+--TEST--
+stream_set_chunk_size basic tests
+--FILE--
+<?php
+class test_wrapper {
+ function stream_open($path, $mode, $openedpath) {
+ return true;
+ }
+ function stream_eof() {
+ return false;
+ }
+ function stream_read($count) {
+ echo "read with size: ", $count, "\n";
+ return str_repeat('a', $count);
+ }
+ function stream_write($data) {
+ echo "write with size: ", strlen($data), "\n";
+ return strlen($data);
+ }
+ function stream_set_option($option, $arg1, $arg2) {
+ echo "option: ", $option, ", ", $arg1, ", ", $arg2, "\n";
+ return false;
+ }
+}
+
+var_dump(stream_wrapper_register('test', 'test_wrapper'));
+
+$f = fopen("test://foo","r");
+
+/* when the chunk size is 1, the read buffer is skipped, but the
+ * the writes are made in chunks of size 1 (business as usual)
+ * This should probably be revisited */
+echo "should return previous chunk size (8192)\n";
+var_dump(stream_set_chunk_size($f, 1));
+echo "should be read without buffer (\$count == 10000)\n";
+var_dump(strlen(fread($f, 10000)));
+echo "should elicit 3 writes of size 1 and return 3\n";
+var_dump(fwrite($f, str_repeat('b', 3)));
+
+echo "should return previous chunk size (1)\n";
+var_dump(stream_set_chunk_size($f, 100));
+echo "should elicit one read of size 100 (chunk size)\n";
+var_dump(strlen(fread($f, 250)));
+echo "should elicit one read of size 100 (chunk size)\n";
+var_dump(strlen(fread($f, 50)));
+echo "should elicit no read because there is sufficient cached data\n";
+var_dump(strlen(fread($f, 50)));
+echo "should elicit 2 writes of size 100 and one of size 50\n";
+var_dump(strlen(fwrite($f, str_repeat('b', 250))));
+
+echo "\nerror conditions\n";
+var_dump(stream_set_chunk_size($f, 0));
+var_dump(stream_set_chunk_size($f, -1));
+var_dump(stream_set_chunk_size($f, array()));
+
+--EXPECTF--
+bool(true)
+should return previous chunk size (8192)
+int(8192)
+should be read without buffer ($count == 10000)
+read with size: 10000
+int(10000)
+should elicit 3 writes of size 1 and return 3
+write with size: 1
+write with size: 1
+write with size: 1
+int(3)
+should return previous chunk size (1)
+int(1)
+should elicit one read of size 100 (chunk size)
+read with size: 100
+int(100)
+should elicit one read of size 100 (chunk size)
+read with size: 100
+int(50)
+should elicit no read because there is sufficient cached data
+int(50)
+should elicit 2 writes of size 100 and one of size 50
+write with size: 100
+write with size: 100
+write with size: 50
+int(3)
+
+error conditions
+
+Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given 0 in %s on line %d
+bool(false)
+
+Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given -1 in %s on line %d
+bool(false)
+
+Warning: stream_set_chunk_size() expects parameter 2 to be long, array given in %s on line %d
+bool(false)
diff --git a/ext/standard/tests/streams/stream_set_timeout_error.phpt b/ext/standard/tests/streams/stream_set_timeout_error.phpt
new file mode 100644
index 0000000..c1d4d14
--- /dev/null
+++ b/ext/standard/tests/streams/stream_set_timeout_error.phpt
@@ -0,0 +1,74 @@
+--TEST--
+Test stream_set_timeout() function : error conditions
+--FILE--
+<?php
+/* Prototype : proto bool stream_set_timeout(resource stream, int seconds, int microseconds)
+ * Description: Set timeout on stream read to seconds + microseonds
+ * Source code: ext/standard/streamsfuncs.c
+ * Alias to functions: socket_set_timeout
+ */
+
+echo "*** Testing stream_set_timeout() : error conditions ***\n";
+
+//Test stream_set_timeout with one more than the expected number of arguments
+echo "\n-- Testing stream_set_timeout() function with more than expected no. of arguments --\n";
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+
+$seconds = 10;
+$microseconds = 10;
+$extra_arg = 10;
+var_dump( stream_set_timeout($client, $seconds, $microseconds, $extra_arg) );
+
+// Testing stream_set_timeout with one less than the expected number of arguments
+echo "\n-- Testing stream_set_timeout() function with less than expected no. of arguments --\n";
+
+$seconds = 10;
+var_dump( stream_set_timeout($client) );
+
+
+echo "\n-- Testing stream_set_timeout() function with a closed socket --\n";
+fclose($client);
+var_dump( stream_set_timeout($client, $seconds) );
+
+echo "\n-- Testing stream_set_timeout() function with an invalid stream --\n";
+var_dump( stream_set_timeout($seconds, $seconds) );
+
+echo "\n-- Testing stream_set_timeout() function with a stream that does not support timeouts --\n";
+$filestream = fopen(__FILE__, "r");
+var_dump( stream_set_timeout($filestream, $seconds) );
+
+fclose($filestream);
+fclose($server);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing stream_set_timeout() : error conditions ***
+
+-- Testing stream_set_timeout() function with more than expected no. of arguments --
+
+Warning: stream_set_timeout() expects at most 3 parameters, 4 given in %s on line %i
+NULL
+
+-- Testing stream_set_timeout() function with less than expected no. of arguments --
+
+Warning: stream_set_timeout() expects at least 2 parameters, 1 given in %s on line %i
+NULL
+
+-- Testing stream_set_timeout() function with a closed socket --
+
+Warning: stream_set_timeout(): %i is not a valid stream resource in %s on line %i
+bool(false)
+
+-- Testing stream_set_timeout() function with an invalid stream --
+
+Warning: stream_set_timeout() expects parameter 1 to be resource, integer given in %s on line %i
+NULL
+
+-- Testing stream_set_timeout() function with a stream that does not support timeouts --
+bool(false)
+Done
diff --git a/ext/standard/tests/streams/stream_socket_pair.phpt b/ext/standard/tests/streams/stream_socket_pair.phpt
new file mode 100644
index 0000000..203ae98
--- /dev/null
+++ b/ext/standard/tests/streams/stream_socket_pair.phpt
@@ -0,0 +1,19 @@
+--TEST--
+stream_socket_pair()
+--FILE--
+<?php
+$domain = (strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? STREAM_PF_INET : STREAM_PF_UNIX);
+$sockets = stream_socket_pair($domain, STREAM_SOCK_STREAM, 0);
+var_dump($sockets);
+fwrite($sockets[0], b"foo");
+var_dump(fread($sockets[1], strlen(b"foo")));
+fclose($sockets[0]);
+?>
+--EXPECTF--
+array(2) {
+ [0]=>
+ resource(%d) of type (stream)
+ [1]=>
+ resource(%d) of type (stream)
+}
+string(3) "foo"