Skip to content

Commit 8c177da

Browse files
committed
refactor: added tests for rfc examples
1 parent 12b986a commit 8c177da

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Zend/tests/property_hooks/readonly_lazy.phpt renamed to Zend/tests/property_hooks/readonly_rfc_example_lazy_product.phpt

File renamed without changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Readonly property hook validation
3+
--FILE--
4+
<?php
5+
6+
readonly class PositivePoint
7+
{
8+
public function __construct(
9+
public int $x { set => $value > 0 ? $value : throw new \Error('Value must be greater 0'); },
10+
public int $y { set => $value > 0 ? $value : throw new \Error('Value must be greater 0'); },
11+
) {}
12+
}
13+
14+
$one = new PositivePoint(1,1);
15+
var_dump($one);
16+
17+
try {
18+
$two = new PositivePoint(0,1);
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
23+
24+
?>
25+
--EXPECTF--
26+
object(PositivePoint)#1 (2) {
27+
["x"]=>
28+
int(1)
29+
["y"]=>
30+
int(1)
31+
}
32+
Value must be greater 0

0 commit comments

Comments
 (0)