Completed
Push — master ( 37a280...0c4ce1 )
by Yo
02:09
created

Client::hasPerformedRequest()   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
9
class Client extends BaseClient
10
{
11
    /** @var bool */
12
    private $requestPerformed = false;
13
14
    /**
15
     * @inheritDoc
16
     */
17
    public function __construct(
18
        KernelInterface $kernel,
19
        array $server,
20
        History $history,
21
        CookieJar $cookieJar
22
    ) {
23
        parent::__construct($kernel, $server, $history, $cookieJar);
24
        $this->disableReboot();
25
    }
26
27
    /**
28
     * @return boolean
29
     */
30
    public function hasPerformedRequest()
31
    {
32
        return $this->requestPerformed;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function doRequest($request)
39
    {
40
        if ($this->requestPerformed) {
41
            // Reboot sfKernel to avoid parent::doRequest to shutdown it and from Kernel::handle to boot it
42
            // This behavior will allow mocking symfony app container service for instance
43
            $this->getKernel()->shutdown();
44
            $this->getKernel()->boot();
45
        } else {
46
            $this->requestPerformed = true;
47
        }
48
49
        return parent::doRequest($request);
50
    }
51
}
52