Commit dc436055 authored by catch's avatar catch
Browse files

Issue #2067809 by Berdir, damiankloip: Fixed YamlDiscovery uses basename of...

Issue #2067809 by Berdir, damiankloip: Fixed YamlDiscovery uses basename of directory instead of module name.
parent 605ed74f
......@@ -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;
}
}
name: 'Router test'
type: module
description: 'Support module for routing testing.'
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
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment