Skip to content

Commit aeb54b3

Browse files
author
matheo
committed
rename props key and add a test
1 parent 6c57a4e commit aeb54b3

File tree

6 files changed

+53
-2
lines changed

6 files changed

+53
-2
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
failOnRisky="true"
9+
failOnWarning="true"
10+
>
11+
<php>
12+
<ini name="error_reporting" value="-1" />
13+
<server name="KERNEL_CLASS" value="Symfony\UX\LiveComponent\Tests\Fixtures\Kernel" />
14+
<server name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/data.db" />
15+
<env name="SHELL_VERBOSITY" value="-1"/>
16+
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0"/>
17+
</php>
18+
19+
<testsuites>
20+
<testsuite name="symfony/ux-live-component Test Suite">
21+
<directory>./tests/</directory>
22+
</testsuite>
23+
</testsuites>
24+
25+
<filter>
26+
<whitelist processUncoveredFilesFromWhitelist="true">
27+
<directory suffix=".php">./src</directory>
28+
</whitelist>
29+
</filter>
30+
31+
<listeners>
32+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
33+
</listeners>
34+
</phpunit>

src/TwigComponent/src/ComponentRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private function preRender(MountedComponent $mounted, array $context = []): PreR
135135
// add attributes
136136
[$metadata->getAttributesVar() => $mounted->getAttributes()],
137137
$props,
138-
['props' => $props]
138+
['__props' => $props]
139139
);
140140
$event = new PreRenderEvent($mounted, $metadata, $variables);
141141

src/TwigComponent/src/Twig/PropsNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function compile(Compiler $compiler): void
3737
$compiler
3838
->write('$propsNames[] = \''.$name.'\';')
3939
->write('$context[\'attributes\'] = $context[\'attributes\']->remove(\''.$name.'\');')
40-
->write('if (!isset($context[\'props\'][\''.$name.'\'])) {');
40+
->write('if (!isset($context[\'__props\'][\''.$name.'\'])) {');
4141

4242
if (!$this->hasNode($name)) {
4343
$compiler
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% set message = 'bar' %}
2+
3+
<twig:Message>
4+
<p>Hey!</p>
5+
</twig:Message>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% props message = 'foo' %}
2+
3+
<p>{{ message }}</p>
4+
{% block content %}
5+
{% endblock %}

src/TwigComponent/tests/Integration/ComponentExtensionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ public function testRenderAnonymousComponentWithNonScalarProps(): void
195195
$this->assertStringContainsString('class variable defined? no', $output);
196196
}
197197

198+
public function testComponentPropsOverwriteContextValue(): void
199+
{
200+
$output = self::getContainer()->get(Environment::class)->render('anonymous_component_with_variable_already_in_context.html.twig');
201+
202+
$this->assertStringContainsString('<p>foo</p>', $output);
203+
}
204+
198205
private function renderComponent(string $name, array $data = []): string
199206
{
200207
return self::getContainer()->get(Environment::class)->render('render_component.html.twig', [

0 commit comments

Comments
 (0)