Passed
Pull Request — master (#164)
by Vincent
06:27
created

Goutte::getServer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Sanpi\Behatch\HttpCall\Request;
4
5
use Symfony\Component\HttpFoundation\File\UploadedFile;
6
7
class Goutte extends BrowserKit
8
{
9
    /**
10
     * headers are no more stored on client, because client does not flush them when reset/restart session.
11
     * They are on Behat\Mink\Driver\BrowserKitDriver and there is no way to get them.
12
     *
13
     * @var array
14
     */
15
    private $requestHeaders = [];
16
17
    public function send($method, $url, $parameters = [], $files = [], $content = null, $headers = [])
18
    {
19
        foreach ($files as $originalName => &$file) {
20
            $file = new UploadedFile($file, $originalName);
21
        }
22
        $page = parent::send($method, $url, $parameters, $files, $content, array_merge($headers, $this->requestHeaders));
23
24
        return $page;
25
    }
26
27
    public function setHttpHeader($name, $value)
28
    {
29
        $name = strtoupper("http_$name");
30
        $this->requestHeaders[$name] = $value;
31
    }
32
33
    protected function resetHttpHeaders()
34
    {
35
        $this->requestHeaders = [];
36
    }
37
}
38