RebootKernelSubscriber::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
namespace Yoanm\Behat3SymfonyExtension\Subscriber;
3
4
use Behat\Behat\EventDispatcher\Event\ExampleTested;
5
use Behat\Behat\EventDispatcher\Event\ScenarioTested;
6
use Psr\Log\LoggerInterface;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
use Yoanm\Behat3SymfonyExtension\Client\Client;
9
use Yoanm\BehatUtilsExtension\Subscriber\ListenerPriority;
10
11
/**
12
 * Class RebootKernelSubscriber
13
 */
14
class RebootKernelSubscriber implements EventSubscriberInterface
15
{
16
    /** @var Client */
17
    private $client;
18
    /** @var LoggerInterface|null */
19
    private $logger;
20
    /** @var bool */
21
    private $debugMode;
22
23
    /**
24
     *
25
     * @param Client          $client
26
     * @param LoggerInterface $logger
27
     * @param bool            $debugMode
28
     */
29 2
    public function __construct(
30
        Client $client,
31
        LoggerInterface $logger = null,
32
        $debugMode = false
33
    ) {
34 2
        $this->client = $client;
35 2
        $this->logger = $logger;
36 2
        $this->debugMode = $debugMode;
37 2
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 1
    public static function getSubscribedEvents()
43
    {
44
        //Register with the highest priority to reset the client (and so the kernel) before all others things
45
        return [
46 1
            ScenarioTested::BEFORE => ['reset', ListenerPriority::HIGH_PRIORITY],
47 1
            ExampleTested::BEFORE => ['reset', ListenerPriority::HIGH_PRIORITY],
48 1
        ];
49
    }
50
51 1
    public function reset()
52
    {
53
        // Resetting the client will also reboot the kernel
54 1
        if (true === $this->debugMode) {
55 1
            $this->logger->debug('Resetting mink driver client');
56 1
        }
57 1
        $this->client->resetClient();
58 1
    }
59
}
60