Completed
Push — master ( e5e74e...13adb5 )
by Yo
02:16
created

Client::hasRequestPerformed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Yoanm\Behat3SymfonyExtension\Client;
3
4
use Symfony\Bundle\FrameworkBundle\Client as BaseClient;
5
use Symfony\Component\BrowserKit\CookieJar;
6
use Symfony\Component\BrowserKit\History;
7
use Symfony\Component\HttpKernel\KernelInterface;
8
use Yoanm\Behat3SymfonyExtension\Handler\KernelHandler;
9
10
class Client extends BaseClient
11
{
12
    /** @var KernelHandler */
13
    private $kernelHandler;
14
    /** @var bool */
15
    private $requestPerformed = false;
16
17
    /**
18
     * @inheritDoc
19
     */
20
    public function __construct(
21
        KernelHandler $kernelHandler,
22
        KernelInterface $kernel,
23
        array $server,
24
        History $history,
25
        CookieJar $cookieJar
26
    ) {
27
        parent::__construct($kernel, $server, $history, $cookieJar);
28
        $this->kernelHandler = $kernelHandler;
29
        $this->disableReboot();
30
    }
31
32
    /**
33
     * @return boolean
34
     */
35
    public function hasRequestPerformed()
36
    {
37
        return $this->requestPerformed;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function doRequest($request)
44
    {
45
        if ($this->requestPerformed) {
46
            // Reboot sfKernel to avoid parent::doRequest to shutdown it and from Kernel::handle to boot it
47
            $this->kernelHandler->rebootSfKernel();
48
        } else {
49
            $this->requestPerformed = true;
50
        }
51
52
        return parent::doRequest($request);
53
    }
54
}
55