function InfoParserUnitTest::testMissingCoreCoreVersionRequirement

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php \Drupal\Tests\Core\Extension\InfoParserUnitTest::testMissingCoreCoreVersionRequirement()

Tests that missing 'core' and 'core_version_requirement' keys are detected.

@covers ::parse

File

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

Class

InfoParserUnitTest
Tests InfoParser class and exception.

Namespace

Drupal\Tests\Core\Extension

Code

public function testMissingCoreCoreVersionRequirement() {
    $missing_core_and_core_version_requirement = <<<MISSING_CORE_AND_CORE_VERSION_REQUIREMENT
# info.yml for testing core and core_version_requirement.
version: VERSION
type: module
name: Skynet
dependencies:
  - self_awareness
MISSING_CORE_AND_CORE_VERSION_REQUIREMENT;
    vfsStream::setup('modules');
    vfsStream::create([
        'fixtures' => [
            'missing_core_and_core_version_requirement.info.txt' => $missing_core_and_core_version_requirement,
            'missing_core_and_core_version_requirement-duplicate.info.txt' => $missing_core_and_core_version_requirement,
        ],
    ]);
    $exception_message = "The 'core' or the 'core_version_requirement' key must be present in vfs://modules/fixtures/missing_core_and_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_and_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_and_core_version_requirement-duplicate.info.txt'));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.