|
2 | 2 |
|
3 | 3 | use lang\reflection\{Kind, Modifiers, Annotations, Constants, Properties, Methods, Package};
|
4 | 4 | use lang\{ElementNotFoundException, Reflection, Enum, Runnable, XPClass, ClassLoader};
|
5 |
| -use unittest\{Assert, Before, Test}; |
| 5 | +use unittest\actions\VerifyThat; |
| 6 | +use unittest\{Action, Assert, Before, Test}; |
6 | 7 |
|
7 | 8 | class TypeTest {
|
8 | 9 | private $fixture;
|
| 10 | + private static $ENUMS; |
| 11 | + |
| 12 | + static function __static() { |
| 13 | + self::$ENUMS= class_exists(\ReflectionEnum::class, false); |
| 14 | + } |
9 | 15 |
|
10 | 16 | /**
|
11 | 17 | * Declares a type and returns its reflection instance
|
@@ -91,8 +97,20 @@ public function trait_kind() {
|
91 | 97 | }
|
92 | 98 |
|
93 | 99 | #[Test]
|
94 |
| - public function enum_kind() { |
95 |
| - $t= $this->declare('K_E', ['kind' => 'class', 'extends' => [Enum::class]], '{ public static $M; }'); |
| 100 | + public function enum_kind_for_xpenums() { |
| 101 | + $t= $this->declare('K_XE', ['kind' => 'class', 'extends' => [Enum::class]], '{ public static $M; }'); |
| 102 | + Assert::equals(Kind::$ENUM, $t->kind()); |
| 103 | + } |
| 104 | + |
| 105 | + #[Test, Action(eval: 'new VerifyThat(fn() => !self::$ENUMS)')] |
| 106 | + public function enum_kind_for_enum_lookalikes() { |
| 107 | + $t= $this->declare('K_LE', ['kind' => 'class', 'implements' => [\UnitEnum::class]], '{ public static $M; }'); |
| 108 | + Assert::equals(Kind::$ENUM, $t->kind()); |
| 109 | + } |
| 110 | + |
| 111 | + #[Test, Action(eval: 'new VerifyThat(fn() => self::$ENUMS)')] |
| 112 | + public function enum_kind_for_native_enums() { |
| 113 | + $t= $this->declare('K_NE', ['kind' => 'enum'], '{ case M; }'); |
96 | 114 | Assert::equals(Kind::$ENUM, $t->kind());
|
97 | 115 | }
|
98 | 116 |
|
@@ -177,6 +195,18 @@ public function annotation() {
|
177 | 195 | Assert::equals('annotated', $this->fixture->annotation(Annotated::class)->name());
|
178 | 196 | }
|
179 | 197 |
|
| 198 | + #[Test, Action(eval: 'new VerifyThat(fn() => self::$ENUMS)')] |
| 199 | + public function enum_annotation() { |
| 200 | + $t= $this->declare('A_E', ['kind' => 'enum'], '{ case M; }'); |
| 201 | + Assert::equals('annotated', $t->annotation(Annotated::class)->name()); |
| 202 | + } |
| 203 | + |
| 204 | + #[Test, Action(eval: 'new VerifyThat(fn() => self::$ENUMS)')] |
| 205 | + public function enum_case_annotation() { |
| 206 | + $t= $this->declare('A_C', ['kind' => 'enum'], '{ #[Annotated] case M; }'); |
| 207 | + Assert::equals('annotated', $t->constant('M')->annotation(Annotated::class)->name()); |
| 208 | + } |
| 209 | + |
180 | 210 | #[Test]
|
181 | 211 | public function non_existant_annotation() {
|
182 | 212 | Assert::null($this->fixture->annotation('does-not-exist'));
|
|
0 commit comments