Passed
Pull Request — master (#32)
by Baptiste
05:37
created

PhpMatcher::__construct()   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 1
1
<?php
2
namespace Behapi\Context;
3
4
use Behat\Behat\Context\Context;
5
use Behat\Gherkin\Node\PyStringNode;
6
7
use Behapi\Tools\HttpHistory;
8
9
class PhpMatcher implements Context
10
{
11
    use ApiTrait;
12
13
    public function __construct(HttpHistory $history)
14
    {
15
        $this->history = $history;
16
    }
17
18
    /** @Then the response content should match :pattern */
19
    public function response_content_should_match(string $pattern)
20
    {
21
        $content = (string) $this->getResponse()->getBody();
22
23
        if (!PHPMatcher::match($content, $pattern, $error)) {
0 ignored issues
show
Bug introduced by
The variable $error does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The method match() does not seem to exist on object<Behapi\Context\PhpMatcher>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
            throw new InvalidArgumentException(
25
                sprintf(
26
                    'The response does not match with the pattern "%s" (error : %s)',
27
                    $pattern,
28
                    $error
29
                )
30
            );
31
        }
32
    }
33
}
34