Add Phpat usage provider#381
Draft
janedbal wants to merge 2 commits into
Draft
Conversation
phpat registers architecture tests as services tagged "phpat.test" in the PHPStan DI container, and at runtime invokes their public methods that are either named `test*` or carry the #[TestRule] attribute (see PHPat\Test\TestParser / TestExtractor). These invocations are invisible in source code, so the methods were reported as dead. PhpatUsageProvider resolves the tagged services from the container and marks those test methods as used. Constructors of the test classes are already covered by PhpStanUsageProvider (they are registered DIC services), so this provider only handles the invoked methods. Autoenabled when phpat/phpat is installed. Closes #378 Co-Authored-By: Claude Code Claude-Session: https://claude.ai/code/session_01WqA3SLHn3vQEytN5C1KCJj
Replace the standalone PhpatUsageProviderTest with the conventional integration fixture used by every other provider: a real data/providers/phpat.php with a registered and an unregistered phpat architecture test, driven through DeadCodeRuleTest. The container mock now returns an instance of the registered test for the "phpat.test" tag, mirroring phpat's getServicesByTag() lookup, so detection is exercised end-to-end against the dead-code graph. testNoFatalError uses require_once since the fixture classes are autoloaded during analysis. Co-Authored-By: Claude Code Claude-Session: https://claude.ai/code/session_01WqA3SLHn3vQEytN5C1KCJj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #378.
phpat registers architecture tests as services tagged
phpat.testin the PHPStan DI container. At runtime it iterates those services and invokes their public methods that are either namedtest*or carry the#[TestRule]attribute (seePHPat\Test\TestParserandPHPat\Test\TestExtractorin phpat's source). Because these invocations are invisible in source code, the test methods were reported as dead — e.g. theInfection\Tests\Architecture\PHPat\...case from the issue.What this does
PhpatUsageProviderresolves the services taggedphpat.testfrom the PHPStan container (getServicesByTag) and marks theirtest*/#[TestRule]public methods as used, mirroring phpat's own selection logic exactly.PhpStanUsageProvideralready covers them.phpat/phpatis installed (overridable viashipmonkDeadCode.usageProviders.phpat.enabled).Notes / trade-offs
phpat/phpatis added as a dev dependency for the fixture/test. As with the other library providers, this couples our test matrix to phpat's supported PHPStan range — something to keep in mind for future PHPStan bumps.phpat.testservice tag, which is resolved viagetServicesByTagand therefore instantiates the tagged test services (this is what phpat itself does).findServiceNamesByType(used byPhpStanUsageProvider) is instantiation-free but is a by-type reverse lookup with no by-tag equivalent on theContainerinterface, so it can't be reused here.