View source
<?php
namespace Drupal\Tests\sqlsrv\TestSuites;
use PHPUnit\Framework\TestSuite;
use Drupal\Core\Test\TestDiscovery;
abstract class TestSuiteBase extends TestSuite {
protected $failingClasses = [
'/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php',
'/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php',
'/core/modules/aggregator/tests/src/Kernel/Migrate/MigrateAggregatorStubTest.php',
'/core/modules/migrate_drupal/tests/src/Kernel/d7/FieldDiscoveryTest.php',
'/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php',
'/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php',
'/core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php',
'/core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php',
'/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php',
'/core/modules/path/tests/src/Functional/PathAliasTest.php',
'/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php',
'/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php',
'/core/modules/views_ui/tests/src/Functional/UnsavedPreviewTest.php',
];
protected function findExtensionDirectories($root) {
$extension_roots = \drupal_phpunit_contrib_extension_directory_roots($root);
$extension_directories = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
return array_reduce($extension_directories, 'array_merge', []);
}
protected function addCoreKernelTestsByName($root, $pattern) {
$failing_classes = [];
foreach ($this->failingClasses as $failing_class) {
$failing_classes[] = $root . $failing_class;
}
$passing_tests = [];
$tests = TestDiscovery::scanDirectory("Drupal\\KernelTests\\", "{$root}/core/tests/Drupal/KernelTests");
foreach ($tests as $test) {
if (!in_array($test, $failing_classes) && preg_match("#.*\\/{$pattern}[a-zA-z]*\\.php\$#i", $test) !== 0) {
$passing_tests[] = $test;
}
}
$this
->addTestFiles($passing_tests);
}
protected function addExtensionTestsBySuiteNamespace($root, $suite_namespace, $pattern) {
$failing_classes = [];
foreach ($this->failingClasses as $failing_class) {
$failing_classes[] = $root . $failing_class;
}
foreach ($this
->findExtensionDirectories($root) as $extension_name => $dir) {
if (preg_match("#^{$pattern}(.*)\$#i", $extension_name) !== 0) {
$test_path = "{$dir}/tests/src/{$suite_namespace}";
if (is_dir($test_path)) {
$passing_tests = [];
$tests = TestDiscovery::scanDirectory("Drupal\\Tests\\{$extension_name}\\{$suite_namespace}\\", $test_path);
foreach ($tests as $test) {
if (!in_array($test, $failing_classes)) {
$passing_tests[] = $test;
}
}
$this
->addTestFiles($passing_tests);
}
}
}
}
protected function addExtensionTestsBySuiteNamespaceAndChunk($root, $suite_namespace, $index = -1) {
$failing_classes = [];
foreach ($this->failingClasses as $failing_class) {
$failing_classes[] = $root . $failing_class;
}
$passing_tests = [];
foreach ($this
->findExtensionDirectories($root) as $extension_name => $dir) {
$test_path = "{$dir}/tests/src/{$suite_namespace}";
if (is_dir($test_path)) {
$tests = TestDiscovery::scanDirectory("Drupal\\Tests\\{$extension_name}\\{$suite_namespace}\\", $test_path);
foreach ($tests as $test) {
if (!in_array($test, $failing_classes)) {
$passing_tests[] = $test;
}
}
}
}
$sizes = static::$functionalSizes;
$total_size = array_sum($sizes);
$total_tests = count($passing_tests);
if ($index == -1) {
$index = rand(0, count($sizes) - 1);
}
$length = $sizes[$index];
$offset = $index == 0 ? 0 : array_sum(array_splice($sizes, 0, $index));
$subset = array_splice($passing_tests, $offset, $length);
$extend = max(0, $total_tests - $total_size);
$message = " SPLICE:" . $index . " EXTEND:" . $extend . " ";
fwrite(STDOUT, $message);
$this
->addTestFiles($subset);
}
protected static function getDrupalRoot() {
return dirname(__DIR__, 5);
}
public static function getCoreExtensionSuite($index) {
$root = static::getDrupalRoot();
$suite = new static('kernel');
$suite
->addExtensionTestsBySuiteNamespace($root, 'Kernel', static::$coreExtensionPatterns[$index]);
return $suite;
}
}