Skip to content
Snippets Groups Projects

Optimize test ordering when directory is passed.

Open catch requested to merge issue/drupal-3450616:3450616-optimize-test-order into 11.x
All threads resolved!
Files
2
@@ -119,7 +119,9 @@ public function registerTestNamespaces() {
* @param string $extension
* (optional) The name of an extension to limit discovery to; e.g., 'node'.
* @param string[] $types
* An array of included test types.
* (optional) An array of included test types.
* @param string|null $directory
* (optional) Limit discovered tests to a specific directory.
*
* @return array
* An array of tests keyed by the group name. If a test is annotated to
@@ -140,7 +142,7 @@ public function registerTestNamespaces() {
* @todo Remove singular grouping; retain list of groups in 'group' key.
* @see https://www.drupal.org/node/2296615
*/
public function getTestClasses($extension = NULL, array $types = []) {
public function getTestClasses($extension = NULL, array $types = [], ?string $directory = NULL) {
if (!isset($extension) && empty($types)) {
if (!empty($this->testClasses)) {
return $this->testClasses;
@@ -148,7 +150,7 @@ public function getTestClasses($extension = NULL, array $types = []) {
}
$list = [];
$classmap = $this->findAllClassFiles($extension);
$classmap = $this->findAllClassFiles($extension, $directory);
// Prevent expensive class loader lookups for each reflected test class by
// registering the complete classmap of test classes to the class loader.
@@ -200,12 +202,14 @@ public function getTestClasses($extension = NULL, array $types = []) {
*
* @param string $extension
* (optional) The name of an extension to limit discovery to; e.g., 'node'.
* @param string|null $directory
* (optional) Limit discovered tests to a specific directory.
*
* @return array
* A classmap containing all discovered class files; i.e., a map of
* fully-qualified classnames to path names.
*/
public function findAllClassFiles($extension = NULL) {
public function findAllClassFiles($extension = NULL, ?string $directory = NULL) {
$classmap = [];
$namespaces = $this->registerTestNamespaces();
if (isset($extension)) {
@@ -215,7 +219,7 @@ public function findAllClassFiles($extension = NULL) {
}
foreach ($namespaces as $namespace => $paths) {
foreach ($paths as $path) {
if (!is_dir($path)) {
if (!is_dir($path) || (!is_null($directory) && !str_contains($path, $directory))) {
continue;
}
$classmap += static::scanDirectory($namespace, $path);
Loading