Passed
Push — master ( 1e0132...9b86f1 )
by Baptiste
02:58
created

ResponseContext   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 4
dl 0
loc 96
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A status_code_should_be() 0 5 1
A status_code_should_not_be() 0 5 1
A content_type_should_be() 0 5 1
A header_should_be() 0 5 1
A header_should_contain() 0 5 1
A response_should_have_header() 0 5 1
A response_should_have_sent_some_data() 0 7 1
A response_should_not_have_any_data() 0 5 1
A response_should_contain() 0 5 1
A response_should_not_contain() 0 5 1
A response_should_be() 0 5 1
A response_should_not_be() 0 5 1
1
<?php declare(strict_types=1);
2
namespace Behapi\Http;
3
4
use RuntimeException;
5
6
use Behat\Behat\Context\Context;
7
8
use Webmozart\Assert\Assert;
9
10
use Behapi\HttpHistory\History as HttpHistory;
11
12
final class ResponseContext implements Context
13
{
14
    use Response;
15
16
    public function __construct(HttpHistory $history)
17
    {
18
        $this->history = $history;
19
    }
20
21
    /** @Then the status code should be :expected */
22
    public function status_code_should_be(int $expected): void
23
    {
24
        $response = $this->getResponse();
25
        Assert::same((int) $response->getStatusCode(), $expected);
26
    }
27
28
    /** @Then the status code should not be :expected */
29
    public function status_code_should_not_be(int $expected): void
30
    {
31
        $response = $this->getResponse();
32
        Assert::notSame((int) $response->getStatusCode(), $expected);
33
    }
34
35
    /** @Then the content-type should be equal to :expected */
36
    public function content_type_should_be(string $expected): void
37
    {
38
        $response = $this->getResponse();
39
        Assert::same($response->getHeaderLine('Content-type'), $expected);
40
    }
41
42
    /** @Then the response header :header should be equal to :expected */
43
    public function header_should_be(string $header, string $expected): void
44
    {
45
        $response = $this->getResponse();
46
        Assert::same($response->getHeaderLine($header), $expected);
47
    }
48
49
    /** @Then the response header :header should contain :expected */
50
    public function header_should_contain(string $header, string $expected): void
51
    {
52
        $response = $this->getResponse();
53
        Assert::contains((string) $response->getHeaderLine($header), $expected);
54
    }
55
56
    /** @Then the response should have a header :header */
57
    public function response_should_have_header(string $header): void
58
    {
59
        $response = $this->getResponse();
60
        Assert::true($response->hasHeader($header));
61
    }
62
63
    /** @Then the response should have sent some data */
64
    public function response_should_have_sent_some_data(): void
65
    {
66
        $body = $this->getResponse()->getBody();
67
68
        Assert::notNull($body->getSize());
69
        Assert::greaterThan($body->getSize(), 0);
70
    }
71
72
    /** @Then the response should not have sent any data */
73
    public function response_should_not_have_any_data(): void
74
    {
75
        $body = $this->getResponse()->getBody();
76
        Assert::nullOrSame($body->getSize(), 0);
77
    }
78
79
    /** @Then the response should contain :data */
80
    public function response_should_contain(string $data): void
81
    {
82
        $response = $this->getResponse();
83
        Assert::contains((string) $response->getBody(), $data);
84
    }
85
86
    /** @Then the response should not contain :data */
87
    public function response_should_not_contain(string $data): void
88
    {
89
        $response = $this->getResponse();
90
        Assert::notContains((string) $response->getBody(), $data);
91
    }
92
93
    /** @Then the response should be :data */
94
    public function response_should_be(string $data): void
95
    {
96
        $response = $this->getResponse();
97
        Assert::eq((string) $response->getBody(), $data);
98
    }
99
100
    /** @Then the response should not be :data */
101
    public function response_should_not_be(string $data): void
102
    {
103
        $response = $this->getResponse();
104
        Assert::NotEq((string) $response->getBody(), $data);
105
    }
106
107
}
108