function InfoParserUnitTest::testInfoException

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php \Drupal\Tests\Core\Extension\InfoParserUnitTest::testInfoException()

Tests if correct exception is thrown for a broken info file.

@dataProvider providerInfoException

Parameters

string $yaml: The YAML to use to create the file to parse.

string $expected_exception_message: The expected exception message.

File

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

Class

InfoParserUnitTest
Tests InfoParser class and exception.

Namespace

Drupal\Tests\Core\Extension

Code

public function testInfoException($yaml, $expected_exception_message) : void {
  vfsStream::setup('modules');
  vfsStream::create([
    'fixtures' => [
      "broken.info.txt" => $yaml,
      "broken-duplicate.info.txt" => $yaml,
    ],
  ]);
  try {
    $this->infoParser
      ->parse(vfsStream::url("modules/fixtures/broken.info.txt"));
  } catch (InfoParserException $exception) {
    $this->assertSame("{$expected_exception_message} vfs://modules/fixtures/broken.info.txt", $exception->getMessage());
  }
  $this->expectException(InfoParserException::class);
  $this->expectExceptionMessage("{$expected_exception_message} vfs://modules/fixtures/broken-duplicate.info.txt");
  $this->infoParser
    ->parse(vfsStream::url("modules/fixtures/broken-duplicate.info.txt"));
}

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