22
33namespace Qossmic \TwigDocBundle \Tests \Functional \Service ;
44
5- use PHPUnit \Framework \Attributes \CoversNothing ;
5+ use PHPUnit \Framework \Attributes \CoversClass ;
66use PHPUnit \Framework \Attributes \DataProvider ;
7+ use PHPUnit \Framework \Attributes \UsesClass ;
8+ use Qossmic \TwigDocBundle \Component \ComponentItem ;
79use Qossmic \TwigDocBundle \Component \ComponentItemFactory ;
810use Qossmic \TwigDocBundle \Exception \InvalidComponentConfigurationException ;
11+ use Qossmic \TwigDocBundle \Service \CategoryService ;
912use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
1013use TypeError ;
1114
12- #[CoversNothing]
15+ #[CoversClass(ComponentItemFactory::class)]
16+ #[UsesClass(CategoryService::class)]
1317class ComponentItemFactoryTest extends KernelTestCase
1418{
1519 #[DataProvider('getInvalidComponentConfigurationTestCases ' )]
@@ -25,6 +29,83 @@ public function testInvalidComponentConfiguration(array $componentData, string $
2529 $ service ->create ($ componentData );
2630 }
2731
32+ public function testComponentWithoutParameters (): void
33+ {
34+ $ data = [
35+ 'name ' => 'TestComponent ' ,
36+ 'title ' => 'Test title ' ,
37+ 'description ' => 'description ' ,
38+ 'category ' => 'MainCategory ' ,
39+ ];
40+
41+ /** @var ComponentItemFactory $factory */
42+ $ factory = self ::getContainer ()->get ('twig_doc.service.component_factory ' );
43+
44+ $ component = $ factory ->create ($ data );
45+
46+ self ::assertInstanceOf (ComponentItem::class, $ component );
47+ }
48+
49+ public function testFactoryCreatesDefaultVariationWhenMissingInConfig (): void
50+ {
51+ $ data = [
52+ 'name ' => 'TestComponent ' ,
53+ 'title ' => 'Test title ' ,
54+ 'description ' => 'description ' ,
55+ 'category ' => 'MainCategory ' ,
56+ ];
57+
58+ /** @var ComponentItemFactory $factory */
59+ $ factory = self ::getContainer ()->get ('twig_doc.service.component_factory ' );
60+
61+ $ component = $ factory ->create ($ data );
62+
63+ self ::assertArrayHasKey ('default ' , $ component ->getVariations ());
64+ }
65+
66+ public function testFactoryCreatesDefaultVariationWithParameterTypes (): void
67+ {
68+ $ data = [
69+ 'name ' => 'TestComponent ' ,
70+ 'title ' => 'Test title ' ,
71+ 'description ' => 'description ' ,
72+ 'category ' => 'MainCategory ' ,
73+ 'parameters ' => [
74+ 'string ' => 'String ' ,
75+ 'float ' => 'Float ' ,
76+ 'double ' => 'Double ' ,
77+ 'int ' => 'Int ' ,
78+ 'integer ' => 'Integer ' ,
79+ 'bool ' => 'Bool ' ,
80+ 'boolean ' => 'Boolean ' ,
81+ 'unknown ' => 'CustomType ' ,
82+ 'complex ' => [
83+ 'title ' => 'String ' ,
84+ 'amount ' => 'Float ' ,
85+ ]
86+ ]
87+ ];
88+
89+ /** @var ComponentItemFactory $factory */
90+ $ factory = self ::getContainer ()->get ('twig_doc.service.component_factory ' );
91+
92+ $ component = $ factory ->create ($ data );
93+
94+ self ::assertInstanceOf (ComponentItem::class, $ component );
95+ self ::assertIsBool ($ component ->getVariations ()['default ' ]['bool ' ]);
96+ self ::assertIsBool ($ component ->getVariations ()['default ' ]['boolean ' ]);
97+ self ::assertIsString ($ component ->getVariations ()['default ' ]['string ' ]);
98+ self ::assertIsInt ($ component ->getVariations ()['default ' ]['int ' ]);
99+ self ::assertIsInt ($ component ->getVariations ()['default ' ]['integer ' ]);
100+ self ::assertIsFloat ($ component ->getVariations ()['default ' ]['float ' ]);
101+ self ::assertIsFloat ($ component ->getVariations ()['default ' ]['double ' ]);
102+ self ::assertNull ($ component ->getVariations ()['default ' ]['unknown ' ]);
103+
104+ self ::assertIsArray ($ component ->getVariations ()['default ' ]['complex ' ]);
105+ self ::assertIsString ($ component ->getVariations ()['default ' ]['complex ' ]['title ' ]);
106+ self ::assertIsFloat ($ component ->getVariations ()['default ' ]['complex ' ]['amount ' ]);
107+ }
108+
28109 public static function getInvalidComponentConfigurationTestCases (): iterable
29110 {
30111 yield [
0 commit comments