You are here

public function TwigEnvironmentTest::testTemplateNotFoundException in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php \Drupal\KernelTests\Core\Theme\TwigEnvironmentTest::testTemplateNotFoundException()

Tests that exceptions are thrown when a template is not found.

File

core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php, line 103

Class

TwigEnvironmentTest
Tests the twig environment.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testTemplateNotFoundException() {

  /** @var \Drupal\Core\Template\TwigEnvironment $environment */
  $environment = \Drupal::service('twig');
  try {
    $environment
      ->loadTemplate('this-template-does-not-exist.html.twig')
      ->render([]);
    $this
      ->fail('Did not throw an exception as expected.');
  } catch (LoaderError $e) {
    $this
      ->assertStringStartsWith('Template "this-template-does-not-exist.html.twig" is not defined', $e
      ->getMessage());
  }
}