14
14
use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
15
15
use Symfony \UX \TwigComponent \Test \InteractsWithTwigComponents ;
16
16
use Symfony \UX \TwigComponent \Tests \Fixtures \Component \ComponentA ;
17
+ use Symfony \UX \TwigComponent \Tests \Fixtures \Component \WithSlots ;
17
18
use Symfony \UX \TwigComponent \Tests \Fixtures \Service \ServiceA ;
18
19
19
20
final class InteractsWithTwigComponentsTest extends KernelTestCase
20
21
{
21
22
use InteractsWithTwigComponents;
22
23
23
- public function testCanMountComponent (): void
24
+ /**
25
+ * @dataProvider componentANameProvider
26
+ */
27
+ public function testCanMountComponent (string $ name ): void
24
28
{
25
- $ component = $ this ->mountTwigComponent (' component_a ' , [
29
+ $ component = $ this ->mountTwigComponent ($ name , [
26
30
'propA ' => 'prop a value ' ,
27
31
'propB ' => 'prop b value ' ,
28
32
]);
@@ -33,9 +37,12 @@ public function testCanMountComponent(): void
33
37
$ this ->assertSame ('prop b value ' , $ component ->getPropB ());
34
38
}
35
39
36
- public function testCanRenderComponent (): void
40
+ /**
41
+ * @dataProvider componentANameProvider
42
+ */
43
+ public function testCanRenderComponent (string $ name ): void
37
44
{
38
- $ rendered = $ this ->renderTwigComponent (' component_a ' , [
45
+ $ rendered = $ this ->renderTwigComponent ($ name , [
39
46
'propA ' => 'prop a value ' ,
40
47
'propB ' => 'prop b value ' ,
41
48
]);
@@ -45,10 +52,13 @@ public function testCanRenderComponent(): void
45
52
$ this ->assertStringContainsString ('service: service a value ' , $ rendered );
46
53
}
47
54
48
- public function testCanRenderComponentWithSlots (): void
55
+ /**
56
+ * @dataProvider withSlotsNameProvider
57
+ */
58
+ public function testCanRenderComponentWithSlots (string $ name ): void
49
59
{
50
60
$ rendered = $ this ->renderTwigComponent (
51
- name: ' WithSlots ' ,
61
+ name: $ name ,
52
62
content: '<p>some content</p> ' ,
53
63
blocks: [
54
64
'slot1 ' => '<p>some slot1 content</p> ' ,
@@ -65,4 +75,16 @@ public function testCanRenderComponentWithSlots(): void
65
75
$ this ->assertStringContainsString ('propB: prop b value ' , $ rendered );
66
76
$ this ->assertStringContainsString ('service: service a value ' , $ rendered );
67
77
}
78
+
79
+ public static function componentANameProvider (): iterable
80
+ {
81
+ yield ['component_a ' ];
82
+ yield [ComponentA::class];
83
+ }
84
+
85
+ public static function withSlotsNameProvider (): iterable
86
+ {
87
+ yield ['WithSlots ' ];
88
+ yield [WithSlots::class];
89
+ }
68
90
}
0 commit comments