diff --git a/src/Core/Manifest/ManifestFileFinder.php b/src/Core/Manifest/ManifestFileFinder.php index c4c248e2359..2e737bd0115 100644 --- a/src/Core/Manifest/ManifestFileFinder.php +++ b/src/Core/Manifest/ManifestFileFinder.php @@ -32,7 +32,8 @@ class ManifestFileFinder extends FileFinder 'include_themes' => false, 'ignore_tests' => true, 'min_depth' => 1, - 'ignore_dirs' => ['node_modules'] + 'ignore_dirs' => ['node_modules'], + 'ignore_ci_library' => [] ]; public function acceptDir($basename, $pathname, $depth) @@ -73,6 +74,14 @@ public function acceptDir($basename, $pathname, $depth) return false; } + // Skip if test dir inside vendor module with unexpected CI library + if ($depth > 3 && $basename === self::TESTS_DIR && $ignoreCILib = $this->getOption('ignore_ci_library')) { + $ciLib = $this->findModuleCILib($basename, $pathname, $depth); + if (in_array($ciLib, $ignoreCILib)) { + return false; + } + } + return parent::acceptDir($basename, $pathname, $depth); } @@ -251,4 +260,22 @@ public function isDirectoryIgnored($basename, $pathname, $depth) return false; } + + private function findModuleCILib(string $basename, string $pathname, int $depth): string + { + if ($depth < 1) { + return Module::CI_PHPUNIT_UNKNOWN; + } + + $newBasename = basename($pathname); + $newPathname = dirname($pathname); + $newDepth = $depth - 1; + + if ($this->isDirectoryModule($newBasename, $newPathname, $newDepth)) { + $module = new Module($newPathname, $this->upLevels($newPathname, $newDepth)); + return $module->getCILibrary(); + } + + return $this->findModuleCILib($newBasename, $newPathname, $newDepth); + } } diff --git a/src/Core/Manifest/Module.php b/src/Core/Manifest/Module.php index 22bd08e4604..71a29cde312 100644 --- a/src/Core/Manifest/Module.php +++ b/src/Core/Manifest/Module.php @@ -5,7 +5,6 @@ use Composer\Semver\Semver; use Exception; use InvalidArgumentException; -use RuntimeException; use Serializable; use SilverStripe\Core\Path; use SilverStripe\Dev\Deprecation; @@ -301,8 +300,9 @@ public function hasResource($path) */ public function getCILibrary(): string { + // We don't have any composer data at all if (empty($this->composerData)) { - throw new RuntimeException('No composer data at all'); + return self::CI_PHPUNIT_UNKNOWN; } // We don't have any dev dependencies diff --git a/tests/php/Core/Manifest/ManifestFileFinderTest.php b/tests/php/Core/Manifest/ManifestFileFinderTest.php index 7c0909b10c4..e179eb04992 100644 --- a/tests/php/Core/Manifest/ManifestFileFinderTest.php +++ b/tests/php/Core/Manifest/ManifestFileFinderTest.php @@ -4,6 +4,7 @@ use SilverStripe\Core\Manifest\ManifestFileFinder; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Core\Manifest\Module; /** * Tests for the {@link ManifestFileFinder} class. @@ -55,6 +56,8 @@ public function testBasicOperation() [ 'module/module.txt', 'vendor/myvendor/thismodule/module.txt', + 'vendor/myvendor/phpunit5module/code/logic.txt', + 'vendor/myvendor/phpunit9module/code/logic.txt', ] ); } @@ -75,6 +78,56 @@ public function testIgnoreTests() 'vendor/myvendor/thismodule/module.txt', 'vendor/myvendor/thismodule/tests/tests.txt', 'vendor/myvendor/thismodule/code/tests/tests2.txt', + 'vendor/myvendor/phpunit5module/code/logic.txt', + 'vendor/myvendor/phpunit5module/tests/phpunit5tests.txt', + 'vendor/myvendor/phpunit9module/code/logic.txt', + 'vendor/myvendor/phpunit9module/tests/phpunit9tests.txt', + ] + ); + } + + public function testIgnorePHPUnit5Tests() + { + $finder = new ManifestFileFinder(); + $finder->setOption('name_regex', '/\.txt$/'); + $finder->setOption('ignore_tests', false); + $finder->setOption('ignore_ci_library', [Module::CI_PHPUNIT_FIVE]); + + $this->assertFinderFinds( + $finder, + null, + [ + 'module/module.txt', + 'module/tests/tests.txt', + 'module/code/tests/tests2.txt', + 'vendor/myvendor/thismodule/module.txt', + 'vendor/myvendor/thismodule/tests/tests.txt', + 'vendor/myvendor/thismodule/code/tests/tests2.txt', + 'vendor/myvendor/phpunit5module/code/logic.txt', + 'vendor/myvendor/phpunit9module/code/logic.txt', + 'vendor/myvendor/phpunit9module/tests/phpunit9tests.txt', + ] + ); + } + + public function testIgnoreNonePHPUnit9Tests() + { + $finder = new ManifestFileFinder(); + $finder->setOption('name_regex', '/\.txt$/'); + $finder->setOption('ignore_tests', false); + $finder->setOption('ignore_ci_library', [Module::CI_PHPUNIT_FIVE, Module::CI_PHPUNIT_UNKNOWN]); + + $this->assertFinderFinds( + $finder, + null, + [ + 'module/module.txt', + 'module/tests/tests.txt', + 'module/code/tests/tests2.txt', + 'vendor/myvendor/thismodule/module.txt', + 'vendor/myvendor/phpunit5module/code/logic.txt', + 'vendor/myvendor/phpunit9module/code/logic.txt', + 'vendor/myvendor/phpunit9module/tests/phpunit9tests.txt', ] ); } @@ -92,6 +145,8 @@ public function testIncludeThemes() 'module/module.txt', 'themes/themes.txt', 'vendor/myvendor/thismodule/module.txt', + 'vendor/myvendor/phpunit5module/code/logic.txt', + 'vendor/myvendor/phpunit9module/code/logic.txt', ] ); } diff --git a/tests/php/Core/Manifest/fixtures/manifestfilefinder/vendor/myvendor/phpunit5module/_config.php b/tests/php/Core/Manifest/fixtures/manifestfilefinder/vendor/myvendor/phpunit5module/_config.php new file mode 100644 index 00000000000..b3d9bbc7f37 --- /dev/null +++ b/tests/php/Core/Manifest/fixtures/manifestfilefinder/vendor/myvendor/phpunit5module/_config.php @@ -0,0 +1 @@ +