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