Add Behat context support#267
Merged
janedbal merged 3 commits intoshipmonk-rnd:masterfrom Nov 25, 2025
Merged
Conversation
56d1830 to
0b70997
Compare
janedbal
requested changes
Nov 24, 2025
Member
|
Also please add short readme mention. |
Member
|
It would be also nice if you could confirm it actually work on some real-world project using Behat. Thank you |
0b70997 to
bd85ad5
Compare
Contributor
Author
|
Thanks @janedbal . As requested I added additional dead methods and added the feature to the README. Yes I verified it on a personal project I am using it on along with behat. That's why I wanted to add this feature since I was getting a lot of false positives. If you need me to link to the project, I can. Let me know if I need to make any other changes. |
This commit adds support for detecting Behat context classes and marking their step definitions and hooks as used, preventing them from being incorrectly flagged as dead code. Features: - New BehatUsageProvider that detects classes implementing Behat\Behat\Context\Context - Supports annotation-based step definitions (@given, @when, @then) - Supports PHP 8 attribute-based step definitions (#[Given], #[When], #[Then]) - Supports all Behat hooks (BeforeScenario, AfterScenario, BeforeStep, AfterStep, etc.) - Supports @Transform/#[Transform] for parameter transformations - Auto-enables when behat/behat package is detected via Composer - Configurable via shipmonkDeadCode.usageProviders.behat.enabled parameter Test coverage: - Added comprehensive test data with both annotation and attribute examples - Achieved 100% code coverage (6/6 methods, 49/49 lines) - Added 4 new test cases to the test suite
Behat contexts often have constructors for dependency injection. These constructors are called by the Behat framework when instantiating contexts, so they should not be marked as dead code. Changes: - Updated BehatUsageProvider to detect and mark constructors as used - Added test cases with constructor examples - Maintained 100% code coverage
- Add helper methods without Behat annotations to test files to verify the provider doesn't incorrectly mark all methods as used - Document Behat support in README including constructors, step definitions, hooks, and transformations
bd85ad5 to
0127fe8
Compare
Member
|
Released as 0.14 |
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.
This adds support for detecting Behat context classes and marking their step definitions and hooks as used. It supports both annotation-based and attribute-based methods.