Skip to content

Commit e0693e9

Browse files
Reflection: add regression tests for lazy initialization errors
Add tests for the four error cases in `reflection_property_check_lazy_compatible()`, as triggered by both `ReflectionProperty::setRawValueWithoutLazyInitialization()` and `ReflectionProperty::skipLazyInitialization()`. While some of these errors are covered by existing tests, having all of the errors in one place will make it easier to see the changes when the error messages are improved.
1 parent a1cd11a commit e0693e9

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
Test ReflectionProperty::setRawValueWithoutLazyInitialization() and skipLazyInitialization() errors
3+
--FILE--
4+
<?php
5+
6+
#[AllowDynamicProperties]
7+
class Demo {
8+
public static $myStatic;
9+
10+
public bool $myVirtual {
11+
get => true;
12+
}
13+
}
14+
15+
function test(object $obj, string $propertyName) {
16+
$r = new ReflectionProperty($obj, $propertyName);
17+
try {
18+
$r->setRawValueWithoutLazyInitialization($obj, true);
19+
} catch (ReflectionException $e) {
20+
echo $e->getMessage() . "\n";
21+
}
22+
try {
23+
$r->skipLazyInitialization($obj);
24+
} catch (ReflectionException $e) {
25+
echo $e->getMessage() . "\n\n";
26+
}
27+
}
28+
29+
$obj = new Demo();
30+
test($obj, 'myStatic');
31+
test($obj, 'myVirtual');
32+
33+
$obj->myDynamic = true;
34+
test($obj, 'myDynamic');
35+
36+
$obj = new ReflectionClass(Demo::class);
37+
test($obj, 'name');
38+
39+
?>
40+
--EXPECT--
41+
Can not use setRawValueWithoutLazyInitialization on static property Demo::$myStatic
42+
Can not use skipLazyInitialization on static property Demo::$myStatic
43+
44+
Can not use setRawValueWithoutLazyInitialization on virtual property Demo::$myVirtual
45+
Can not use skipLazyInitialization on virtual property Demo::$myVirtual
46+
47+
Can not use setRawValueWithoutLazyInitialization on dynamic property Demo::$myDynamic
48+
Can not use skipLazyInitialization on dynamic property Demo::$myDynamic
49+
50+
Can not use setRawValueWithoutLazyInitialization on internal class ReflectionClass
51+
Can not use skipLazyInitialization on internal class ReflectionClass

0 commit comments

Comments
 (0)