diff --git a/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php index 80b270a..3f86bdf 100644 --- a/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php @@ -9,6 +9,9 @@ use Drupal\Tests\UnitTestCase; use Drupal\Component\Discovery\YamlDiscovery; +use org\bovigo\vfs\vfsStream; +use org\bovigo\vfs\vfsStreamDirectory; +use org\bovigo\vfs\vfsStreamWrapper; /** * YamlDiscovery component unit tests. @@ -19,24 +22,47 @@ class YamlDiscoveryTest extends UnitTestCase { /** + * The test module base URL. + * + * @var string + */ + protected $url; + + /** + * {@inheritdoc} + */ + public function setUp() { + vfsStreamWrapper::register(); + $root = new vfsStreamDirectory('test_modules'); + vfsStreamWrapper::setRoot($root); + $this->url = vfsStream::url('test_modules'); + } + + /** * Tests the YAML file discovery. * * @covers ::findAll */ public function testDiscovery() { - $base_path = __DIR__ . '/Fixtures'; // Set up the directories to search. $directories = array( - 'test_1' => $base_path . '/test_1', - 'test_2' => $base_path . '/test_2', + 'test_1' => $this->url . '/test_1', + 'test_2' => $this->url . '/test_2', // Use the same directory with a different provider name. - 'test_3' => $base_path . '/test_2', + 'test_3' => $this->url . '/test_2', ); + foreach ($directories as $provider => $directory) { + if (!file_exists($directory)) { + mkdir($directory); + } + file_put_contents($directory . '/' . $provider . '.test.yml', 'name: test'); + } + $discovery = new YamlDiscovery('test', $directories); $data = $discovery->findAll(); - $this->assertEquals(count($data), count($directories)); + $this->assertCount(3, $data); $this->assertArrayHasKey('test_1', $data); $this->assertArrayHasKey('test_2', $data); $this->assertArrayHasKey('test_3', $data); @@ -53,16 +79,30 @@ public function testDiscovery() { * @covers ::findAll */ public function testImport() { - $base_path = __DIR__ . '/Fixtures'; // Set up the directories to search. $directories = array( - 'test_import' => $base_path . '/test_import', + 'test_import' => $this->url . '/test_import', ); + $directory = $directories['test_import']; + mkdir($directory); + + file_put_contents($directory . '/test_import.test.yml', " +name: test +imports: + - test_import.yml + "); + + file_put_contents($directory . '/test_import.yml', " +# Name should not get overwritten from import. +name: test_import +additional: imported + "); + $discovery = new YamlDiscovery('test', $directories); $data = $discovery->findAll(); - $this->assertEquals(count($data), count($directories)); + $this->assertCount(1, $data); $this->assertArrayHasKey('test_import', $data); $item = $data['test_import']; @@ -74,7 +114,5 @@ public function testImport() { // Check the new imported key exists. $this->assertArrayHasKey('additional', $item); $this->assertEquals($item['additional'], 'imported'); - } - }