mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-29 07:05:50 +00:00
Deduplicate template error handling
This commit is contained in:
@@ -36,6 +36,7 @@ use Twig\Node\Node;
|
||||
use Twig\Source;
|
||||
use Twig\Token;
|
||||
use Twig\TokenParser\AbstractTokenParser;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class ErrorTest extends TestCase
|
||||
{
|
||||
@@ -47,6 +48,24 @@ class ErrorTest extends TestCase
|
||||
$this->assertStringContainsString('tests'.\DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage());
|
||||
}
|
||||
|
||||
public function testTwigErrorIsEnrichedWithoutBeingWrapped(): void
|
||||
{
|
||||
$twig = new Environment(new ArrayLoader(['index' => "foo\n{{ fail() }}"]), ['debug' => true, 'cache' => false]);
|
||||
$error = null;
|
||||
$twig->addFunction(new TwigFunction('fail', static function () use (&$error): never {
|
||||
throw $error = new RuntimeError('Runtime error.');
|
||||
}));
|
||||
|
||||
try {
|
||||
$twig->render('index');
|
||||
$this->fail();
|
||||
} catch (RuntimeError $e) {
|
||||
$this->assertSame($error, $e);
|
||||
$this->assertSame(2, $e->getTemplateLine());
|
||||
$this->assertSame('index', $e->getSourceContext()->getName());
|
||||
}
|
||||
}
|
||||
|
||||
public function testTwigExceptionGuessWithMissingVarAndArrayLoader(): void
|
||||
{
|
||||
$loader = new ArrayLoader([
|
||||
|
||||
Reference in New Issue
Block a user