Skip to content

Commit fa33a58

Browse files
fain182claude
andcommitted
Add integration tests for @throws docblock dependency collection
Add two integration tests to verify that dependencies defined in @throws docblock tags are properly collected: - test_it_collects_throws_tag_as_dependencies: Tests collection of relative and fully qualified exception names in @throws tags - test_it_collects_throws_tag_with_fully_qualified_names: Tests handling of different naming conventions (backslash-prefixed, relative to namespace) These tests validate that the @throws tag parsing feature works end-to-end and that exceptions are properly resolved to their fully qualified names. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <[email protected]>
1 parent 01c1d11 commit fa33a58

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tests/Unit/Analyzer/FileParser/CanParseDocblocksTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,4 +495,87 @@ class ApplicationLevelDto
495495

496496
self::assertCount(1, $violations);
497497
}
498+
499+
public function test_it_collects_throws_tag_as_dependencies(): void
500+
{
501+
$code = <<< 'EOF'
502+
<?php
503+
504+
namespace Domain\Foo;
505+
506+
use Domain\FooException;
507+
use Domain\BarException;
508+
509+
class MyClass
510+
{
511+
/**
512+
* @throws FooException
513+
* @throws BarException
514+
*/
515+
public function method1()
516+
{
517+
}
518+
519+
/**
520+
* @throws \Exception
521+
*/
522+
public function method2()
523+
{
524+
}
525+
}
526+
EOF;
527+
528+
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
529+
$fp->parse($code, 'relativePathName');
530+
531+
$cd = $fp->getClassDescriptions();
532+
533+
self::assertCount(1, $cd);
534+
$dependencies = $cd[0]->getDependencies();
535+
536+
// Should have 3 dependencies from @throws: FooException, BarException, Exception
537+
self::assertCount(3, $dependencies);
538+
539+
$fqcns = array_map(static fn ($dep) => $dep->getFQCN()->toString(), $dependencies);
540+
self::assertContains('Domain\FooException', $fqcns);
541+
self::assertContains('Domain\BarException', $fqcns);
542+
self::assertContains('Exception', $fqcns);
543+
}
544+
545+
public function test_it_collects_throws_tag_with_fully_qualified_names(): void
546+
{
547+
$code = <<< 'EOF'
548+
<?php
549+
550+
namespace App\Services;
551+
552+
class MyService
553+
{
554+
/**
555+
* @throws \Exception
556+
* @throws \Domain\FooException
557+
* @throws BarException
558+
*/
559+
public function doSomething()
560+
{
561+
}
562+
}
563+
EOF;
564+
565+
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_1);
566+
$fp->parse($code, 'relativePathName');
567+
568+
$cd = $fp->getClassDescriptions();
569+
570+
self::assertCount(1, $cd);
571+
$dependencies = $cd[0]->getDependencies();
572+
573+
// Should have 3 dependencies from @throws
574+
self::assertCount(3, $dependencies);
575+
576+
$fqcns = array_map(static fn ($dep) => $dep->getFQCN()->toString(), $dependencies);
577+
self::assertContains('Exception', $fqcns);
578+
self::assertContains('Domain\FooException', $fqcns);
579+
self::assertContains('App\Services\BarException', $fqcns);
580+
}
498581
}

0 commit comments

Comments
 (0)