Skip to content

Commit 3bf4671

Browse files
committed
Add SerializerInterface to BaseFunctionalCommandTest.php
1 parent fe70e35 commit 3bf4671

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/Functional/Command/Base/BaseFunctionalCommandTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use Symfony\Component\Console\Tester\CommandTester;
4040
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
4141
use Symfony\Component\HttpFoundation\RequestStack;
42+
use Symfony\Component\Serializer\SerializerInterface;
4243
use Symfony\Contracts\Translation\TranslatorInterface;
4344
use Twig\Environment;
4445

@@ -49,6 +50,7 @@
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
*/
5355
abstract 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

Comments
 (0)