Skip to content

Commit 31a2cca

Browse files
committed
Add Enum with multiple interfaces test case
Signed-off-by: Agustin Gomes <[email protected]>
1 parent 8d57953 commit 31a2cca

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--TEST--
2+
Backed Enum with multiple implementing interfaces
3+
--FILE--
4+
<?php
5+
6+
interface Colorful {
7+
public function color(): string;
8+
}
9+
10+
interface Shaped {
11+
public function shape(): string;
12+
}
13+
14+
interface ExtendedShaped {
15+
}
16+
17+
enum Suit: string implements Colorful, ExtendedShaped {
18+
case Hearts = 'H';
19+
case Diamonds = 'D';
20+
case Clubs = 'C';
21+
case Spades = 'S';
22+
23+
public function color(): string {
24+
return match ($this) {
25+
self::Hearts, self::Diamonds => 'Red',
26+
self::Clubs, self::Spades => 'Black',
27+
};
28+
}
29+
30+
public function shape(): string {
31+
return match ($this) {
32+
self::Hearts => 'heart',
33+
self::Diamonds => 'diamond',
34+
self::Clubs => 'club',
35+
self::Spades => 'spade',
36+
};
37+
}
38+
}
39+
40+
echo Suit::Hearts->color() . "\n";
41+
echo Suit::Hearts->shape() . "\n";
42+
echo Suit::Diamonds->color() . "\n";
43+
echo Suit::Diamonds->shape() . "\n";
44+
echo Suit::Clubs->color() . "\n";
45+
echo Suit::Clubs->shape() . "\n";
46+
echo Suit::Spades->color() . "\n";
47+
echo Suit::Spades->shape() . "\n";
48+
49+
?>
50+
--EXPECT--
51+
Red
52+
heart
53+
Red
54+
diamond
55+
Black
56+
club
57+
Black
58+
spade

0 commit comments

Comments
 (0)