Passed
Branch develop (2eaa9a)
by Daniel
05:29
created

FeatureContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 4
1
<?php
2
3
use Behat\Behat\Context\Context;
4
use Behat\Behat\Hook\Scope\AfterStepScope;
5
use Behatch\HttpCall\Request;
6
7
/**
8
 * Defines application features from the specific context.
9
 */
10
class FeatureContext implements Context
11
{
12
    /**
13
     * @var Request\BrowserKit
14
     */
15
    private $request;
16
17
    /**
18
     * Initializes context.
19
     *
20
     * Every scenario gets its own context instance.
21
     * You can also pass arbitrary arguments to the
22
     * context constructor through behat.yml.
23
     * @param Request $request
24
     */
25
    public function __construct(Request $request)
26
    {
27
        $this->request = $request;
28
    }
29
30
    /**
31
     * Sets the default Accept HTTP header to null (workaround to artificially remove it).
32
     * @AfterStep
33
     * @param AfterStepScope $event
34
     */
35
    public function removeAcceptHeaderAfterRequest(AfterStepScope $event)
36
    {
37
        if (preg_match('/^I send a "[A-Z]+" request to ".+"/', $event->getStep()->getText())) {
38
            $this->request->setHttpHeader('Accept', null);
39
        }
40
    }
41
42
    /**
43
     * Sets the default Accept HTTP header to null (workaround to artificially remove it).
44
     *
45
     * @BeforeScenario
46
     */
47
    public function removeAcceptHeaderBeforeScenario()
48
    {
49
        $this->request->setHttpHeader('Accept', null);
50
    }
51
}
52