Skip to content

Commit 416c46a

Browse files
author
matheo
committed
make remove method immutable and test if attributes are still render
1 parent 66b7f58 commit 416c46a

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

src/TwigComponent/src/ComponentAttributes.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,12 @@ public function add($stimulusDto): self
149149
return $clone->defaults($controllersAttributes);
150150
}
151151

152-
public function remove($key): void
152+
public function remove($key): self
153153
{
154-
unset($this->attributes[$key]);
154+
$attributes = $this->attributes;
155+
156+
unset($attributes[$key]);
157+
158+
return new self($attributes);
155159
}
156160
}

src/TwigComponent/src/Twig/PropsNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function compile(Compiler $compiler): void
3131
foreach ($this->getAttribute('names') as $name) {
3232
$compiler
3333
->addDebugInfo($this)
34-
->write('$context[\'attributes\']->remove(\''.$name.'\');')
34+
->write('$context[\'attributes\'] = $context[\'attributes\']->remove(\''.$name.'\');')
3535
->write('if (!isset($context[\''.$name.'\'])) {')
3636
;
3737

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<twig:UserCard :user='user'/>
1+
<twig:UserCard :user='user' class='foo'/>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% props user %}
22

3-
<div {{ attributes }} class='user-card'>
3+
<div {{ attributes }}>
44
<p>{{ user.name }}</p>
55
<p>{{ user.email }}</p>
66
</div>

src/TwigComponent/tests/Integration/ComponentExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public function testRenderAnonymousComponentWithNonScalarProps(): void
189189

190190
$output = self::getContainer()->get(Environment::class)->render('anonymous_component_none_scalar_prop.html.twig', ['user' => $user]);
191191

192+
$this->assertStringContainsString('class="foo"', $output);
192193
$this->assertStringContainsString('Fabien', $output);
193194
$this->assertStringContainsString('test@test.com', $output);
194195
}

0 commit comments

Comments
 (0)