FileSystemModuleDiscoveryDataProviderTrait.php 846 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?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() {
17 18 19 20
    $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);
21 22 23 24 25 26 27 28 29 30 31
    }, $module_dirs);
    $modules_keyed = array_combine($module_names, $module_names);

    $data = array_map(function ($module) {
      return [$module];
    }, $modules_keyed);

    return $data;
  }

}