Merge branch '3.x' into 4.x

* 3.x:
  Clarify the exception message for nested block chains from another environment
  Report a clear error when using macros imported in a template body that was not rendered

# Conflicts:
#	CHANGELOG
#	src/Template.php
#	tests/CallMacroTest.php
This commit is contained in:
Fabien Potencier
2026-09-14 14:07:14 +02:00
5 changed files with 52 additions and 5 deletions
+3 -2
View File
@@ -296,7 +296,7 @@ class BlockChainTest extends TestCase
$other = new Environment(new ArrayLoader(['theme' => '']));
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('A block chain cannot contain templates from different Twig environments.');
$this->expectExceptionMessage('A block chain cannot contain a block chain from a different Twig environment.');
new BlockChain($twig, [new BlockChain($other, ['theme'])]);
}
@@ -519,7 +519,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']));