3939use Symfony \Component \Console \Tester \CommandTester ;
4040use Symfony \Component \DependencyInjection \ParameterBag \ParameterBagInterface ;
4141use Symfony \Component \HttpFoundation \RequestStack ;
42+ use Symfony \Component \Serializer \SerializerInterface ;
4243use Symfony \Contracts \Translation \TranslatorInterface ;
4344use Twig \Environment ;
4445
4950 * @version 0.1.0 (2023-01-01)
5051 * @since 0.1.0 (2023-01-01) First version.
5152 * @SuppressWarnings(PHPMD.TooManyFields)
53+ * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
5254 */
5355abstract class BaseFunctionalCommandTest extends WebTestCase
5456{
@@ -69,6 +71,12 @@ abstract class BaseFunctionalCommandTest extends WebTestCase
6971 protected string $ parameterBagClass = ParameterBagInterface::class;
7072
7173
74+ protected SerializerInterface $ serializer ;
75+
76+ /** @var class-string<SerializerInterface> $serializerClass */
77+ protected string $ serializerClass = SerializerInterface::class;
78+
79+
7280 protected Entity $ entity ;
7381
7482 /** @var class-string<Entity> $entityClass */
@@ -113,6 +121,8 @@ abstract class BaseFunctionalCommandTest extends WebTestCase
113121
114122 protected bool $ useParameterBag = false ;
115123
124+ protected bool $ useSerializer = false ;
125+
116126 protected bool $ useTwig = false ;
117127
118128 protected bool $ useRequestStack = false ;
@@ -183,6 +193,17 @@ protected function setConfigUseParameterBag(): self
183193 return $ this ;
184194 }
185195
196+ /**
197+ * @return self
198+ */
199+ protected function setConfigUseSerializer (): self
200+ {
201+ $ this ->setConfigUseKernel ();
202+ $ this ->useSerializer = true ;
203+
204+ return $ this ;
205+ }
206+
186207 /**
187208 * @return self
188209 */
@@ -264,6 +285,10 @@ protected function setUp(): void
264285 $ this ->createService ($ this ->getServiceParameterBagClass ());
265286 }
266287
288+ if ($ this ->useSerializer ) {
289+ $ this ->createService ($ this ->getServiceSerializerClass ());
290+ }
291+
267292 if ($ this ->useDb ) {
268293 $ this ->createService ($ this ->getServiceEntityClass ());
269294 $ this ->createService ($ this ->getServiceRepositoryClass ());
@@ -310,6 +335,7 @@ protected function createService(string $serviceName): void
310335 $ service instanceof Entity => $ this ->entity = $ service ,
311336 $ service instanceof Environment => $ this ->twig = $ service ,
312337 $ service instanceof ParameterBagInterface => $ this ->parameterBag = $ service ,
338+ $ service instanceof SerializerInterface => $ this ->serializer = $ service ,
313339 $ service instanceof Repository => $ this ->repository = $ service ,
314340 $ service instanceof RequestStack => $ this ->request = $ service ,
315341 $ service instanceof TranslatorInterface => $ this ->translator = $ service ,
@@ -342,6 +368,25 @@ public function setServiceParameterBagClass(string $parameterBagClass): self
342368 return $ this ;
343369 }
344370
371+ /**
372+ * @return class-string<SerializerInterface>
373+ */
374+ public function getServiceSerializerClass (): string
375+ {
376+ return $ this ->serializerClass ;
377+ }
378+
379+ /**
380+ * @param class-string<SerializerInterface> $serializerClass
381+ * @return self
382+ */
383+ public function setServiceSerializerClass (string $ serializerClass ): self
384+ {
385+ $ this ->serializerClass = $ serializerClass ;
386+
387+ return $ this ;
388+ }
389+
345390 /**
346391 * @return class-string<Entity>
347392 */
0 commit comments