function YamlDirectoryDiscoveryTest::testDiscoveryAlternateId

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscoveryAlternateId()
  2. 10 core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscoveryAlternateId()
  3. 11.x 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 104

Class

YamlDirectoryDiscoveryTest
YamlDirectoryDiscoveryTest component unit tests.

Namespace

Drupal\Tests\Component\Discovery

Code

public function testDiscoveryAlternateId() {
    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.