|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2025 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Base\View\Helper\Response; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $object; |
|
15
|
|
|
private $response; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() : void |
|
19
|
|
|
{ |
|
20
|
|
|
$view = new \Aimeos\Base\View\Standard(); |
|
21
|
|
|
$this->response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock(); |
|
22
|
|
|
$this->object = new \Aimeos\Base\View\Helper\Response\Standard( $view, $this->response ); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
protected function tearDown() : void |
|
27
|
|
|
{ |
|
28
|
|
|
unset( $this->object, $this->response ); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
public function testTransform() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertInstanceOf( \Aimeos\Base\View\Helper\Response\Iface::class, $this->object->transform() ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function testCreateStream() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->assertInstanceOf( \Psr\Http\Message\StreamInterface::class, $this->object->createStream( __FILE__ ) ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
public function testCreateStreamFromString() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->assertInstanceOf( \Psr\Http\Message\StreamInterface::class, $this->object->createStreamFromString( 'test' ) ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
public function testGetProtocolVersion() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->response->expects( $this->once() )->method( 'getProtocolVersion' ) |
|
53
|
|
|
->willReturn( '1.0' ); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertEquals( '1.0', $this->object->getProtocolVersion() ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function testWithProtocolVersion() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->response->expects( $this->once() )->method( 'withProtocolVersion' ) |
|
62
|
|
|
->willReturn( $this->response ); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertEquals( $this->object, $this->object->withProtocolVersion( '1.0' ) ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
public function testGetHeaders() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->response->expects( $this->once() )->method( 'getHeaders' ) |
|
71
|
|
|
->willReturn( [] ); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertEquals( [], $this->object->getHeaders() ); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
public function testHasHeader() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->response->expects( $this->once() )->method( 'hasHeader' ) |
|
80
|
|
|
->willReturn( true ); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertEquals( true, $this->object->hasHeader( 'test' ) ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
public function testGetHeader() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->response->expects( $this->once() )->method( 'getHeader' ) |
|
89
|
|
|
->willReturn( ['value'] ); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertEquals( ['value'], $this->object->getHeader( 'test' ) ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
public function testGetHeaderLine() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->response->expects( $this->once() )->method( 'getHeaderLine' ) |
|
98
|
|
|
->willReturn( 'value' ); |
|
99
|
|
|
|
|
100
|
|
|
$this->assertEquals( 'value', $this->object->getHeaderLine( 'test' ) ); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
public function testWithHeader() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->response->expects( $this->once() )->method( 'withHeader' ) |
|
107
|
|
|
->willReturn( $this->response ); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertEquals( $this->object, $this->object->withHeader( 'test', 'value' ) ); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
public function testWithAddedHeader() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->response->expects( $this->once() )->method( 'withAddedHeader' ) |
|
116
|
|
|
->willReturn( $this->response ); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertEquals( $this->object, $this->object->withAddedHeader( 'test', 'value' ) ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
public function testWithoutHeader() |
|
123
|
|
|
{ |
|
124
|
|
|
$this->response->expects( $this->once() )->method( 'withoutHeader' ) |
|
125
|
|
|
->willReturn( $this->response ); |
|
126
|
|
|
|
|
127
|
|
|
$this->assertEquals( $this->object, $this->object->withoutHeader( 'test' ) ); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
public function testGetBody() |
|
132
|
|
|
{ |
|
133
|
|
|
$stream = $this->getMockBuilder( \Psr\Http\Message\StreamInterface::class )->getMock(); |
|
134
|
|
|
|
|
135
|
|
|
$this->response->expects( $this->once() )->method( 'getBody' ) |
|
136
|
|
|
->willReturn( $stream ); |
|
137
|
|
|
|
|
138
|
|
|
$this->assertEquals( $stream, $this->object->getBody() ); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
public function testWithBody() |
|
143
|
|
|
{ |
|
144
|
|
|
$stream = $this->getMockBuilder( \Psr\Http\Message\StreamInterface::class )->getMock(); |
|
145
|
|
|
|
|
146
|
|
|
$this->response->expects( $this->once() )->method( 'withBody' ) |
|
147
|
|
|
->willReturn( $this->response ); |
|
148
|
|
|
|
|
149
|
|
|
$this->assertEquals( $this->object, $this->object->withBody( $stream ) ); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
public function testGetStatusCode() |
|
154
|
|
|
{ |
|
155
|
|
|
$this->response->expects( $this->once() )->method( 'getStatusCode' ) |
|
156
|
|
|
->willReturn( 200 ); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertEquals( 200, $this->object->getStatusCode() ); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
public function testWithStatus() |
|
163
|
|
|
{ |
|
164
|
|
|
$this->response->expects( $this->once() )->method( 'withStatus' ) |
|
165
|
|
|
->willReturn( $this->response ); |
|
166
|
|
|
|
|
167
|
|
|
$this->assertEquals( $this->object, $this->object->withStatus( 500, 'phrase' ) ); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
public function testGetReasonPhrase() |
|
172
|
|
|
{ |
|
173
|
|
|
$this->response->expects( $this->once() )->method( 'getReasonPhrase' ) |
|
174
|
|
|
->willReturn( 'test' ); |
|
175
|
|
|
|
|
176
|
|
|
$this->assertEquals( 'test', $this->object->getReasonPhrase() ); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|