Skip to content

Commit b7c4342

Browse files
committed
Add test for directories
1 parent 11078e3 commit b7c4342

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

Zend/tests/gh8548_2.phpt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
GH-8548: Test stream_wrapper_unregister() for directories
3+
--FILE--
4+
<?php
5+
6+
class Wrapper
7+
{
8+
public $context;
9+
10+
public function dir_opendir(string $path, int $options): bool
11+
{
12+
return true;
13+
}
14+
15+
public function stream_eof(): bool
16+
{
17+
return true;
18+
}
19+
}
20+
21+
function test() {
22+
if (!stream_wrapper_register('foo', \Wrapper::class)) {
23+
throw new \Exception('Could not register stream wrapper');
24+
}
25+
26+
$dir = opendir('foo://bar');
27+
28+
if (!stream_wrapper_unregister('foo')) {
29+
throw new \Exception('Could not unregister stream wrapper');
30+
}
31+
32+
$wrapper = stream_get_meta_data($dir)['wrapper_data'];
33+
if (!$wrapper instanceof Wrapper) {
34+
throw new \Exception('Wrapper is not of expected type');
35+
}
36+
37+
closedir($dir);
38+
unset($dir);
39+
}
40+
41+
// The first iterations will allocate space for things like the resource list
42+
for ($i = 0; $i < 10; $i++) {
43+
test();
44+
}
45+
46+
$before = memory_get_usage();
47+
for ($i = 0; $i < 1000; $i++) {
48+
test();
49+
}
50+
$after = memory_get_usage();
51+
52+
var_dump($before === $after);
53+
54+
?>
55+
--EXPECT--
56+
bool(true)

0 commit comments

Comments
 (0)