public function TwigEnvironmentTest::testTemplateNotFoundException in Drupal 8
Same name and namespace in other branches
- 9 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 101 
Class
- TwigEnvironmentTest
- Tests the twig environment.
Namespace
Drupal\KernelTests\Core\ThemeCode
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 (\Twig_Error_Loader $e) {
    $this
      ->assertStringStartsWith('Template "this-template-does-not-exist.html.twig" is not defined', $e
      ->getMessage());
  }
}