StandardTest   A
last analyzed

Complexity

Total Complexity 35

Size/Duplication

Total Lines 313
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 35
eloc 104
c 2
b 0
f 0
dl 0
loc 313
rs 9.6

35 Methods

Rating   Name   Duplication   Size   Complexity  
A testWithAddedHeader() 0 6 1
A testWithUploadedFiles() 0 6 1
A testHasHeader() 0 6 1
A testWithParsedBody() 0 6 1
A testWithMethod() 0 6 1
A testGetAttributes() 0 6 1
A testWithoutAttribute() 0 6 1
A testWithUri() 0 8 1
A testWithoutHeader() 0 6 1
A testGetParsedBody() 0 6 1
A testGetCookieParams() 0 6 1
A testGetMethod() 0 6 1
A testWithBody() 0 8 1
A tearDown() 0 3 1
A testGetProtocolVersion() 0 6 1
A testGetQueryParams() 0 6 1
A testWithCookieParams() 0 6 1
A testGetClientAddress() 0 3 1
A testGetServerParams() 0 6 1
A testGetHeaderLine() 0 6 1
A testWithRequestTarget() 0 6 1
A testGetUploadedFiles() 0 6 1
A testGetAttribute() 0 6 1
A testWithHeader() 0 6 1
A testGetRequestTarget() 0 6 1
A testWithAttribute() 0 6 1
A testWithQueryParams() 0 6 1
A testWithProtocolVersion() 0 6 1
A testGetBody() 0 8 1
A testGetTarget() 0 3 1
A testTransform() 0 3 1
A setUp() 0 5 1
A testGetUri() 0 8 1
A testGetHeaders() 0 6 1
A testGetHeader() 0 6 1
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\Request;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $request;
16
17
18
	protected function setUp() : void
19
	{
20
		$view = new \Aimeos\Base\View\Standard();
21
		$this->request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
22
		$this->object = new \Aimeos\Base\View\Helper\Request\Standard( $view, $this->request, '127.0.0.1', 'test' );
23
	}
24
25
26
	protected function tearDown() : void
27
	{
28
		unset( $this->object, $this->request );
29
	}
30
31
32
	public function testTransform()
33
	{
34
		$this->assertInstanceOf( \Aimeos\Base\View\Helper\Request\Iface::class, $this->object->transform() );
35
	}
36
37
38
	public function testGetClientAddress()
39
	{
40
		$this->assertEquals( '127.0.0.1', $this->object->transform()->getClientAddress() );
41
	}
42
43
44
	public function testGetTarget()
45
	{
46
		$this->assertEquals( 'test', $this->object->transform()->getTarget() );
47
	}
48
49
50
	public function testGetProtocolVersion()
51
	{
52
		$this->request->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->request->expects( $this->once() )->method( 'withProtocolVersion' )
62
			->willReturn( $this->request );
63
64
		$this->assertEquals( $this->object, $this->object->withProtocolVersion( '1.0' ) );
65
	}
66
67
68
	public function testGetHeaders()
69
	{
70
		$this->request->expects( $this->once() )->method( 'getHeaders' )
71
			->willReturn( [] );
72
73
		$this->assertEquals( [], $this->object->getHeaders() );
74
	}
75
76
77
	public function testHasHeader()
78
	{
79
		$this->request->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->request->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->request->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->request->expects( $this->once() )->method( 'withHeader' )
107
			->willReturn( $this->request );
108
109
		$this->assertEquals( $this->object, $this->object->withHeader( 'test', 'value' ) );
110
	}
111
112
113
	public function testWithAddedHeader()
114
	{
115
		$this->request->expects( $this->once() )->method( 'withAddedHeader' )
116
			->willReturn( $this->request );
117
118
		$this->assertEquals( $this->object, $this->object->withAddedHeader( 'test', 'value' ) );
119
	}
120
121
122
	public function testWithoutHeader()
123
	{
124
		$this->request->expects( $this->once() )->method( 'withoutHeader' )
125
			->willReturn( $this->request );
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->request->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->request->expects( $this->once() )->method( 'withBody' )
147
			->willReturn( $this->request );
148
149
		$this->assertEquals( $this->object, $this->object->withBody( $stream ) );
150
	}
151
152
153
	public function testGetRequestTarget()
154
	{
155
		$this->request->expects( $this->once() )->method( 'getRequestTarget' )
156
			->willReturn( 'test' );
157
158
		$this->assertEquals( 'test', $this->object->getRequestTarget() );
159
	}
160
161
162
	public function testWithRequestTarget()
163
	{
164
		$this->request->expects( $this->once() )->method( 'withRequestTarget' )
165
			->willReturn( $this->request );
166
167
		$this->assertEquals( $this->object, $this->object->withRequestTarget( 'test' ) );
168
	}
169
170
171
	public function testGetMethod()
172
	{
173
		$this->request->expects( $this->once() )->method( 'getMethod' )
174
			->willReturn( 'test' );
175
176
		$this->assertEquals( 'test', $this->object->getMethod() );
177
	}
178
179
180
	public function testWithMethod()
181
	{
182
		$this->request->expects( $this->once() )->method( 'withMethod' )
183
			->willReturn( $this->request );
184
185
		$this->assertEquals( $this->object, $this->object->withMethod( 'test' ) );
186
	}
187
188
189
	public function testGetUri()
190
	{
191
		$uri = $this->getMockBuilder( \Psr\Http\Message\UriInterface::class )->getMock();
192
193
		$this->request->expects( $this->once() )->method( 'getUri' )
194
			->willReturn( $uri );
195
196
		$this->assertEquals( $uri, $this->object->getUri() );
197
	}
198
199
200
	public function testWithUri()
201
	{
202
		$uri = $this->getMockBuilder( \Psr\Http\Message\UriInterface::class )->getMock();
203
204
		$this->request->expects( $this->once() )->method( 'withUri' )
205
			->willReturn( $this->request );
206
207
		$this->assertEquals( $this->object, $this->object->withUri( $uri, false ) );
208
	}
209
210
211
	public function testGetServerParams()
212
	{
213
		$this->request->expects( $this->once() )->method( 'getServerParams' )
214
			->willReturn( [] );
215
216
		$this->assertEquals( [], $this->object->getServerParams() );
217
	}
218
219
220
	public function testGetCookieParams()
221
	{
222
		$this->request->expects( $this->once() )->method( 'getCookieParams' )
223
			->willReturn( [] );
224
225
		$this->assertEquals( [], $this->object->getCookieParams() );
226
	}
227
228
229
	public function testWithCookieParams()
230
	{
231
		$this->request->expects( $this->once() )->method( 'withCookieParams' )
232
			->willReturn( $this->request );
233
234
		$this->assertEquals( $this->object, $this->object->withCookieParams( [] ) );
235
	}
236
237
238
	public function testGetQueryParams()
239
	{
240
		$this->request->expects( $this->once() )->method( 'getQueryParams' )
241
			->willReturn( [] );
242
243
		$this->assertEquals( [], $this->object->getQueryParams() );
244
	}
245
246
247
	public function testWithQueryParams()
248
	{
249
		$this->request->expects( $this->once() )->method( 'withQueryParams' )
250
			->willReturn( $this->request );
251
252
		$this->assertEquals( $this->object, $this->object->withQueryParams( [] ) );
253
	}
254
255
256
	public function testGetUploadedFiles()
257
	{
258
		$this->request->expects( $this->once() )->method( 'getUploadedFiles' )
259
			->willReturn( [] );
260
261
		$this->assertEquals( [], $this->object->getUploadedFiles() );
262
	}
263
264
265
	public function testWithUploadedFiles()
266
	{
267
		$this->request->expects( $this->once() )->method( 'withUploadedFiles' )
268
			->willReturn( $this->request );
269
270
		$this->assertEquals( $this->object, $this->object->withUploadedFiles( [] ) );
271
	}
272
273
274
	public function testGetParsedBody()
275
	{
276
		$this->request->expects( $this->once() )->method( 'getParsedBody' )
277
			->willReturn( 'test' );
278
279
		$this->assertEquals( 'test', $this->object->getParsedBody() );
280
	}
281
282
283
	public function testWithParsedBody()
284
	{
285
		$this->request->expects( $this->once() )->method( 'withParsedBody' )
286
			->willReturn( $this->request );
287
288
		$this->assertEquals( $this->object, $this->object->withParsedBody( array( 'test' ) ) );
289
	}
290
291
292
	public function testGetAttributes()
293
	{
294
		$this->request->expects( $this->once() )->method( 'getAttributes' )
295
			->willReturn( [] );
296
297
		$this->assertEquals( [], $this->object->getAttributes() );
298
	}
299
300
301
	public function testGetAttribute()
302
	{
303
		$this->request->expects( $this->once() )->method( 'getAttribute' )
304
			->willReturn( 'value' );
305
306
		$this->assertEquals( 'value', $this->object->getAttribute( 'test', 'default' ) );
307
	}
308
309
310
	public function testWithAttribute()
311
	{
312
		$this->request->expects( $this->once() )->method( 'withAttribute' )
313
			->willReturn( $this->request );
314
315
		$this->assertEquals( $this->object, $this->object->withAttribute( 'test', 'value' ) );
316
	}
317
318
319
	public function testWithoutAttribute()
320
	{
321
		$this->request->expects( $this->once() )->method( 'withoutAttribute' )
322
			->willReturn( $this->request );
323
324
		$this->assertEquals( $this->object, $this->object->withoutAttribute( 'test' ) );
325
	}
326
}
327