Skip to content

Conversation

@Jhuntenburg
Copy link

Add PHPUnit Group Filtering & Run Support

Summary

This PR adds support for PHPUnit test groups, enabling users to filter and run tests by group directly from the VS Code Test Explorer.

It supports both traditional @group annotations and PHP 8+ #[Group] attributes, mapping them into Test Explorer tags and providing a new command to execute grouped tests in a single PHPUnit process.

⚠️ Note: TypeScript is not my primary language. While this feature is working in practice (see demo video below), I’d really appreciate a careful review of the TS structure, patterns, and edge cases.


Features

Group Parsing

  • Parses @group annotations and #[Group('name')] attributes
  • Works at both class and method level

Test Explorer Integration

  • Groups appear as filterable tags in the VS Code Test Explorer
  • Filter syntax:
    @phpUnitTestController:group:

Run Tests by Group

  • New command: PHPUnit: Run tests by group
  • Displays a picker UI to select a group and run all matching tests

Tag Inheritance

  • Test methods inherit group tags from their parent class
  • Filtering by a class-level group automatically includes all its test methods

Single Process Execution

  • Uses PHPUnit’s native --group flag
  • Runs all matching tests in a single PHPUnit process
  • Avoids database and container conflicts caused by parallel execution

Demo

📽️ Video walkthrough included, demonstrating:

  • Group tags appearing in the Test Explorer
  • Filtering tests by group
  • Running a group via the command palette

https://youtu.be/WJf1DIRIcNI


Files Changed

  • src/PHPUnit/TestParser/AnnotationParser.ts
    → Added group parsing support

  • src/PHPUnit/types.ts
    → Added group?: string[] to Annotations

  • src/TestCollection/TestHierarchyBuilder.ts
    → Added GroupRegistry singleton
    → Assigned group tags with parent → child inheritance

  • src/CommandHandler.ts
    → New runByGroup() command and picker UI

  • src/Handler.ts
    → New startGroupTestRun() using PHPUnit --group

  • src/extension.ts
    → Command registration

  • package.json
    → Command contribution

  • src/PHPUnit/TestParser/PHPUnitParser.test.ts
    → Unit tests for group parsing

@Jhuntenburg Jhuntenburg marked this pull request as ready for review January 2, 2026 21:10

jest.mock('child_process');
//updated to match spawn for tests
jest.mock('node:child_process');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was because i was getting test failures from run npm jest, this change fixed on local, not sure if you were haveing the same issue.

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.

1 participant