Skip to content

Commit 0fa12a5

Browse files
author
matheo
committed
make remove method immutable and test if attributes are still render
1 parent 7afeae9 commit 0fa12a5

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
@@ -151,8 +151,12 @@ public function add($stimulusDto): self
151151
return $clone->defaults($controllersAttributes);
152152
}
153153

154-
public function remove($key): void
154+
public function remove($key): self
155155
{
156-
unset($this->attributes[$key]);
156+
$attributes = $this->attributes;
157+
158+
unset($attributes[$key]);
159+
160+
return new self($attributes);
157161
}
158162
}

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('[email protected]', $output);
194195
}

0 commit comments

Comments
 (0)