Skip to content

Commit a690efc

Browse files
committed
Test that objects free handler call zend_weakrefs_notify
1 parent d30c78d commit a690efc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Zend/tests/weakrefs/notify.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Object free handler must call zend_weakrefs_notify
3+
--FILE--
4+
<?php
5+
6+
$classes = get_declared_classes();
7+
$testedClasses = 0;
8+
9+
foreach ($classes as $class) {
10+
$reflector = new \ReflectionClass($class);
11+
try {
12+
$instance = $reflector->newInstanceWithoutConstructor();
13+
} catch (\Throwable $e) {
14+
continue;
15+
}
16+
$testedClasses++;
17+
$ref = WeakReference::create($instance);
18+
$instance = null;
19+
gc_collect_cycles();
20+
if ($ref->get() !== null) {
21+
printf("free handler of %s did not call zend_weakrefs_notify?\n", $class);
22+
}
23+
}
24+
25+
if ($testedClasses === 0) {
26+
print "Did not test any class\n";
27+
}
28+
?>
29+
==DONE==
30+
--EXPECT--
31+
==DONE==

0 commit comments

Comments
 (0)