public function TwigEnvironmentTest::testTemplateNotFoundException in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php \Drupal\KernelTests\Core\Theme\TwigEnvironmentTest::testTemplateNotFoundException()
- 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 103
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
->load('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());
}
}