From 1b6f89dc0d192689f5332d271f1c354ff7f14e34 Mon Sep 17 00:00:00 2001 From: sneakyvv Date: Tue, 20 Jun 2023 11:50:06 +0200 Subject: [PATCH] Fix initial root hierarchy creation --- src/TwigComponent/src/ComponentRenderer.php | 4 ++-- src/TwigComponent/tests/Integration/EmbeddedComponentTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TwigComponent/src/ComponentRenderer.php b/src/TwigComponent/src/ComponentRenderer.php index 0064555f11d..e47cfe319fe 100644 --- a/src/TwigComponent/src/ComponentRenderer.php +++ b/src/TwigComponent/src/ComponentRenderer.php @@ -117,8 +117,8 @@ private function preRender(MountedComponent $mounted, array $context = []): PreR $component = $mounted->getComponent(); // add the "parent" component when rendering a nested embedded component - if (isset($context[PreRenderEvent::EMBEDDED]) && true === $context[PreRenderEvent::EMBEDDED]) { - $hierarchy = isset($context['this']) && $context['this'] instanceof Hierarchy ? $context['this'] : new Hierarchy($component); + if (isset($context[PreRenderEvent::EMBEDDED]) && true === $context[PreRenderEvent::EMBEDDED] && isset($context['this'])) { + $hierarchy = $context['this'] instanceof Hierarchy ? $context['this'] : new Hierarchy($context['this']); if (isset($context['this'])) { $hierarchy = $hierarchy->add($component); } diff --git a/src/TwigComponent/tests/Integration/EmbeddedComponentTest.php b/src/TwigComponent/tests/Integration/EmbeddedComponentTest.php index d0d5dbed74f..77b600e17e0 100644 --- a/src/TwigComponent/tests/Integration/EmbeddedComponentTest.php +++ b/src/TwigComponent/tests/Integration/EmbeddedComponentTest.php @@ -150,9 +150,9 @@ public function testBlockDefinitionCanAccessTheContextOfTheDestinationBlocks(): ); } - public function testAccessingTheHierarchyToHighThrowsAnException(): void + public function testAccessingTheHierarchyTooHighThrowsAnException(): void { - $this->expectExceptionMessage('Impossible to access an attribute ("foo") on a null variable'); + $this->expectExceptionMessage('Neither the property "parent" nor one of the methods "parent()", "getparent()"/"isparent()"/"hasparent()" or "__call()" exist'); self::getContainer()->get(Environment::class)->render('embedded_component_hierarchy_exception.html.twig'); }