FileSystemModuleDiscoveryDataProviderTrait.php 846 B

12345678910111213141516171819202122232425262728293031
  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. $prefix = dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'modules';
  15. $module_dirs = array_keys(iterator_to_array(new \FilesystemIterator($prefix)));
  16. $module_names = array_map(function ($path) use ($prefix) {
  17. return str_replace($prefix . DIRECTORY_SEPARATOR, '', $path);
  18. }, $module_dirs);
  19. $modules_keyed = array_combine($module_names, $module_names);
  20. $data = array_map(function ($module) {
  21. return [$module];
  22. }, $modules_keyed);
  23. return $data;
  24. }
  25. }