Skip to content

Commit 6d578be

Browse files
committed
refactor: merged simple test cases
1 parent 41a8aba commit 6d578be

File tree

2 files changed

+68
-74
lines changed

2 files changed

+68
-74
lines changed

Zend/tests/property_hooks/readonly.phpt

Lines changed: 0 additions & 73 deletions
This file was deleted.

Zend/tests/property_hooks/readonly_property_backed.phpt

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,76 @@ try {
3333
echo $e->getMessage(), "\n";
3434
}
3535
var_dump($t->prop);
36+
37+
// class readonly
38+
final readonly class Foo
39+
{
40+
public function __construct(
41+
public array $values {
42+
set(array $value) => array_map(strtoupper(...), $value);
43+
},
44+
) {}
45+
}
46+
47+
// property readonly
48+
final class Foo2
49+
{
50+
public function __construct(
51+
public readonly array $values {
52+
set(array $value) => array_map(strtoupper(...), $value);
53+
},
54+
) {}
55+
}
56+
57+
// redundant readonly
58+
final readonly class Foo3
59+
{
60+
public function __construct(
61+
public readonly array $values {
62+
set(array $value) => array_map(strtoupper(...), $value);
63+
get => $this->makeNicer($this->values);
64+
},
65+
) {}
66+
67+
public function makeNicer(array $entries): array
68+
{
69+
return array_map(
70+
fn($i, $entry) => $entry . strtoupper(['', 'r', 'st'][$i]), array_keys($entries),
71+
$entries
72+
);
73+
}
74+
}
75+
76+
\var_dump(new Foo(['yo,', 'you', 'can'])->values);
77+
\var_dump(new Foo2(['just', 'do', 'things'])->values);
78+
\var_dump(new Foo3(['nice', 'nice', 'nice'])->values);
3679
?>
3780
--EXPECT--
3881
int(42)
3982
Cannot modify readonly property Test::$prop
4083
Cannot modify protected(set) readonly property Test::$prop from global scope
41-
int(42)
84+
int(42)
85+
array(3) {
86+
[0]=>
87+
string(3) "YO,"
88+
[1]=>
89+
string(3) "YOU"
90+
[2]=>
91+
string(3) "CAN"
92+
}
93+
array(3) {
94+
[0]=>
95+
string(4) "JUST"
96+
[1]=>
97+
string(2) "DO"
98+
[2]=>
99+
string(6) "THINGS"
100+
}
101+
array(3) {
102+
[0]=>
103+
string(4) "NICE"
104+
[1]=>
105+
string(5) "NICER"
106+
[2]=>
107+
string(6) "NICEST"
108+
}

0 commit comments

Comments
 (0)