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
|
|
|
|