Completed
Push — master ( 3ef0d0...50fc50 )
by Kamil
07:01
created

KernelRebooter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
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 transferBehatContainer() 0 6 1
A rebootSymfonyKernel() 0 5 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 KernelRebooter 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::AFTER => ['rebootSymfonyKernel', -15],
31
            ExampleTested::AFTER => ['rebootSymfonyKernel', -15],
32
            ScenarioTested::BEFORE => ['transferBehatContainer', 15],
33
            ExampleTested::BEFORE => ['transferBehatContainer', 15],
34
        ];
35
    }
36
37
    public function transferBehatContainer(): void
38
    {
39
        $symfonyContainer = $this->symfonyKernel->getContainer();
40
41
        $symfonyContainer->set('behat.service_container', $this->behatContainer);
42
    }
43
44
    public function rebootSymfonyKernel(): void
45
    {
46
        $this->symfonyKernel->shutdown();
47
        $this->symfonyKernel->boot();
48
    }
49
}
50