-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #1041 Props tag remove props from the attribute list (matheo,…
… WebMamba) This PR was merged into the 2.x branch. Discussion ---------- Props tag remove props from the attribute list | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | none | License | MIT An assertion in ComponentFactory is blocking us to use non-scalar values for anonymous components. `@weaverryan` do you know why this check was made for? Commits ------- 6f693d6 Remove .idea 58fce65 remove .idea f6ac821 remove attributes from context 416c46a make remove method immutable and test if attributes are still render 66b7f58 remove props from the attribute in the PropsNode 2555d26 Revert "props tag remove props from attributes" a9d422e props tag remove props from attributes 2d9f300 Fix non scalar value to anonymous component
- Loading branch information
Showing
8 changed files
with
79 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Symfony\UX\TwigComponent\Tests\Fixtures; | ||
|
||
class User | ||
{ | ||
public function __construct( | ||
private readonly string $name, | ||
private readonly string $email, | ||
) {} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getEmail(): string | ||
{ | ||
return $this->email; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/TwigComponent/tests/Fixtures/templates/anonymous_component_none_scalar_prop.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<twig:UserCard :user='user' class='foo'/> |
7 changes: 7 additions & 0 deletions
7
src/TwigComponent/tests/Fixtures/templates/components/UserCard.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% props user %} | ||
|
||
<div {{ attributes }}> | ||
<p>{{ user.name }}</p> | ||
<p>{{ user.email }}</p> | ||
<p>class variable defined? {{ class is defined ? 'yes': 'no' }}</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\UX\TwigComponent\Tests\Integration; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\UX\TwigComponent\Tests\Fixtures\User; | ||
use Twig\Environment; | ||
|
||
/** | ||
|
@@ -182,6 +183,18 @@ public function testRenderAnonymousComponentInNestedDirectory(): void | |
$this->assertStringContainsString('class="primary"', $output); | ||
} | ||
|
||
public function testRenderAnonymousComponentWithNonScalarProps(): void | ||
{ | ||
$user = new User('Fabien', '[email protected]'); | ||
|
||
$output = self::getContainer()->get(Environment::class)->render('anonymous_component_none_scalar_prop.html.twig', ['user' => $user]); | ||
|
||
$this->assertStringContainsString('class="foo"', $output); | ||
$this->assertStringContainsString('Fabien', $output); | ||
$this->assertStringContainsString('[email protected]', $output); | ||
$this->assertStringContainsString('class variable defined? no', $output); | ||
} | ||
|
||
private function renderComponent(string $name, array $data = []): string | ||
{ | ||
return self::getContainer()->get(Environment::class)->render('render_component.html.twig', [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters