function drupal_phpunit_get_extension_namespaces

Same name in other branches
  1. 8.9.x core/tests/bootstrap.php \drupal_phpunit_get_extension_namespaces()
  2. 10 core/tests/bootstrap.php \drupal_phpunit_get_extension_namespaces()
  3. 11.x core/tests/bootstrap.php \drupal_phpunit_get_extension_namespaces()

Registers the namespace for each extension directory with the autoloader.

Parameters

array $dirs: An associative array of extension directories, keyed by extension name.

Return value

array An associative array of extension directories, keyed by their namespace.

1 call to drupal_phpunit_get_extension_namespaces()
drupal_phpunit_populate_class_loader in core/tests/bootstrap.php
Populate class loader with additional namespaces for tests.

File

core/tests/bootstrap.php, line 82

Code

function drupal_phpunit_get_extension_namespaces($dirs) {
    $suite_names = [
        'Unit',
        'Kernel',
        'Functional',
        'Build',
        'FunctionalJavascript',
    ];
    $namespaces = [];
    foreach ($dirs as $extension => $dir) {
        if (is_dir($dir . '/src')) {
            // Register the PSR-4 directory for module-provided classes.
            $namespaces['Drupal\\' . $extension . '\\'][] = $dir . '/src';
        }
        $test_dir = $dir . '/tests/src';
        if (is_dir($test_dir)) {
            foreach ($suite_names as $suite_name) {
                $suite_dir = $test_dir . '/' . $suite_name;
                if (is_dir($suite_dir)) {
                    // Register the PSR-4 directory for PHPUnit-based suites.
                    $namespaces['Drupal\\Tests\\' . $extension . '\\' . $suite_name . '\\'][] = $suite_dir;
                }
            }
            // Extensions can have a \Drupal\Tests\extension\Traits namespace for
            // cross-suite trait code.
            $trait_dir = $test_dir . '/Traits';
            if (is_dir($trait_dir)) {
                $namespaces['Drupal\\Tests\\' . $extension . '\\Traits\\'][] = $trait_dir;
            }
        }
    }
    return $namespaces;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.