KernelOrchestrator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSubscribedEvents() 0 9 1
A setUp() 0 5 1
A tearDown() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FriendsOfBehat\SymfonyExtension\Listener;
6
7
use Behat\Behat\EventDispatcher\Event\ExampleTested;
8
use Behat\Behat\EventDispatcher\Event\ScenarioTested;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
use Symfony\Component\HttpKernel\KernelInterface;
12
13
final class KernelOrchestrator implements EventSubscriberInterface
14
{
15
    /** @var KernelInterface */
16
    private $symfonyKernel;
17
18
    /** @var ContainerInterface */
19
    private $behatContainer;
20
21
    public function __construct(KernelInterface $symfonyKernel, ContainerInterface $behatContainer)
22
    {
23
        $this->symfonyKernel = $symfonyKernel;
24
        $this->behatContainer = $behatContainer;
25
    }
26
27
    public static function getSubscribedEvents(): array
28
    {
29
        return [
30
            ScenarioTested::BEFORE => ['setUp', 15],
31
            ExampleTested::BEFORE => ['setUp', 15],
32
            ScenarioTested::AFTER => ['tearDown', -15],
33
            ExampleTested::AFTER => ['tearDown', -15],
34
        ];
35
    }
36
37
    public function setUp(): void
38
    {
39
        /** @psalm-suppress InvalidArgument Psalm complains that ContainerInterface does not match object|null */
40
        $this->symfonyKernel->getContainer()->set('behat.service_container', $this->behatContainer);
41
    }
42
43
    public function tearDown(): void
44
    {
45
        $this->symfonyKernel->getContainer()->set('behat.service_container', null);
46
        $this->symfonyKernel->shutdown();
47
        $this->symfonyKernel->boot();
48
    }
49
}
50