diff --git a/src/TokenParsers/StructureHeadTokenParser.php b/src/TokenParsers/StructureHeadTokenParser.php index 64f2a56..aaf4236 100644 --- a/src/TokenParsers/StructureHeadTokenParser.php +++ b/src/TokenParsers/StructureHeadTokenParser.php @@ -46,14 +46,14 @@ public function execute( } if (! $tokens->get($index)->is([ - T_EXTENDS, - T_IMPLEMENTS, - T_STRING, - T_NAME_FULLY_QUALIFIED, - T_NAME_FULLY_QUALIFIED, - T_NAME_RELATIVE, - T_NAME_QUALIFIED, - ])) { + T_EXTENDS, + T_IMPLEMENTS, + T_STRING, + T_NAME_FULLY_QUALIFIED, + T_NAME_FULLY_QUALIFIED, + T_NAME_RELATIVE, + T_NAME_QUALIFIED, + ]) && $tokens->get($index)->text !== ':') { break; } diff --git a/tests/Fakes/FakeIntEnum.php b/tests/Fakes/FakeIntEnum.php new file mode 100644 index 0000000..c7b5a10 --- /dev/null +++ b/tests/Fakes/FakeIntEnum.php @@ -0,0 +1,10 @@ +enums(), [ FakeEnum::class, + FakeIntEnum::class, + FakeStringEnum::class, ], ], 'traits' => [ @@ -104,6 +110,8 @@ ), [ FakeEnum::class, + FakeIntEnum::class, + FakeStringEnum::class, FakeTrait::class, ], ], @@ -126,6 +134,8 @@ FakeSubChildClass::class, FakeChildClass::class, FakeEnum::class, + FakeIntEnum::class, + FakeStringEnum::class, FakeSubChildInterface::class, ]); }); @@ -136,6 +146,8 @@ expect($found)->toEqualCanonicalizing([ FakeChildClass::class, FakeEnum::class, + FakeIntEnum::class, + FakeStringEnum::class, FakeSubChildInterface::class, ]); }); @@ -211,6 +223,8 @@ expect($found)->toEqualCanonicalizing([ FakeChildClass::class, FakeEnum::class, + FakeIntEnum::class, + FakeStringEnum::class, FakeSubChildClass::class, ]); }); @@ -407,6 +421,8 @@ public function satisfies(DiscoveredStructure $discoveredData): bool ->toEqualCanonicalizing([ FakeChildClass::class, FakeEnum::class, + FakeIntEnum::class, + FakeStringEnum::class, FakeSubChildInterface::class, ]) ->toEqualCanonicalizing($foundInterfacesB); @@ -415,7 +431,7 @@ public function satisfies(DiscoveredStructure $discoveredData): bool it('can use a discoverer with cache', function () { $found = StubStructureScout::create()->get(); - expect($found)->toBe([FakeEnum::class]); + expect($found)->toBe([FakeEnum::class,FakeIntEnum::class, FakeStringEnum::class, ]); // Replace cache StaticDiscoverCacheDriver::$entries['stub'] = [FakeRootClass::class]; @@ -429,7 +445,7 @@ public function satisfies(DiscoveredStructure $discoveredData): bool StructureScoutManager::cache([__DIR__.'/Stubs']); expect(StaticDiscoverCacheDriver::$entries)->toHaveKey('stub'); - expect(StaticDiscoverCacheDriver::$entries['stub'])->toBe([FakeEnum::class]); + expect(StaticDiscoverCacheDriver::$entries['stub'])->toBe([FakeEnum::class, FakeIntEnum::class, FakeStringEnum::class, ]); StructureScoutManager::clear([__DIR__.'/Stubs']); @@ -445,7 +461,7 @@ public function satisfies(DiscoveredStructure $discoveredData): bool StructureScoutManager::cache([]); expect(StaticDiscoverCacheDriver::$entries)->toHaveKey('stub'); - expect(StaticDiscoverCacheDriver::$entries['stub'])->toBe([FakeEnum::class]); + expect(StaticDiscoverCacheDriver::$entries['stub'])->toBe([FakeEnum::class, FakeIntEnum::class, FakeStringEnum::class, ]); StructureScoutManager::clear([__DIR__.'/Stubs']); @@ -458,7 +474,7 @@ public function satisfies(DiscoveredStructure $discoveredData): bool artisan('structure-scouts:cache'); expect(StaticDiscoverCacheDriver::$entries)->toHaveKey('stub'); - expect(StaticDiscoverCacheDriver::$entries['stub'])->toBe([FakeEnum::class]); + expect(StaticDiscoverCacheDriver::$entries['stub'])->toBe([FakeEnum::class, FakeIntEnum::class, FakeStringEnum::class, ]); artisan('structure-scouts:clear'); @@ -478,3 +494,16 @@ public function satisfies(DiscoveredStructure $discoveredData): bool FakeChildInterface::class, ]); }); + +it('can discover enums with interfaces', function () { + $found = Discover::in(__DIR__.'/Fakes') + ->implementing(FakeChildInterface::class) + ->enums() + ->get(); + + expect($found)->toEqualCanonicalizing([ + FakeEnum::class, + FakeStringEnum::class, + FakeIntEnum::class, + ]); +}); diff --git a/tests/TokenParsersTest.php b/tests/TokenParsersTest.php index d163546..4a737ac 100644 --- a/tests/TokenParsersTest.php +++ b/tests/TokenParsersTest.php @@ -235,7 +235,7 @@ enum IntEnum: int{} ->name->toEqual('IntEnum'); }); -it('can resolve implemented interfaces for an enum', function () { +it('can resolve implemented interfaces for a unit enum', function () { $definition = <<<'PHP' use Illuminate\Contracts\Support\Arrayable; @@ -249,6 +249,20 @@ enum UnitEnum implements EnumInterface, Arrayable {} ->implements->toContain('EnumInterface', Arrayable::class); }); +it('can resolve implemented interfaces for a string enum', function () { + $definition = <<<'PHP' + use Illuminate\Contracts\Support\Arrayable; + + enum UnitEnum: string implements EnumInterface, Arrayable {} +PHP; + + $discovered = getDiscoveredStructure($definition, structure: 'UnitEnum'); + + expect($discovered) + ->toBeInstanceOf(DiscoveredEnum::class) + ->implements->toContain('EnumInterface', Arrayable::class); +}); + /** * Traits */