Skip to content

Commit

Permalink
Simplify module logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TavoNiievez committed Jun 19, 2024
1 parent 39293ea commit 800fd98
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 148 deletions.
35 changes: 9 additions & 26 deletions src/Codeception/Lib/Connector/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@
class Symfony extends HttpKernelBrowser
{
private bool $hasPerformedRequest = false;

private ?ContainerInterface $container;

/**
* Constructor.
*
* @param Kernel $kernel A booted HttpKernel instance
* @param array $persistentServices An injected services
*/
public function __construct(
Kernel $kernel,
public array $persistentServices = [],
Expand Down Expand Up @@ -74,14 +67,12 @@ public function rebootKernel(): void

$this->persistDoctrineConnections();
$this->kernel->reboot(null);

$this->container = $this->getContainer();

foreach ($this->persistentServices as $serviceName => $service) {
try {
$this->container->set($serviceName, $service);
} catch (InvalidArgumentException $e) {
//Private services can't be set in Symfony 4
codecept_debug("[Symfony] Can't set persistent service {$serviceName}: " . $e->getMessage());
}
}
Expand All @@ -95,31 +86,23 @@ private function getContainer(): ?ContainerInterface
{
/** @var ContainerInterface $container */
$container = $this->kernel->getContainer();
if ($container->has('test.service_container')) {
$container = $container->get('test.service_container');
}

return $container;
return $container->has('test.service_container')
? $container->get('test.service_container')
: $container;
}

private function getProfiler(): ?Profiler
{
if ($this->container->has('profiler')) {
/** @var Profiler $profiler */
$profiler = $this->container->get('profiler');
return $profiler;
}

return null;
return $this->container->has('profiler')
? $this->container->get('profiler')
: null;
}

private function getService(string $serviceName): ?object
{
if ($this->container->has($serviceName)) {
return $this->container->get($serviceName);
}

return null;
return $this->container->has($serviceName)
? $this->container->get($serviceName)
: null;
}

private function persistDoctrineConnections(): void
Expand Down
Loading

0 comments on commit 800fd98

Please sign in to comment.