FileSystemModuleDiscoveryDataProviderTrait.php

Same filename in other branches
  1. 9 core/tests/Drupal/KernelTests/FileSystemModuleDiscoveryDataProviderTrait.php
  2. 10 core/tests/Drupal/KernelTests/FileSystemModuleDiscoveryDataProviderTrait.php
  3. 11.x core/tests/Drupal/KernelTests/FileSystemModuleDiscoveryDataProviderTrait.php

Namespace

Drupal\KernelTests

File

core/tests/Drupal/KernelTests/FileSystemModuleDiscoveryDataProviderTrait.php

View source
<?php

namespace Drupal\KernelTests;


/**
 * A trait used in testing for providing a list of modules in a dataProvider.
 */
trait FileSystemModuleDiscoveryDataProviderTrait {
    
    /**
     * A data provider that lists every module in core.
     *
     * @return array
     *   An array of module names to test.
     */
    public function coreModuleListDataProvider() {
        $prefix = dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'modules';
        $module_dirs = array_keys(iterator_to_array(new \FilesystemIterator($prefix)));
        $module_names = array_map(function ($path) use ($prefix) {
            return str_replace($prefix . DIRECTORY_SEPARATOR, '', $path);
        }, $module_dirs);
        $modules_keyed = array_combine($module_names, $module_names);
        $data = array_map(function ($module) {
            return [
                $module,
            ];
        }, $modules_keyed);
        return $data;
    }

}

Traits

Title Deprecated Summary
FileSystemModuleDiscoveryDataProviderTrait A trait used in testing for providing a list of modules in a dataProvider.

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