Skip to content

Commit 179b15b

Browse files
committed
Adjust error message to match PHP 8.1 implementation
1 parent a528053 commit 179b15b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/main/php/lang/ast/emit/PHP.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ protected function emitEnum($result, $enum) {
387387
}');
388388
$result->out->write('public static function from($value) {
389389
if ($r= self::$values[$value] ?? null) return $r;
390-
throw new \ValueError("Not an enum value: ".\util\Objects::stringOf($value));
390+
throw new \ValueError(\util\Objects::stringOf($value)." is not a valid backing value for enum \"".self::class."\"");
391391
}');
392392
} else {
393393
$result->out->write('public $name;');

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,24 @@ public static function run($arg) {
8181

8282
#[Test]
8383
public function backed_enum_from_nonexistant() {
84-
$t= $this->type('enum <T>: string {
84+
$t= $this->type('use lang\IllegalStateException; enum <T>: string {
8585
case ASC = "asc";
8686
case DESC = "desc";
8787
8888
public static function run() {
8989
try {
9090
self::from("illegal");
91-
throw new \lang\IllegalStateException("No exception raised");
91+
throw new IllegalStateException("No exception raised");
9292
} catch (\ValueError $expected) {
9393
return $expected->getMessage();
9494
}
9595
}
9696
}');
9797

98-
Assert::equals('Not an enum value: "illegal"', $t->getMethod('run')->invoke(null));
98+
Assert::equals(
99+
'"illegal" is not a valid backing value for enum "'.$t->literal().'"',
100+
$t->getMethod('run')->invoke(null)
101+
);
99102
}
100103

101104
#[Test, Values([['asc', 'ASC'], ['desc', 'DESC'], ['illegal', null]])]

0 commit comments

Comments
 (0)