You are here

public function InfoParserUnitTest::testInfoParserMissingKey in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php \Drupal\Tests\Core\Extension\InfoParserUnitTest::testInfoParserMissingKey()
  2. 10 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 335

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
core: 8.x
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'));
  }
}