Skip to content

Commit ce24ceb

Browse files
committed
Verify int-backed enums
1 parent 71379f9 commit ce24ceb

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/test/php/lang/ast/unittest/emit/EnumTest.class.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,22 @@ public static function run() {
6565
Assert::equals('desc', $t->getMethod('run')->invoke(null));
6666
}
6767

68+
#[Test, Values([[0, 'NO'], [1, 'YES']])]
69+
public function backed_enum_from_int($arg, $expected) {
70+
$t= $this->type('enum <T>: int {
71+
case NO = 0;
72+
case YES = 1;
73+
74+
public static function run($arg) {
75+
return self::from($arg)->name;
76+
}
77+
}');
78+
79+
Assert::equals($expected, $t->getMethod('run')->invoke(null, [$arg]));
80+
}
81+
6882
#[Test, Values([['asc', 'ASC'], ['desc', 'DESC']])]
69-
public function backed_enum_from($arg, $expected) {
83+
public function backed_enum_from_string($arg, $expected) {
7084
$t= $this->type('enum <T>: string {
7185
case ASC = "asc";
7286
case DESC = "desc";
@@ -89,7 +103,7 @@ public static function run() {
89103
try {
90104
self::from("illegal");
91105
throw new IllegalStateException("No exception raised");
92-
} catch (\Exception $expected) {
106+
} catch (\Throwable $expected) {
93107
return $expected->getMessage();
94108
}
95109
}

0 commit comments

Comments
 (0)