Skip to content

Comments

feat: support inherited test methods from abstract base classes#352

Merged
recca0120 merged 4 commits intomainfrom
feature/inherited-test-methods
Feb 16, 2026
Merged

feat: support inherited test methods from abstract base classes#352
recca0120 merged 4 commits intomainfrom
feature/inherited-test-methods

Conversation

@recca0120
Copy link
Owner

Summary

  • Adds ClassRegistry to track class inheritance info across files, enabling Test Explorer to discover test methods inherited from abstract parent classes
  • Resolves extends and use statements in PhpAstNodeWrapper to build fully-qualified parent class names
  • PHPUnitParser now registers all classes (including abstract) and merges inherited methods into concrete subclasses
  • TestCollection re-parses child classes when a parent file changes, handling cross-file parse order
  • ClassRegistry is injected via constructor for proper DI

Fixes #277, #164

Test plan

  • ClassRegistry unit tests: register, extendsTestCase, resolveInheritedMethods, circular detection, deleteByUri, getChildClasses
  • PHPUnitParser tests: inherited methods discovered, own+inherited merged, use-statement FQN resolution, fully-qualified extends, child override precedence
  • Integration: ConcreteFromAbstractTest (no own methods) and ConcreteWithOwnTest (own + inherited) discovered in Test Explorer
  • All 629 existing + new tests pass
  • tsc --noEmit zero errors
  • biome check zero errors

@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 92.81768% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.88%. Comparing base (d6328df) to head (cc46805).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/PHPUnit/TestParser/PhpAstNodeWrapper.ts 90.80% 8 Missing ⚠️
src/PHPUnit/TestParser/ClassRegistry.ts 95.32% 5 Missing ⚠️
src/PHPUnit/TestParser/TraitUseParser.ts 91.07% 5 Missing ⚠️
src/PHPUnit/TestParser/PHPUnitParser.ts 90.00% 4 Missing ⚠️
src/PHPUnit/TestParser/TestDefinitionBuilder.ts 60.00% 2 Missing ⚠️
src/PHPUnit/TestCollection/TestCollection.ts 95.83% 1 Missing ⚠️
src/TestCollection/TestDefinitionIndex.ts 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #352      +/-   ##
==========================================
- Coverage   94.04%   93.88%   -0.16%     
==========================================
  Files          78       80       +2     
  Lines        2921     3206     +285     
  Branches      536      620      +84     
==========================================
+ Hits         2747     3010     +263     
- Misses        156      178      +22     
  Partials       18       18              
Flag Coverage Δ
unittests 93.88% <92.81%> (-0.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@recca0120 recca0120 force-pushed the feature/inherited-test-methods branch 2 times, most recently from e39604f to 929f7ca Compare February 16, 2026 17:10
Add ClassRegistry to track class inheritance across files, enabling
Test Explorer to discover test methods inherited from abstract parent
classes (fixes #277, #164).

- Add ClassRegistry with extendsTestCase/resolveInheritedMethods
- Extract extends/use-statement resolution in PhpAstNodeWrapper
- PHPUnitParser registers all classes and merges inherited methods
- TestCollection re-parses child classes when parent file changes
- ClassRegistry injected via constructor for proper DI
@recca0120 recca0120 force-pushed the feature/inherited-test-methods branch from 929f7ca to a28bc6c Compare February 16, 2026 17:21
…olution

Add TraitUseParser to parse PHP trait use statements including
insteadof and as adaptations. ClassRegistry now resolves trait methods
with correct PHP precedence (own > trait > parent) and supports
nested trait-uses with cycle detection.
- Merge filterChildrenByKind/filterChildrenByKinds into single method accepting string | string[]
- Add trait support to children getter for consistency
- Remove unused variable assignment in TestCollection.change()
- Extract resolveTraitMethods into collectTraitMethods, applyInsteadofAdaptations, applyAliasAdaptations
- Convert PHPUnitParser.classRegistry to constructor injection, remove setClassRegistry
- Simplify ProblemMatcher: remove redundant cache.get after set, merge has+get in handleFinished, use direct comparison in isFault
- Extract extractTraitAndMethod in TraitUseParser to eliminate duplication
- Unify classFQN split logic in NamespaceDefinitionBuilder
- Extract deleteById() in TestDefinitionIndex to share deletion logic
- Extract getMessage()/formatTestName() in OutputFormatter base class
- PrettyPrinter/CollisionPrinter use shared base class methods
- Replace array allocation with direct === comparison in utils.ts and PestV1Fixer
- Update extension.test.ts expected counts for inherited test methods (+4)
@recca0120 recca0120 merged commit 2f43bf4 into main Feb 16, 2026
11 of 14 checks passed
@recca0120 recca0120 deleted the feature/inherited-test-methods branch February 16, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Class that extends abstract Test class with methods implemented isn't running any test method

1 participant