Skip to content

Commit

Permalink
rename props key and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
matheo committed Sep 28, 2023
1 parent 6c57a4e commit aeb54b3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/LiveComponent/phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="Symfony\UX\LiveComponent\Tests\Fixtures\Kernel" />
<server name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/data.db" />
<env name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0"/>
</php>

<testsuites>
<testsuite name="symfony/ux-live-component Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
2 changes: 1 addition & 1 deletion src/TwigComponent/src/ComponentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function preRender(MountedComponent $mounted, array $context = []): PreR
// add attributes
[$metadata->getAttributesVar() => $mounted->getAttributes()],
$props,
['props' => $props]
['__props' => $props]
);
$event = new PreRenderEvent($mounted, $metadata, $variables);

Expand Down
2 changes: 1 addition & 1 deletion src/TwigComponent/src/Twig/PropsNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function compile(Compiler $compiler): void
$compiler
->write('$propsNames[] = \''.$name.'\';')
->write('$context[\'attributes\'] = $context[\'attributes\']->remove(\''.$name.'\');')
->write('if (!isset($context[\'props\'][\''.$name.'\'])) {');
->write('if (!isset($context[\'__props\'][\''.$name.'\'])) {');

if (!$this->hasNode($name)) {
$compiler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% set message = 'bar' %}

<twig:Message>
<p>Hey!</p>
</twig:Message>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% props message = 'foo' %}

<p>{{ message }}</p>
{% block content %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ public function testRenderAnonymousComponentWithNonScalarProps(): void
$this->assertStringContainsString('class variable defined? no', $output);
}

public function testComponentPropsOverwriteContextValue(): void
{
$output = self::getContainer()->get(Environment::class)->render('anonymous_component_with_variable_already_in_context.html.twig');

$this->assertStringContainsString('<p>foo</p>', $output);
}

private function renderComponent(string $name, array $data = []): string
{
return self::getContainer()->get(Environment::class)->render('render_component.html.twig', [
Expand Down

0 comments on commit aeb54b3

Please sign in to comment.