FileSystemModuleDiscoveryDataProviderTrait.php 786 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace Drupal\KernelTests;
  3. /**
  4. * A trait used in testing for providing a list of modules in a dataProvider.
  5. */
  6. trait FileSystemModuleDiscoveryDataProviderTrait {
  7. /**
  8. * A data provider that lists every module in core.
  9. *
  10. * @return array
  11. * An array of module names to test.
  12. */
  13. public function coreModuleListDataProvider() {
  14. $module_dirs = array_keys(iterator_to_array(new \FilesystemIterator(__DIR__ . '/../../../modules/')));
  15. $module_names = array_map(function($path) {
  16. return str_replace(__DIR__ . '/../../../modules/', '', $path);
  17. }, $module_dirs);
  18. $modules_keyed = array_combine($module_names, $module_names);
  19. $data = array_map(function ($module) {
  20. return [$module];
  21. }, $modules_keyed);
  22. return $data;
  23. }
  24. }