diff --git a/src/TwigComponent/doc/index.rst b/src/TwigComponent/doc/index.rst index 63fa6f53e63..cb465157ef9 100644 --- a/src/TwigComponent/doc/index.rst +++ b/src/TwigComponent/doc/index.rst @@ -948,7 +948,7 @@ You can test how your component is mounted and rendered using the public function testComponentMount(): void { $component = $this->mountTwigComponent( - name: 'MyComponent', + name: 'MyComponent', // can also use FQCN (MyComponent::class) data: ['foo' => 'bar'], ); @@ -959,7 +959,7 @@ You can test how your component is mounted and rendered using the public function testComponentRenders(): void { $rendered = $this->renderTwigComponent( - name: 'MyComponent', + name: 'MyComponent', // can also use FQCN (MyComponent::class) data: ['foo' => 'bar'], ); @@ -969,7 +969,7 @@ You can test how your component is mounted and rendered using the public function testEmbeddedComponentRenders(): void { $rendered = $this->renderTwigComponent( - name: 'MyComponent', + name: 'MyComponent', // can also use FQCN (MyComponent::class) data: ['foo' => 'bar'], content: '
My content
', // "content" (default) block blocks: [ diff --git a/src/TwigComponent/src/Test/InteractsWithTwigComponents.php b/src/TwigComponent/src/Test/InteractsWithTwigComponents.php index 687b35e9c7f..810e332c1fa 100644 --- a/src/TwigComponent/src/Test/InteractsWithTwigComponents.php +++ b/src/TwigComponent/src/Test/InteractsWithTwigComponents.php @@ -48,7 +48,7 @@ protected function renderTwigComponent(string $name, array $data = [], ?string $ ); } - $template = sprintf('{%% component %s with data %%}', $name); + $template = sprintf('{%% component "%s" with data %%}', addslashes($name)); foreach (array_keys($blocks) as $blockName) { $template .= sprintf('{%% block %1$s %%}{{ blocks.%1$s|raw }}{%% endblock %%}', $blockName); diff --git a/src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php b/src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php index ecd88918941..6ca156e0b15 100644 --- a/src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php +++ b/src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php @@ -14,15 +14,19 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\UX\TwigComponent\Test\InteractsWithTwigComponents; use Symfony\UX\TwigComponent\Tests\Fixtures\Component\ComponentA; +use Symfony\UX\TwigComponent\Tests\Fixtures\Component\WithSlots; use Symfony\UX\TwigComponent\Tests\Fixtures\Service\ServiceA; final class InteractsWithTwigComponentsTest extends KernelTestCase { use InteractsWithTwigComponents; - public function testCanMountComponent(): void + /** + * @dataProvider componentANameProvider + */ + public function testCanMountComponent(string $name): void { - $component = $this->mountTwigComponent('component_a', [ + $component = $this->mountTwigComponent($name, [ 'propA' => 'prop a value', 'propB' => 'prop b value', ]); @@ -33,9 +37,12 @@ public function testCanMountComponent(): void $this->assertSame('prop b value', $component->getPropB()); } - public function testCanRenderComponent(): void + /** + * @dataProvider componentANameProvider + */ + public function testCanRenderComponent(string $name): void { - $rendered = $this->renderTwigComponent('component_a', [ + $rendered = $this->renderTwigComponent($name, [ 'propA' => 'prop a value', 'propB' => 'prop b value', ]); @@ -45,10 +52,13 @@ public function testCanRenderComponent(): void $this->assertStringContainsString('service: service a value', $rendered); } - public function testCanRenderComponentWithSlots(): void + /** + * @dataProvider withSlotsNameProvider + */ + public function testCanRenderComponentWithSlots(string $name): void { $rendered = $this->renderTwigComponent( - name: 'WithSlots', + name: $name, content: '

some content

', blocks: [ 'slot1' => '

some slot1 content

', @@ -65,4 +75,16 @@ public function testCanRenderComponentWithSlots(): void $this->assertStringContainsString('propB: prop b value', $rendered); $this->assertStringContainsString('service: service a value', $rendered); } + + public static function componentANameProvider(): iterable + { + yield ['component_a']; + yield [ComponentA::class]; + } + + public static function withSlotsNameProvider(): iterable + { + yield ['WithSlots']; + yield [WithSlots::class]; + } }