Skip to content

Commit 6173977

Browse files
fain182claude
andcommitted
Test enum implementing interface records the dependency
Add a test covering the foreach in handleEnumNode that records interface dependencies for enums that implement interfaces (e.g. enum Suit implements Colorful). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent a3fc86b commit 6173977

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/Unit/Analyzer/FileParser/CanParseEnumsTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,33 @@ public function test_it_can_parse_enum(): void
3131
self::assertCount(1, $violations);
3232
}
3333

34+
/**
35+
* @requires PHP 8.1
36+
*/
37+
public function test_it_records_interface_dependency_for_enum_implementing_interface(): void
38+
{
39+
$code = <<< 'EOF'
40+
<?php
41+
namespace App\Foo;
42+
43+
interface Colorful {}
44+
45+
enum Suit: string implements Colorful
46+
{
47+
case Hearts = 'H';
48+
}
49+
EOF;
50+
51+
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_1);
52+
$fp->parse($code, 'relativePathName');
53+
$cd = $fp->getClassDescriptions();
54+
55+
$enum = $cd[1]; // cd[0] = Colorful interface, cd[1] = Suit enum
56+
self::assertTrue($enum->isEnum());
57+
self::assertCount(1, $enum->getDependencies());
58+
self::assertEquals('App\Foo\Colorful', $enum->getDependencies()[0]->getFQCN()->toString());
59+
}
60+
3461
/**
3562
* @dataProvider provide_enums
3663
*/

0 commit comments

Comments
 (0)