Skip to content
Snippets Groups Projects
Unverified Commit 8f92d9a1 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2973127 by vaplas, Mile23, alexpott: Exclude *TestBase.php, *Trait.php...

Issue #2973127 by vaplas, Mile23, alexpott: Exclude *TestBase.php, *Trait.php and *Interface.php files from test discovery reflection
parent 551cb08b
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -282,13 +282,21 @@ public static function scanDirectory($namespace_prefix, $path) { ...@@ -282,13 +282,21 @@ public static function scanDirectory($namespace_prefix, $path) {
$flags |= \FilesystemIterator::SKIP_DOTS; $flags |= \FilesystemIterator::SKIP_DOTS;
$flags |= \FilesystemIterator::FOLLOW_SYMLINKS; $flags |= \FilesystemIterator::FOLLOW_SYMLINKS;
$flags |= \FilesystemIterator::CURRENT_AS_SELF; $flags |= \FilesystemIterator::CURRENT_AS_SELF;
$flags |= \FilesystemIterator::KEY_AS_FILENAME;
$iterator = new \RecursiveDirectoryIterator($path, $flags); $iterator = new \RecursiveDirectoryIterator($path, $flags);
$filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $key, $iterator) { $filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $file_name, $iterator) {
if ($iterator->hasChildren()) { if ($iterator->hasChildren()) {
return TRUE; return TRUE;
} }
return $current->isFile() && $current->getExtension() === 'php'; // We don't want to discover abstract TestBase classes, traits or
// interfaces. They can be deprecated and will call @trigger_error()
// during discovery.
return
substr($file_name, -4) === '.php' &&
substr($file_name, -12) !== 'TestBase.php' &&
substr($file_name, -9) !== 'Trait.php' &&
substr($file_name, -13) !== 'Interface.php';
}); });
$files = new \RecursiveIteratorIterator($filter); $files = new \RecursiveIteratorIterator($filter);
$classes = []; $classes = [];
......
...@@ -281,6 +281,9 @@ class FunctionalExampleTest {} ...@@ -281,6 +281,9 @@ class FunctionalExampleTest {}
], ],
'Kernel' => [ 'Kernel' => [
'KernelExampleTest3.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest3', '@group example2'], $test_file), 'KernelExampleTest3.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest3', '@group example2'], $test_file),
'KernelExampleTestBase.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTestBase', '@group example2'], $test_file),
'KernelExampleTrait.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTrait', '@group example2'], $test_file),
'KernelExampleInterface.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleInterface', '@group example2'], $test_file),
], ],
], ],
], ],
...@@ -400,6 +403,21 @@ public function testGetTestInfoEmptyDocblock() { ...@@ -400,6 +403,21 @@ public function testGetTestInfoEmptyDocblock() {
TestDiscovery::getTestInfo('Drupal\Tests\simpletest\ThisTestDoesNotExistTest', ''); TestDiscovery::getTestInfo('Drupal\Tests\simpletest\ThisTestDoesNotExistTest', '');
} }
/**
* Ensure TestDiscovery::scanDirectory() ignores certain abstract file types.
*
* @covers ::scanDirectory
*/
public function testScanDirectoryNoAbstract() {
$this->setupVfsWithTestClasses();
$files = TestDiscovery::scanDirectory('Drupal\\Tests\\test_module\\Kernel\\', vfsStream::url('drupal/modules/test_module/tests/src/Kernel'));
$this->assertNotEmpty($files);
$this->assertArrayNotHasKey('Drupal\Tests\test_module\Kernel\KernelExampleTestBase', $files);
$this->assertArrayNotHasKey('Drupal\Tests\test_module\Kernel\KernelExampleTrait', $files);
$this->assertArrayNotHasKey('Drupal\Tests\test_module\Kernel\KernelExampleInterface', $files);
$this->assertArrayHasKey('Drupal\Tests\test_module\Kernel\KernelExampleTest3', $files);
}
} }
class TestTestDiscovery extends TestDiscovery { class TestTestDiscovery extends TestDiscovery {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment