11<?php namespace lang \reflection \unittest ;
22
33use lang \reflection \{AccessingFailed , CannotAccess , Constraint , Modifiers };
4- use lang \{Primitive , Type , TypeIntersection , TypeUnion , XPClass , IllegalStateException };
5- use test \verify \Runtime ;
4+ use lang \{Primitive , Type , TypeIntersection , TypeUnion , XPClass , IllegalArgumentException };
5+ use test \verify \{ Condition , Runtime } ;
66use test \{Action , Assert , Expect , Test , Values };
77
88class PropertiesTest {
99 use TypeDefinition;
1010
11+ private static $ ASYMMETRIC ;
12+
13+ static function __static () {
14+ self ::$ ASYMMETRIC = method_exists (\ReflectionProperty::class, 'isPrivateSet ' );
15+ }
16+
1117 #[Test]
1218 public function name () {
1319 Assert::equals ('fixture ' , $ this ->declare ('{ public $fixture; } ' )->property ('fixture ' )->name ());
@@ -27,6 +33,27 @@ public function modifiers() {
2733 );
2834 }
2935
36+ #[Test, Values(['public ' , 'protected ' , 'private ' ])]
37+ public function get_modifiers ($ modifier ) {
38+ Assert::equals (
39+ new Modifiers ($ modifier ),
40+ $ this ->declare ('{ ' .$ modifier .' $fixture; } ' )->property ('fixture ' )->modifiers ('get ' )
41+ );
42+ }
43+
44+ #[Test, Values(['public ' , 'protected ' , 'private ' ])]
45+ public function set_modifiers ($ modifier ) {
46+ Assert::equals (
47+ new Modifiers ($ modifier ),
48+ $ this ->declare ('{ ' .$ modifier .' $fixture; } ' )->property ('fixture ' )->modifiers ('set ' )
49+ );
50+ }
51+
52+ #[Test, Expect(IllegalArgumentException::class)]
53+ public function modifiers_unknown_hook () {
54+ $ this ->declare ('{ private $fixture; } ' )->property ('fixture ' )->modifiers ('@unknown ' );
55+ }
56+
3057 #[Test]
3158 public function no_comment () {
3259 Assert::null ($ this ->declare ('{ private $fixture; } ' )->property ('fixture ' )->comment ());
@@ -228,12 +255,37 @@ public function set_accessing_failed_exceptions_target_member() {
228255 }
229256 }
230257
231- #[Test, Runtime(php : '>=8.4 ' )]
232- public function asymmetric_visibility () {
233- $ t = $ this ->declare ('{ public private(set) string $fixture; } ' );
258+ #[Test, Condition(assert : 'self::$ASYMMETRIC ' ), Values([ ' public protected(set) ' , ' public private(set) ' , ' protected private(set) ' ] )]
259+ public function asymmetric_visibility ($ modifiers ) {
260+ $ t = $ this ->declare ('{ ' . $ modifiers . ' int $fixture; } ' );
234261 Assert::equals (
235- ' public private(set) string $name ' ,
262+ $ modifiers . ' int $fixture ' ,
236263 $ t ->property ('fixture ' )->toString ()
237264 );
238265 }
266+
267+ #[Test, Condition(assert: 'self::$ASYMMETRIC ' ), Values(['public ' , 'protected ' , 'private ' ])]
268+ public function set_implicit_when_same_as_get ($ modifier ) {
269+ $ t = $ this ->declare ('{ ' .$ modifier .' ' .$ modifier .'(set) int $fixture; } ' );
270+ Assert::equals (
271+ $ modifier .' int $fixture ' ,
272+ $ t ->property ('fixture ' )->toString ()
273+ );
274+ }
275+
276+ #[Test, Condition(assert: 'self::$ASYMMETRIC ' ), Values(['public ' , 'protected ' , 'private ' ])]
277+ public function asymmetric_get ($ modifier ) {
278+ Assert::equals (
279+ new Modifiers ($ modifier ),
280+ $ this ->declare ('{ ' .$ modifier .' private(set) int $fixture; } ' )->property ('fixture ' )->modifiers ('get ' )
281+ );
282+ }
283+
284+ #[Test, Condition(assert: 'self::$ASYMMETRIC ' ), Values(['public ' , 'protected ' , 'private ' ])]
285+ public function asymmetric_set ($ modifier ) {
286+ Assert::equals (
287+ new Modifiers ($ modifier ),
288+ $ this ->declare ('{ public ' .$ modifier .'(set) int $fixture; } ' )->property ('fixture ' )->modifiers ('set ' )
289+ );
290+ }
239291}
0 commit comments