diff --git a/core/lib/Drupal/Component/Discovery/YamlDiscovery.php b/core/lib/Drupal/Component/Discovery/YamlDiscovery.php index 38c4d44..5ac0b7d 100644 --- a/core/lib/Drupal/Component/Discovery/YamlDiscovery.php +++ b/core/lib/Drupal/Component/Discovery/YamlDiscovery.php @@ -22,7 +22,7 @@ class YamlDiscovery implements DiscoverableInterface { protected $name; /** - * An array of directories to scan. + * An array of directories to scan, keyed by the provider. * * @var array */ @@ -39,10 +39,10 @@ class YamlDiscovery implements DiscoverableInterface { * Constructs a YamlDiscovery object. * * @param string $name - * The + * The base filename to look for in each directory. The format will be + * $provider.$name.yml. * @param array $directories - * An array of directories to scan. If an associative array is provided the - * return array will use these keys. + * An array of directories to scan, keyed by the provider. */ public function __construct($name, array $directories) { $this->name = $name; @@ -56,15 +56,15 @@ public function findAll() { $all = array(); $parser = $this->parser(); - foreach ($this->findFiles() as $key => $file) { - $all[$key] = $parser->parse(file_get_contents($file)); + foreach ($this->findFiles() as $provider => $file) { + $all[$provider] = $parser->parse(file_get_contents($file)); } return $all; } /** - * Returns the YAML parse. + * Returns the YAML parser. * * @return \Symfony\Component\Yaml\Parser * The symfony YAML parser. @@ -77,33 +77,20 @@ protected function parser() { } /** - * Returns an array of file paths. + * Returns an array of file paths, keyed by provider. * * @return array */ protected function findFiles() { $files = array(); - foreach ($this->directories as $key => $directory) { - $file = $directory . '/' . $this->fileBaseName($directory) . '.yml'; + foreach ($this->directories as $provider => $directory) { + $file = $directory . '/' . $provider . '.' . $this->name . '.yml'; if (file_exists($file)) { - $files[$key] = $file; + $files[$provider] = $file; } } return $files; } - /** - * Returns the base filename for the current directory. - * - * @param string $directory - * The current directory path. - * - * @return string - * The file name, without the .yml extension. - */ - protected function fileBaseName($directory) { - return basename($directory) . '.' . $this->name; - } - } diff --git a/core/modules/system/tests/modules/router_test/router_test.info.yml b/core/modules/system/tests/modules/router_test/router_test.info.yml deleted file mode 100644 index 8641b98..0000000 --- a/core/modules/system/tests/modules/router_test/router_test.info.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: 'Router test' -type: module -description: 'Support module for routing testing.' -package: Testing -version: VERSION -core: 8.x -hidden: true diff --git a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/Access/DefinedTestAccessCheck.php b/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/Access/DefinedTestAccessCheck.php similarity index 100% rename from core/modules/system/tests/modules/router_test/lib/Drupal/router_test/Access/DefinedTestAccessCheck.php rename to core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/Access/DefinedTestAccessCheck.php diff --git a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/Access/TestAccessCheck.php b/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/Access/TestAccessCheck.php similarity index 100% rename from core/modules/system/tests/modules/router_test/lib/Drupal/router_test/Access/TestAccessCheck.php rename to core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/Access/TestAccessCheck.php diff --git a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouteTestSubscriber.php b/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/RouteTestSubscriber.php similarity index 100% rename from core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouteTestSubscriber.php rename to core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/RouteTestSubscriber.php diff --git a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php b/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/RouterTestServiceProvider.php similarity index 100% rename from core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php rename to core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/RouterTestServiceProvider.php diff --git a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/TestContent.php b/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/TestContent.php similarity index 100% rename from core/modules/system/tests/modules/router_test/lib/Drupal/router_test/TestContent.php rename to core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/TestContent.php diff --git a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/TestControllers.php b/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/TestControllers.php similarity index 100% rename from core/modules/system/tests/modules/router_test/lib/Drupal/router_test/TestControllers.php rename to core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/TestControllers.php diff --git a/core/modules/system/tests/modules/router_test_directory/router_test.info.yml b/core/modules/system/tests/modules/router_test_directory/router_test.info.yml new file mode 100644 index 0000000..915f0ff --- /dev/null +++ b/core/modules/system/tests/modules/router_test_directory/router_test.info.yml @@ -0,0 +1,7 @@ +name: 'Router test' +type: module +description: 'Support module for routing testing. In a directory that does not match the module name to test that use case.' +package: Testing +version: VERSION +core: 8.x +hidden: true diff --git a/core/modules/system/tests/modules/router_test/router_test.module b/core/modules/system/tests/modules/router_test_directory/router_test.module similarity index 100% rename from core/modules/system/tests/modules/router_test/router_test.module rename to core/modules/system/tests/modules/router_test_directory/router_test.module diff --git a/core/modules/system/tests/modules/router_test/router_test.routing.yml b/core/modules/system/tests/modules/router_test_directory/router_test.routing.yml similarity index 100% rename from core/modules/system/tests/modules/router_test/router_test.routing.yml rename to core/modules/system/tests/modules/router_test_directory/router_test.routing.yml diff --git a/core/tests/Drupal/Tests/Component/Discovery/Fixtures/test_2/test_3.test.yml b/core/tests/Drupal/Tests/Component/Discovery/Fixtures/test_2/test_3.test.yml new file mode 100644 index 0000000..b327536 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Discovery/Fixtures/test_2/test_3.test.yml @@ -0,0 +1 @@ +name: test diff --git a/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php index 8075674..325ef01 100644 --- a/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php @@ -32,14 +32,17 @@ public function testDiscovery() { $directories = array( 'test_1' => $base_path . '/test_1', 'test_2' => $base_path . '/test_2', + // Use the same directory with a different provider name. + 'test_3' => $base_path . '/test_2', ); $discovery = new YamlDiscovery('test', $directories); $data = $discovery->findAll(); - $this->assertEquals(count($data), 2); + $this->assertEquals(count($data), count($directories)); $this->assertArrayHasKey('test_1', $data); $this->assertArrayHasKey('test_2', $data); + $this->assertArrayHasKey('test_3', $data); foreach ($data as $item) { $this->assertArrayHasKey('name', $item);