Code Duplication    Length = 11-16 lines in 3 locations

src/Context/JsonMatcher.php 1 location

@@ 27-42 (lines=16) @@
24
    }
25
26
    /** @Then the root should match: */
27
    public function root_should_match(PyStringNode $pattern)
28
    {
29
        $matcher = $this->factory->createMatcher();
30
        $body = (string) $this->getResponse()->getBody();
31
32
        if ($matcher->match($body, $pattern->getRaw())) {
33
            return;
34
        }
35
36
        throw new InvalidArgumentException(
37
            sprintf(
38
                'The json root does not match with the given pattern (error : %s)',
39
                $matcher->getError()
40
            )
41
        );
42
    }
43
44
    /** @Then in the json, :path should match: */
45
    public function path_should_match(string $path, PyStringNode $pattern)

src/Context/PhpMatcher.php 2 locations

@@ 28-38 (lines=11) @@
25
    }
26
27
    /** @Then the response content should match: */
28
    public function response_content_should_match(PyStringNode $pattern)
29
    {
30
        $matcher = $this->factory->createMatcher();
31
        $content = (string) $this->getResponse()->getBody();
32
33
        if ($matcher->match($content, $pattern->getRaw())) {
34
            return;
35
        }
36
37
        throw new InvalidArgumentException($matcher->getError());
38
    }
39
40
    /** @Then the response content should match: */
41
    public function response_content_should_not_match(PyStringNode $pattern)
@@ 41-54 (lines=14) @@
38
    }
39
40
    /** @Then the response content should match: */
41
    public function response_content_should_not_match(PyStringNode $pattern)
42
    {
43
        $matcher = $this->factory->createMatcher();
44
        $content = (string) $this->getResponse()->getBody();
45
46
        if (!$matcher->match($content, $pattern->getRaw())) {
47
            return;
48
        }
49
50
        throw new InvalidArgumentException(sprintf(
51
            'The response matches with the pattern "%s"',
52
            $pattern->getRaw()
53
        ));
54
    }
55
}
56