Report a clear error when using macros imported in a template body that was not rendered

This commit is contained in:
Fabien Potencier
2026-09-12 12:17:17 +02:00
parent a414c3a491
commit 72c2f669bd
5 changed files with 51 additions and 3 deletions
+2 -1
View File
@@ -480,7 +480,8 @@ class BlockChainTest extends TestCase
try {
$chain->renderBlock('field', ['helper' => 'macros1']);
$this->fail('Rendering an uninitialized import must fail.');
} catch (RuntimeError) {
} catch (RuntimeError $e) {
$this->assertStringContainsString('Macros imported in the body of template "theme" are not available because the body was not rendered', $e->getMessage());
}
$this->assertSame('one', $twig->render('theme', ['helper' => 'macros1']));