Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/TwigComponent/src/Test/InteractsWithTwigComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ protected function renderTwigComponent(string $name, array $data = [], ?string $

$template = \sprintf('{%% component "%s" with data %%}', addslashes($name));

foreach (array_keys($blocks) as $blockName) {
$template .= \sprintf('{%% block %1$s %%}{{ blocks.%1$s|raw }}{%% endblock %%}', $blockName);
foreach ($blocks as $blockName => $blockContent) {
$template .= \sprintf('{%% block %1$s %%}%2$s{%% endblock %%}', $blockName, $blockContent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good idea to change implementation here.

This will create a new template everytime, risking that two successive calls for the same component end up with different cache files. (what would be the case elsewhen, and something TwigComponent or LiveComponent sometimes uses).

But also because it does change the way it words. Current is runtime block-rendering, when your suggestion is changing that into a pre-compiled static template.

I can understand your desire to make things work the way you'd like, but for the vast majority of users out there, this change will not bring new or value, but would change the way their tests are done...

What about adding new methods in the trait.. could be specialized in testing/working with Components?
What do you feel about looking at what can be done here and how?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So i'm 👎 this one

}

$template .= '{% endcomponent %}';
Expand All @@ -62,7 +62,6 @@ protected function renderTwigComponent(string $name, array $data = [], ?string $
->createTemplate($template)
->render([
'data' => $data,
'blocks' => $blocks,
])
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\UX\TwigComponent\Tests\Fixtures\Component;

use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
#[AsTwigComponent]
final class WithSlotsAndLimitedScope
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
{% with { outerScope } only %}
{% block content %}{% endblock %}
{% block slot1 %}{% endblock %}
{% block slot2 %}{% endblock %}
{% endwith %}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function testCannotGetConfigByNameForNonRegisteredComponent()
* @testWith ["tabl", "Unknown component \"tabl\". Did you mean this: \"table\"?"]
* ["Basic", "Unknown component \"Basic\". Did you mean this: \"BasicComponent\"?"]
* ["basic", "Unknown component \"basic\". Did you mean this: \"BasicComponent\"?"]
* ["with", "Unknown component \"with\". Did you mean one of these: \"with_attributes\", \"with_exposed_variables\", \"WithSlots\"?"]
* ["with", "Unknown component \"with\". Did you mean one of these: \"with_attributes\", \"with_exposed_variables\", \"WithSlots\", \"WithSlotsAndLimitedScope\"?"]
* ["anonAnon", "Unknown component \"anonAnon\". And no matching anonymous component template was found."]
*/
public function testCannotGetInvalidComponent(string $name, string $expectedExceptionMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\UX\TwigComponent\Test\InteractsWithTwigComponents;
use Symfony\UX\TwigComponent\Tests\Fixtures\Component\ComponentA;
use Symfony\UX\TwigComponent\Tests\Fixtures\Component\WithSlots;
use Symfony\UX\TwigComponent\Tests\Fixtures\Component\WithSlotsAndLimitedScope;
use Symfony\UX\TwigComponent\Tests\Fixtures\Service\ServiceA;

final class InteractsWithTwigComponentsTest extends KernelTestCase
Expand Down Expand Up @@ -87,5 +88,7 @@ public static function withSlotsNameProvider(): iterable
{
yield ['WithSlots'];
yield [WithSlots::class];
yield ['WithSlotsAndLimitedScope'];
yield [WithSlotsAndLimitedScope::class];
}
}
Loading