Skip to content

Fix PHPUnit configuration discovery for Drupal QA - #80

Merged
lennartvava merged 1 commit into
developfrom
feature/phpunit-configuration-discovery
Sep 24, 2026
Merged

lennartvava merged 1 commit into
developfrom
feature/phpunit-configuration-discovery

Conversation

@lennartvava

Copy link
Copy Markdown
Contributor

Summary

Fix PHPUnit configuration generation and source discovery in QA Drupal for
Drupal 11 and Drupal 12 consumers.

Changes

  • Select PHPUnit 11 or PHPUnit 12 templates from the consumer project's
    installed phpunit/phpunit version rather than the PHPUnit version bundled
    inside the GrumPHP PHAR.
  • Add a dedicated PHPUnit version resolver with focused unit coverage.
  • Require district09/qa-php:^3.1.1 so generated PHPStan configuration can
    resolve the GrumPHP API stubs used by the shared task event listener.
  • Prevent extension bootstrap discovery from following directory symlinks.
  • Limit PHPUnit source exclusions to relevant custom extension paths, avoiding
    recursive traversal of Composer dependencies and linked repositories.
  • Retain the existing PHPUnit configuration precedence and generated filenames.

Verification

  • composer validate --strict
  • vendor/bin/phpunit --configuration=phpunit.xml.dist tests/src/Unit/GrumPHP
    • 8 tests, 18 assertions, passing
  • Verified QA PHP resolves to the released 3.1.1 version.
  • git diff --check

$iterator = new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator(
$scanDirectory,
RecursiveDirectoryIterator::FOLLOW_SYMLINKS | RecursiveDirectoryIterator::SKIP_DOTS

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we remove symlinks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Removing FOLLOW_SYMLINKS avoided a recursive link, but it also removed valid linked-extension support. I changed this to retain symlink traversal while tracking canonical directory paths and skipping only paths already visited, including cycles.

/**
* Tests that extension discovery does not recurse into directory symlinks.
*/
public function testExtensionDiscoveryDoesNotFollowDirectorySymlinks(): void {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we remove symlink support?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. The revised tests now cover both a valid symlinked extension, which is discovered, and a directory-link cycle, which is safely skipped.

Comment thread src/GrumPHP/ConfigFileMerger.php Outdated

// PHPUnit configuration schemas are specific to the runner major.
if ($taskInfo['filename'] === 'phpunit' && Version::majorVersionNumber() === 11) {
if ($taskInfo['filename'] === 'phpunit' && PhpunitVersionResolver::installedMajorVersion() === 11) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe better to add a mapping array between phpunit versions and the file to include?
This to prevent altering the actual code instead of a "mapping config".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. This is now an explicit mapping of supported PHPUnit majors to template suffixes (11 => '-11', 12 => ''), while still resolving the consumer project's installed version from Composer metadata.

Comment on lines -46 to -53
<exclude>
<directory suffix=".api.php">./</directory>
<directory suffix="Spy.php">./</directory>
<directory suffix="Stub.php">./</directory>
<directory suffix="Test.php">./</directory>
<directory suffix="TestBase.php">./</directory>
<directory suffix="TestCase.php">./</directory>
</exclude>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we remove these?
This prevents PHPUnit wanting to have code coverage for test Fixtures and base test classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. The root-wide exclusions were removed to stop PHPUnit traversing the project and vendor tree, but the exclusions themselves are still needed. They are now restored and bounded to ./src and ./modules/**/src, so fixtures, stubs, and test base classes remain outside coverage without reintroducing recursive scanning.

Comment on lines -46 to -53
<exclude>
<directory suffix=".api.php">./</directory>
<directory suffix="Spy.php">./</directory>
<directory suffix="Stub.php">./</directory>
<directory suffix="Test.php">./</directory>
<directory suffix="TestBase.php">./</directory>
<directory suffix="TestCase.php">./</directory>
</exclude>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we remove these?
This prevents PHPUnit wanting to have code coverage for test Fixtures and base test classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct. The root-wide exclusions were removed to stop PHPUnit traversing the project and vendor tree, but the exclusions themselves are still needed. They are now restored and bounded to ./src and ./modules/**/src, so fixtures, stubs, and test base classes remain outside coverage without reintroducing recursive scanning.

Comment on lines -70 to -75
<directory suffix=".api.php">./</directory>
<directory suffix="Spy.php">./</directory>
<directory suffix="Stub.php">./</directory>
<directory suffix="Test.php">./</directory>
<directory suffix="TestBase.php">./</directory>
<directory suffix="TestCase.php">./</directory>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we remove these?
This prevents PHPUnit wanting to have code coverage for test Fixtures and base test classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. The root-wide exclusions were removed to stop PHPUnit traversing the project and vendor tree, but the exclusions themselves are still needed. They are now restored and bounded to the custom module, profile, and theme roots, so fixtures, stubs, and test base classes remain outside coverage without reintroducing recursive scanning.

Comment thread configs/phpunit-site.xml
Comment on lines -70 to -75
<directory suffix=".api.php">./</directory>
<directory suffix="Spy.php">./</directory>
<directory suffix="Stub.php">./</directory>
<directory suffix="Test.php">./</directory>
<directory suffix="TestBase.php">./</directory>
<directory suffix="TestCase.php">./</directory>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we remove these?
This prevents PHPUnit wanting to have code coverage for test Fixtures and base test classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, see previous comments

@lennartvava
lennartvava force-pushed the feature/phpunit-configuration-discovery branch from c970205 to 753de54 Compare September 21, 2026 10:57
@lennartvava
lennartvava merged commit c7868c9 into develop Sep 24, 2026
8 checks passed
@lennartvava
lennartvava deleted the feature/phpunit-configuration-discovery branch September 24, 2026 07:46
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.

2 participants