Skip to content

[AnnotationsToAttributes] Convert external @depends ClassName::method to #[DependsExternal]#679

Merged
TomasVotruba merged 1 commit into
mainfrom
fix/depends-external-attribute
May 30, 2026
Merged

[AnnotationsToAttributes] Convert external @depends ClassName::method to #[DependsExternal]#679
TomasVotruba merged 1 commit into
mainfrom
fix/depends-external-attribute

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9539

When a @depends annotation references a method on another test class (@depends OtherTest::testMethod), DependsAnnotationWithValueToAttributeRector left it untouched. PHPUnit expresses a cross-class dependency with a dedicated attribute that takes the class and method as two arguments:

-    /**
-     * @depends \Some\OtherTest::testIsImmutable
-     */
+    #[\PHPUnit\Framework\Attributes\DependsExternal(\Some\OtherTest::class, 'testIsImmutable')]
     public function testIsImmutable(): void

Previously this case fell through all resolvers and produced no change (or, as reported, a malformed single-argument #[Depends(Other::testIsImmutable)]).

What changed

  • Added a resolveDependsExternalClassMethod() branch that recognises ClassName::method (skipping ::class, already handled by DependsOnClass, and clone …, handled by DependsUsingDeepClone) and emits #[DependsExternal(ClassName::class, 'method')].
  • Refactored the resolver to return [attributeClass, items[]] so attributes can carry more than one argument (the existing single-argument cases keep their behaviour).

Tests

  • New fixture Fixture/depends_external.php.inc.
  • Full rules-tests/AnnotationsToAttributes suite is green; ECS, PHPStan and Rector pass on the changed rule.

Scope note: the deep-clone external variant (@depends clone OtherTest::methodDependsExternalUsingDeepClone) is intentionally left out of scope and explicitly skipped, so its current behaviour is unchanged.

@TomasVotruba TomasVotruba merged commit 5018a0a into main May 30, 2026
8 checks passed
@TomasVotruba
Copy link
Copy Markdown
Member Author

LGTM 👍

@TomasVotruba TomasVotruba deleted the fix/depends-external-attribute branch May 30, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect behavior of AnnotationWithValueToAttributeRector, CoversAnnotationWithValueToAttributeRector

1 participant