1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Psr7Unitesting; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Message\StreamInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class to execute basic assertions with a StreamInterface instance. |
9
|
|
|
*/ |
10
|
|
|
class Stream extends Utils\AbstractAssert |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var StreamInterface |
14
|
|
|
*/ |
15
|
|
|
protected $stream; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $string; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor. |
24
|
|
|
* |
25
|
|
|
* @param StreamInterface $stream |
26
|
|
|
* @param AbstractAssert|null $previous |
27
|
|
|
*/ |
28
|
|
|
public function __construct(StreamInterface $stream, Utils\AbstractAssert $previous = null) |
29
|
|
|
{ |
30
|
|
|
$this->stream = $stream; |
31
|
|
|
$this->string = (string) $stream; |
32
|
|
|
$this->previous($previous); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Asserts that the stream has a specific size. |
37
|
|
|
* |
38
|
|
|
* @param int $size |
39
|
|
|
* @param string $message |
40
|
|
|
* |
41
|
|
|
* @return self |
42
|
|
|
*/ |
43
|
|
|
public function size($size, $message = '') |
44
|
|
|
{ |
45
|
|
|
return $this->assert($this->stream, new Stream\Size($size), $message); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Asserts that the stream is seekable. |
50
|
|
|
* |
51
|
|
|
* @param string $message |
52
|
|
|
* |
53
|
|
|
* @return self |
54
|
|
|
*/ |
55
|
|
|
public function isSeekable($message = '') |
56
|
|
|
{ |
57
|
|
|
return $this->assert($this->stream, new Stream\IsSeekable(), $message); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Asserts that the stream is not seekable. |
62
|
|
|
* |
63
|
|
|
* @param string $message |
64
|
|
|
* |
65
|
|
|
* @return self |
66
|
|
|
*/ |
67
|
|
|
public function isNotSeekable($message = '') |
68
|
|
|
{ |
69
|
|
|
return $this->assert($this->stream, new Stream\IsNotSeekable(), $message); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Asserts that the stream is writable. |
74
|
|
|
* |
75
|
|
|
* @param string $message |
76
|
|
|
* |
77
|
|
|
* @return self |
78
|
|
|
*/ |
79
|
|
|
public function isWritable($message = '') |
80
|
|
|
{ |
81
|
|
|
return $this->assert($this->stream, new Stream\IsWritable(), $message); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Asserts that the stream is not writable. |
86
|
|
|
* |
87
|
|
|
* @param string $message |
88
|
|
|
* |
89
|
|
|
* @return self |
90
|
|
|
*/ |
91
|
|
|
public function isNotWritable($message = '') |
92
|
|
|
{ |
93
|
|
|
return $this->assert($this->stream, new Stream\IsNotWritable(), $message); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Asserts that the stream is readable. |
98
|
|
|
* |
99
|
|
|
* @param string $message |
100
|
|
|
* |
101
|
|
|
* @return self |
102
|
|
|
*/ |
103
|
|
|
public function isReadable($message = '') |
104
|
|
|
{ |
105
|
|
|
return $this->assert($this->stream, new Stream\IsReadable(), $message); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Asserts that the stream is readable. |
110
|
|
|
* |
111
|
|
|
* @param string $message |
112
|
|
|
* |
113
|
|
|
* @return self |
114
|
|
|
*/ |
115
|
|
|
public function isNotReadable($message = '') |
116
|
|
|
{ |
117
|
|
|
return $this->assert($this->stream, new Stream\IsNotReadable(), $message); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Creates an instance of Html to execute assertions with the html code. |
122
|
|
|
* |
123
|
|
|
* @return Html |
124
|
|
|
*/ |
125
|
|
|
public function assertHtml() |
126
|
|
|
{ |
127
|
|
|
return new Html($this->stream, $this); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|