File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77class User
88{
9- /**
10- * Asymmetric visibility property with @var constraint
11- *
12- * @var positive-int
13- */
14- public private(set) int $ id = 10 ;
15-
16- /**
17- * Property hook with asymmetric visibility and @var constraint
18- *
19- * @var non-empty-string
20- */
21- public protected(set) string $ username {
22- get => $ this ->_username ;
23- set => $ this ->_username = trim ($ value );
24- }
25-
26- private string $ _username = 'Alice ' ;
27-
28- public function updateProfile (int $ newId , string $ newUsername ): void
29- {
30- $ this ->id = $ newId ; // Validated against @var positive-int!
31- $ this ->username = $ newUsername ; // Validated in set hook against @var non-empty-string!
9+ public function __construct (
10+ public string $ name = 'Alice ' ,
11+ public int $ id = 1
12+ ) {
3213 }
33- }
14+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace TypePHP \Tests \Fixtures \Types ;
6+
7+ class HookedUser
8+ {
9+ /**
10+ * Asymmetric visibility property with @var constraint
11+ *
12+ * @var positive-int
13+ */
14+ public private(set) int $ id = 10 ;
15+
16+ /**
17+ * Property hook with asymmetric visibility and @var constraint
18+ *
19+ * @var non-empty-string
20+ */
21+ public protected(set) string $ username {
22+ get => $ this ->_username ;
23+ set => $ this ->_username = trim ($ value );
24+ }
25+
26+ private string $ _username = 'Alice ' ;
27+
28+ public function updateProfile (int $ newId , string $ newUsername ): void
29+ {
30+ $ this ->id = $ newId ;
31+ $ this ->username = $ newUsername ;
32+ }
33+ }
Original file line number Diff line number Diff line change 77}
88
99use TypePHP \Internal \Config ;
10- use TypePHP \Tests \Fixtures \Domain \User ;
1110use TypePHP \Tests \Fixtures \Types \HookedInterfaceImplementation ;
11+ use TypePHP \Tests \Fixtures \Types \HookedUser ;
1212use TypePHP \Tests \Fixtures \Types \PropertyHooks ;
1313
1414beforeEach (function () {
7676 expect ($ fixture ->unvalidatedHook )->toBe (-50 );
7777 });
7878
79- test ('validates asymmetric visibility properties combined with property hooks ' , function () {
80- $ profile = new User ();
79+ test ('validates asymmetric visibility properties combined with property hooks ' , function () {
80+ $ profile = new HookedUser ();
8181
8282 $ profile ->updateProfile (100 , 'Bob ' );
8383 expect ($ profile ->id )->toBe (100 );
You can’t perform that action at this time.
0 commit comments