Skip to content

Commit c18ea45

Browse files
committed
add a convoluted test
1 parent 23e0ec9 commit c18ea45

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Zend/tests/data_class_006.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
A convoluted path
3+
--FILE--
4+
<?php
5+
6+
data class Length {
7+
public function __construct(public float $length) {}
8+
}
9+
10+
data class Point {
11+
public int $x;
12+
private Length $l;
13+
public function __construct(int $x, public int $y) {
14+
$previous = $this;
15+
$this->x = $x;
16+
$this->l = new Length($x + $y);
17+
echo "$previous === $this\n";
18+
}
19+
20+
public function addNoisily(Point $other): Point {
21+
echo "Adding $this and $other\n";
22+
$previous = $this;
23+
$this->x += $other->x;
24+
$this->y += $other->y;
25+
$this->l = new Length($this->x + $this->y);
26+
echo "$previous !== $this\n";
27+
return $this;
28+
}
29+
30+
public function __toString(): string {
31+
return "({$this->x},{$this->y}|{$this->l->length})";
32+
}
33+
}
34+
35+
$p1 = new Point(1, 2);
36+
$p2 = $p1->addNoisily($p1);
37+
38+
?>
39+
--EXPECT--
40+
(1,2|3) === (1,2|3)
41+
Adding (1,2|3) and (1,2|3)
42+
(1,2|3) !== (2,4|6)

0 commit comments

Comments
 (0)