Skip to content

Commit 1dc831d

Browse files
committed
ext/standard/tests/file: add test with interleaved read/write/copy calls
1 parent 696bd9b commit 1dc831d

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
stream_copy_to_stream() tests with interleaved read/write calls
3+
--FILE--
4+
<?php
5+
define('WIN', substr(PHP_OS, 0, 3) == 'WIN');
6+
7+
$initial_file = __DIR__.'/bug38086.txt';
8+
$new_file = __DIR__.'/stream_copy_to_stream_interleaved.txt';
9+
10+
$src = fopen($initial_file, 'r');
11+
12+
$dest = fopen($new_file, 'w');
13+
14+
var_dump(fread($src, 10));
15+
var_dump(fwrite($dest, "foo"));
16+
var_dump(stream_copy_to_stream($src, $dest, 10));
17+
var_dump(ftell($src));
18+
var_dump(ftell($dest));
19+
var_dump(fread($src, 10));
20+
var_dump(fwrite($dest, "bar"));
21+
var_dump(stream_copy_to_stream($src, $dest, 10));
22+
var_dump(ftell($src));
23+
var_dump(ftell($dest));
24+
fclose($src); fclose($dest);
25+
26+
if (WIN) {
27+
var_dump(str_replace("\r\n","\n", file_get_contents($new_file)));
28+
} else {
29+
var_dump(file_get_contents($new_file));
30+
}
31+
unlink($new_file);
32+
33+
echo "Done\n";
34+
?>
35+
--EXPECTF--
36+
string(10) "Another da"
37+
int(3)
38+
int(10)
39+
int(20)
40+
int(13)
41+
string(10) " pains of "
42+
int(3)
43+
int(10)
44+
int(40)
45+
int(26)
46+
string(26) "fooy
47+
When thebarlife won't"
48+
Done

0 commit comments

Comments
 (0)