summaryrefslogtreecommitdiff
path: root/ext/reflection/tests/ReflectionEnumBackedCase_getBackingValue.phpt
blob: f81241d73a9e3434a49bdf4f11b21580ac8255f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
--TEST--
ReflectionEnumBackedCase::getBackingValue()
--FILE--
<?php

enum Enum_ {
    case Foo;
}

enum IntEnum: int {
    case Foo = 0;
}

enum StringEnum: string {
    case Foo = 'Foo';
}

try {
    var_dump(new ReflectionEnumBackedCase(Enum_::class, 'Foo'));
} catch (ReflectionException $e) {
    echo $e->getMessage() . "\n";
}

try {
    var_dump(new ReflectionEnumBackedCase([], 'Foo'));
} catch (Error $e) {
    echo $e->getMessage() . "\n";
}

var_dump((new ReflectionEnumBackedCase(IntEnum::class, 'Foo'))->getBackingValue());
var_dump((new ReflectionEnumBackedCase(StringEnum::class, 'Foo'))->getBackingValue());

?>
--EXPECT--
Enum case Enum_::Foo is not a backed case
ReflectionEnumBackedCase::__construct(): Argument #1 ($class) must be of type object|string, array given
int(0)
string(3) "Foo"