File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
src/test/php/lang/ast/syntax/php/unittest Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,10 @@ XP records for PHP - ChangeLog
33
44## ?.?.? / ????-??-??
55
6+ ## 2.3.0 / 2022-02-05
7+
8+ * Add support for ` readonly ` record parameters. See issue #7 - @thekid
9+
610## 2.2.0 / 2022-02-03
711
812* Merged PR #8 : Replace ` __init() ` function with ` init { } ` blocks
Original file line number Diff line number Diff line change @@ -34,6 +34,30 @@ public function __construct() { }
3434 } ' );
3535 }
3636
37+ #[Test]
38+ public function fields_are_private_by_default () {
39+ $ t = $ this ->type ('record <T>(string $name) { } ' );
40+ Assert::equals (MODIFIER_PRIVATE , $ t ->getField ('name ' )->getModifiers ());
41+ }
42+
43+ #[Test]
44+ public function can_declare_field_modifiers () {
45+ $ t = $ this ->type ('record <T>(public string $name) { } ' );
46+ Assert::equals (MODIFIER_PUBLIC , $ t ->getField ('name ' )->getModifiers ());
47+ }
48+
49+ #[Test]
50+ public function can_have_readonly_fields () {
51+ $ t = $ this ->type ('record <T>(public readonly string $name) { } ' );
52+ Assert::equals (MODIFIER_PUBLIC | MODIFIER_READONLY , $ t ->getField ('name ' )->getModifiers ());
53+ }
54+
55+ #[Test, Expect(class: Error::class, withMessage: '/Cannot modify readonly property .+name/ ' )]
56+ public function writing_to_readonly_field () {
57+ $ t = $ this ->type ('record <T>(public readonly string $name) { } ' );
58+ $ t ->newInstance ('Test ' )->name = 'Modified ' ;
59+ }
60+
3761 #[Test]
3862 public function point_record () {
3963 $ p = $ this ->type ('record <T>(int $x, int $y) { } ' )->newInstance (1 , 10 );
You can’t perform that action at this time.
0 commit comments