function YamlDirectoryDiscoveryTest::testDiscoveryAlternateId

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscoveryAlternateId()
  2. 8.9.x core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscoveryAlternateId()
  3. 10 core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscoveryAlternateId()

Tests YAML directory discovery with an alternate ID key.

@covers ::findAll

File

core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php, line 106

Class

YamlDirectoryDiscoveryTest
YamlDirectoryDiscoveryTest component unit tests.

Namespace

Drupal\Tests\Component\Discovery

Code

public function testDiscoveryAlternateId() : void {
    vfsStream::setup('modules', NULL, [
        'test_1' => [
            'item_1.test.yml' => "alt_id: item1\nid: ignored",
        ],
    ]);
    // Set up the directories to search.
    $directories = [
        'test_1' => vfsStream::url('modules/test_1'),
    ];
    $discovery = new YamlDirectoryDiscovery($directories, 'test', 'alt_id');
    $data = $discovery->findAll();
    $this->assertSame([
        'alt_id' => 'item1',
        'id' => 'ignored',
        YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1' . DIRECTORY_SEPARATOR . 'item_1.test.yml',
    ], $data['test_1']['item1']);
    $this->assertCount(1, $data['test_1']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.