Completed
Pull Request — master (#16)
by Sergii
07:37
created

RawRedirectContext::getStatusCode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Drupal\TqExtension\Context\Redirect;
6
7
// Contexts.
8
use Drupal\TqExtension\Context\RawTqContext;
9
// Utils.
10
use Behat\Mink\Driver\GoutteDriver;
11
12
class RawRedirectContext extends RawTqContext
13
{
14
    /**
15
     * @param string $path
16
     *   An URL to visit (relative or absolute).
17
     *
18
     * @return int
19
     */
20
    public function getStatusCode($path)
21
    {
22
        // The "Goutte" session should be used because it provides HTTP status codes.
23
        // Visit path once again if current session driver is not Goutte.
24
        if (!($this->getSessionDriver() instanceof GoutteDriver)) {
25
            $this->visitPath($path, 'goutte');
26
        }
27
28
        $statusCode = (int) $this->getSession('goutte')->getStatusCode();
29
30
        self::debug(['HTTP status code: %s'], [$statusCode]);
31
32
        return $statusCode;
33
    }
34
}
35