You are here

public function InfoParserUnitTest::testInfoParserMissingKey in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php \Drupal\Tests\Core\Extension\InfoParserUnitTest::testInfoParserMissingKey()
  2. 9 core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php \Drupal\Tests\Core\Extension\InfoParserUnitTest::testInfoParserMissingKey()

Tests that missing required key is detected.

@covers ::parse

File

core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php, line 173

Class

InfoParserUnitTest
Tests InfoParser class and exception.

Namespace

Drupal\Tests\Core\Extension

Code

public function testInfoParserMissingKey() {
  $missing_key = <<<MISSINGKEY
# info.yml for testing missing type key.
name: File
description: 'Defines a file field type.'
package: Core
version: VERSION
dependencies:
  - field
MISSINGKEY;
  vfsStream::setup('modules');
  vfsStream::create([
    'fixtures' => [
      'missing_key.info.txt' => $missing_key,
      'missing_key-duplicate.info.txt' => $missing_key,
    ],
  ]);

  // Set the expected exception for the 2nd call to parse().
  $this
    ->expectException(InfoParserException::class);
  $this
    ->expectExceptionMessage('Missing required keys (type) in vfs://modules/fixtures/missing_key-duplicate.info.txt');
  try {
    $this->infoParser
      ->parse(vfsStream::url('modules/fixtures/missing_key.info.txt'));
  } catch (InfoParserException $exception) {
    $this
      ->assertSame('Missing required keys (type) in vfs://modules/fixtures/missing_key.info.txt', $exception
      ->getMessage());
    $this->infoParser
      ->parse(vfsStream::url('modules/fixtures/missing_key-duplicate.info.txt'));
  }
}