Passed
Pull Request — master (#32)
by Baptiste
04:34
created

PhpMatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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 Coduo\PHPMatcher\Factory\SimpleFactory;
8
9
use Behapi\Tools\HttpHistory;
10
11
class PhpMatcher implements Context
12
{
13
    use ApiTrait;
14
15
    /** @var Factory */
16
    private $factory;
17
18
    public function __construct(HttpHistory $history)
19
    {
20
        $this->history = $history;
21
22
        $this->factory = new SimpleFactory;
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Coduo\PHPMatcher\Factory\SimpleFactory() of type object<Coduo\PHPMatcher\Factory\SimpleFactory> is incompatible with the declared type object<Behapi\Context\Factory> of property $factory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
    }
24
25
    /** @Then the response content should match :pattern */
26
    public function response_content_should_match(string $pattern)
27
    {
28
        $matcher = $this->factory->createMatcher();
29
        $content = (string) $this->getResponse()->getBody();
30
31
        if ($matcher->match($content, $pattern)) {
32
            return;
33
        }
34
35
        throw new InvalidArgumentException(
36
            sprintf(
37
                'The response does not match with the pattern "%s" (error : %s)',
38
                $pattern,
39
                $matcher->getError()
40
            )
41
        );
42
    }
43
}
44