Repository navigation
Fix PHPUnit configuration discovery for Drupal QA #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,12 +67,27 @@ | |
| <directory suffix=".php">web/themes/custom</directory> | ||
| </include> | ||
| <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> | ||
|
Comment on lines
-70
to
-75
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we remove these?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, see previous comments |
||
| <directory suffix=".api.php">web/modules/custom</directory> | ||
| <directory suffix=".api.php">web/profiles/custom</directory> | ||
| <directory suffix=".api.php">web/themes/custom</directory> | ||
| <directory suffix="Spy.php">web/modules/custom</directory> | ||
| <directory suffix="Spy.php">web/profiles/custom</directory> | ||
| <directory suffix="Spy.php">web/themes/custom</directory> | ||
| <directory suffix="Stub.php">web/modules/custom</directory> | ||
| <directory suffix="Stub.php">web/profiles/custom</directory> | ||
| <directory suffix="Stub.php">web/themes/custom</directory> | ||
| <directory suffix="Test.php">web/modules/custom</directory> | ||
| <directory suffix="Test.php">web/profiles/custom</directory> | ||
| <directory suffix="Test.php">web/themes/custom</directory> | ||
| <directory suffix="TestBase.php">web/modules/custom</directory> | ||
| <directory suffix="TestBase.php">web/profiles/custom</directory> | ||
| <directory suffix="TestBase.php">web/themes/custom</directory> | ||
| <directory suffix="TestCase.php">web/modules/custom</directory> | ||
| <directory suffix="TestCase.php">web/profiles/custom</directory> | ||
| <directory suffix="TestCase.php">web/themes/custom</directory> | ||
| <directory>web/modules/custom/**/tests</directory> | ||
| <directory>web/profiles/custom/**/tests</directory> | ||
| <directory>web/themes/custom/**/tests</directory> | ||
| <directory>web/themes/custom/*/source</directory> | ||
| </exclude> | ||
| </source> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Digipolisgent\QA\Drupal\GrumPHP; | ||
|
|
||
| use Composer\InstalledVersions; | ||
|
|
||
| /** | ||
| * Resolves the PHPUnit major installed in the consumer project. | ||
| * | ||
| * @internal | ||
| */ | ||
| final class PhpunitVersionResolver { | ||
|
|
||
| /** | ||
| * Gets the installed PHPUnit major version. | ||
| */ | ||
| public static function installedMajorVersion(): int { | ||
| $version = InstalledVersions::getVersion('phpunit/phpunit'); | ||
| if ($version === NULL) { | ||
| throw new \LogicException('Unable to determine the installed PHPUnit version.'); | ||
| } | ||
|
|
||
| if (!preg_match('/^(?:v)?(?<major>\d+)/', $version, $matches)) { | ||
| throw new \LogicException(sprintf( | ||
| 'Unable to determine the PHPUnit major version from "%s".', | ||
| $version, | ||
| )); | ||
| } | ||
|
|
||
| $major = (int) $matches['major']; | ||
| if (!in_array($major, [11, 12], TRUE)) { | ||
| throw new \LogicException(sprintf( | ||
| 'Unsupported PHPUnit major version %d. Supported versions are 11 and 12.', | ||
| $major, | ||
| )); | ||
| } | ||
|
|
||
| return $major; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,14 +71,33 @@ function drupal_phpunit_core_dir(): string { | |
| */ | ||
| function drupal_phpunit_find_extension_directories(string $scanDirectory): array { | ||
| $extensions = []; | ||
| $visitedDirectories = []; | ||
| $realScanDirectory = realpath($scanDirectory); | ||
| if ($realScanDirectory !== FALSE) { | ||
| $visitedDirectories[$realScanDirectory] = TRUE; | ||
| } | ||
|
|
||
| $iterator = new RecursiveCallbackFilterIterator( | ||
| new RecursiveDirectoryIterator( | ||
| $scanDirectory, | ||
| RecursiveDirectoryIterator::FOLLOW_SYMLINKS | RecursiveDirectoryIterator::SKIP_DOTS | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we remove symlinks?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Removing |
||
| ), | ||
| static function (SplFileInfo $file): bool { | ||
| return !$file->isDir() | ||
| || !in_array($file->getFilename(), ['.git', 'node_modules', 'vendor'], TRUE); | ||
| static function (SplFileInfo $file) use (&$visitedDirectories): bool { | ||
| if (!$file->isDir()) { | ||
| return TRUE; | ||
| } | ||
|
|
||
| if (in_array($file->getFilename(), ['.git', 'node_modules', 'vendor'], TRUE)) { | ||
| return FALSE; | ||
| } | ||
|
|
||
| $realPath = $file->getRealPath(); | ||
| if ($realPath === FALSE || isset($visitedDirectories[$realPath])) { | ||
| return FALSE; | ||
| } | ||
|
|
||
| $visitedDirectories[$realPath] = TRUE; | ||
| return TRUE; | ||
| } | ||
| ); | ||
| $directories = new RecursiveIteratorIterator( | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.