Message::hasNotHeader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Psr7Unitesting;
4
5
use Psr\Http\Message\MessageInterface;
6
7
/**
8
 * Class to execute assertions for generic http messages.
9
 */
10
class Message extends Utils\AbstractAssert
11
{
12
    /**
13
     * @var MessageInterface
14
     */
15
    protected $message;
16
17
    /**
18
     * Constructor.
19
     *
20
     * @param MessageInterface    $message
21
     * @param AbstractAssert|null $previous
22
     */
23
    public function __construct(MessageInterface $message, Utils\AbstractAssert $previous = null)
24
    {
25
        $this->message = $message;
26
        $this->previous($previous);
27
    }
28
29
    /**
30
     * Asserts that a header exists.
31
     *
32
     * @param string $name
33
     * @param string $message
34
     *
35
     * @return self
36
     */
37
    public function hasHeader($name, $message = '')
38
    {
39
        return $this->assert($this->message, new Message\HasHeader($name), $message);
40
    }
41
42
    /**
43
     * Asserts that a header does not exists.
44
     *
45
     * @param string $name
46
     * @param string $message
47
     *
48
     * @return self
49
     */
50
    public function hasNotHeader($name, $message = '')
51
    {
52
        return $this->assert($this->message, new Message\HasNotHeader($name), $message);
53
    }
54
55
    /**
56
     * Asserts that a header has a specific value.
57
     *
58
     * @param string $name
59
     * @param string $value
60
     * @param string $message
61
     *
62
     * @return self
63
     */
64
    public function header($name, $value, $message = '')
65
    {
66
        return $this->assert($this->message, new Message\Header($name, $value), $message);
67
    }
68
69
    /**
70
     * Asserts the protocol version of the message.
71
     *
72
     * @param string $version
73
     * @param string $message
74
     *
75
     * @return self
76
     */
77
    public function protocolVersion($version, $message = '')
78
    {
79
        return $this->assert($this->message, new Message\ProtocolVersion($version), $message);
80
    }
81
82
    /**
83
     * Asserts the whole body.
84
     * 
85
     * @param string|StreamInterface $body
86
     * @param string                 $message
87
     *
88
     * @return self
89
     */
90
    public function body($body, $message = '')
91
    {
92
        return $this->assert($this->message, new Message\Body((string) $body), $message);
93
    }
94
95
    /**
96
     * Creates a Body instance to execute assertions in the body.
97
     *
98
     * @return Stream
99
     */
100
    public function assertBody()
101
    {
102
        return new Stream($this->message->getBody(), $this);
103
    }
104
}
105