Skip to content

Commit 8d57953

Browse files
committed
Add Backed Enum test case
In the Enumeration RFC, it states Backed Enums can implement interfaces, but it was not clear where the backed Enum type would need to be placed in such situation. This commit adds a test case for this scenario. Signed-off-by: Agustin Gomes <[email protected]>
1 parent a2bc57e commit 8d57953

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Backed Enum implements
3+
--FILE--
4+
<?php
5+
6+
interface Colorful {
7+
public function color(): string;
8+
}
9+
10+
enum Suit: string implements Colorful {
11+
case Hearts = 'H';
12+
case Diamonds = 'D';
13+
case Clubs = 'C';
14+
case Spades = 'S';
15+
16+
public function color(): string {
17+
return match ($this) {
18+
self::Hearts, self::Diamonds => 'Red',
19+
self::Clubs, self::Spades => 'Black',
20+
};
21+
}
22+
}
23+
24+
echo Suit::Hearts->color() . "\n";
25+
echo Suit::Diamonds->color() . "\n";
26+
echo Suit::Clubs->color() . "\n";
27+
echo Suit::Spades->color() . "\n";
28+
29+
?>
30+
--EXPECT--
31+
Red
32+
Red
33+
Black
34+
Black

0 commit comments

Comments
 (0)