11<?php namespace lang \reflection \unittest ;
22
33use lang \reflection \{AccessingFailed , CannotAccess , Constraint , Modifiers };
4- use lang \{Primitive , Type , TypeIntersection , TypeUnion , XPClass };
4+ use lang \{Primitive , Type , TypeIntersection , TypeUnion , XPClass , IllegalStateException };
55use test \verify \Runtime ;
6- use test \{Action , Assert , AssertionFailedError , Expect , Test , Values };
6+ use test \{Action , Assert , Expect , Test , Values };
77
88class PropertiesTest {
99 use TypeDefinition;
@@ -79,44 +79,20 @@ public function set_static() {
7979 Assert::equals ('Modified ' , $ class ::$ fixture );
8080 }
8181
82- #[Test, Expect(CannotAccess::class)]
83- public function cannot_read_private_by_default () {
84- $ type = $ this ->declare ('{ private static $fixture = "Test"; } ' );
85- $ type ->property ('fixture ' )->get (null );
86- }
87-
88- #[Test, Expect(CannotAccess::class)]
89- public function cannot_write_private_by_default () {
90- $ type = $ this ->declare ('{ private static $fixture = "Test"; } ' );
91- $ type ->property ('fixture ' )->set (null , 'Modified ' );
92- }
93-
94- #[Test, Expect(CannotAccess::class)]
95- public function cannot_read_private_with_incorrect_context () {
96- $ type = $ this ->declare ('{ private static $fixture = "Test"; } ' );
97- $ type ->property ('fixture ' )->get (null , typeof ($ this ));
98- }
99-
100- #[Test, Expect(CannotAccess::class)]
101- public function cannot_write_private_with_incorrect_context () {
102- $ type = $ this ->declare ('{ private static $fixture = "Test"; } ' );
103- $ type ->property ('fixture ' )->set (null , 'Modified ' , typeof ($ this ));
104- }
105-
10682 #[Test, Expect(AccessingFailed::class)]
10783 public function type_mismatch () {
10884 $ type = $ this ->declare ('{ private static array $fixture; } ' );
109- $ type ->property ('fixture ' )->set (null , 1 , $ type );
85+ $ type ->property ('fixture ' )->set (null , 1 );
11086 }
11187
11288 #[Test]
11389 public function private_instance_roundtrip () {
11490 $ type = $ this ->declare ('{ private $fixture = "Test"; } ' );
11591 $ instance = $ type ->newInstance ();
11692 $ property = $ type ->properties ()->named ('fixture ' );
117- $ property ->set ($ instance , 'Modified ' , $ type );
93+ $ property ->set ($ instance , 'Modified ' );
11894
119- Assert::equals ('Modified ' , $ property ->get ($ instance, $ type ));
95+ Assert::equals ('Modified ' , $ property ->get ($ instance ));
12096 }
12197
12298 #[Test]
@@ -242,7 +218,7 @@ public function string_representation_with_union_type_declaration() {
242218 }
243219
244220 #[Test]
245- public function accessing_failed_target () {
221+ public function set_accessing_failed_exceptions_target_member () {
246222 $ t = $ this ->declare ('{ public static array $fixture; } ' );
247223 try {
248224 $ t ->property ('fixture ' )->set (null , 1 );
@@ -251,15 +227,4 @@ public function accessing_failed_target() {
251227 Assert::equals ($ t ->property ('fixture ' ), $ expected ->target ());
252228 }
253229 }
254-
255- #[Test]
256- public function cannot_access_target () {
257- $ t = $ this ->declare ('{ private static $fixture; } ' );
258- try {
259- $ t ->property ('fixture ' )->get (null );
260- throw new AssertionFailedError ('No exception was raised ' );
261- } catch (CannotAccess $ expected ) {
262- Assert::equals ($ t ->property ('fixture ' ), $ expected ->target ());
263- }
264- }
265230}
0 commit comments