You are here

public function InfoParserUnitTest::testMissingCoreVersionRequirement in Drupal 10

Tests that a missing 'core_version_requirement' key is detected.

@covers ::parse

File

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

Class

InfoParserUnitTest
Tests InfoParser class and exception.

Namespace

Drupal\Tests\Core\Extension

Code

public function testMissingCoreVersionRequirement() {
  $missing_core_version_requirement = <<<MISSING_CORE_VERSION_REQUIREMENT
# info.yml for testing core_version_requirement.
version: VERSION
type: module
name: Skynet
dependencies:
  - self_awareness
MISSING_CORE_VERSION_REQUIREMENT;
  vfsStream::setup('modules');
  vfsStream::create([
    'fixtures' => [
      'missing_core_version_requirement.info.txt' => $missing_core_version_requirement,
      'missing_core_version_requirement-duplicate.info.txt' => $missing_core_version_requirement,
    ],
  ]);
  $exception_message = "The 'core_version_requirement' key must be present in vfs://modules/fixtures/missing_core_version_requirement";

  // Set the expected exception for the 2nd call to parse().
  $this
    ->expectException('\\Drupal\\Core\\Extension\\InfoParserException');
  $this
    ->expectExceptionMessage("{$exception_message}-duplicate.info.txt");
  try {
    $this->infoParser
      ->parse(vfsStream::url('modules/fixtures/missing_core_version_requirement.info.txt'));
  } catch (InfoParserException $exception) {
    $this
      ->assertSame("{$exception_message}.info.txt", $exception
      ->getMessage());
    $this->infoParser
      ->parse(vfsStream::url('modules/fixtures/missing_core_version_requirement-duplicate.info.txt'));
  }
}