You are here

public function YamlDirectoryDiscoveryTest::testDiscoveryInvalidYamlException in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscoveryInvalidYamlException()

Tests YAML directory discovery with invalid YAML.

@covers ::findAll

File

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

Class

YamlDirectoryDiscoveryTest
YamlDirectoryDiscoveryTest component unit tests.

Namespace

Drupal\Tests\Component\Discovery

Code

public function testDiscoveryInvalidYamlException() {
  $this
    ->expectException(DiscoveryException::class);
  $this
    ->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains invalid YAML');
  vfsStream::setup('modules', NULL, [
    'test_1' => [
      'item_1.test.yml' => "id: invalid\nfoo : [bar}",
    ],
  ]);

  // Set up the directories to search.
  $directories = [
    'test_1' => vfsStream::url('modules/test_1'),
  ];
  $discovery = new YamlDirectoryDiscovery($directories, 'test');
  $discovery
    ->findAll();
}