|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Zend\Diactoros\ServerRequest; |
|
4
|
|
|
use Zend\Diactoros\Response; |
|
5
|
|
|
use Zend\Diactoros\Uri; |
|
6
|
|
|
use Zend\Diactoros\UploadedFile; |
|
7
|
|
|
use Zend\Diactoros\Stream; |
|
8
|
|
|
use Psr7Unitesting\Assert; |
|
9
|
|
|
|
|
10
|
|
|
class AppTest extends PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testServerRequest() |
|
13
|
|
|
{ |
|
14
|
|
|
$request = (new ServerRequest(['DOCUMENT_ROOT' => '/www'])) |
|
15
|
|
|
->withMethod('GET') |
|
16
|
|
|
->withUri(new Uri('http://user:[email protected]/?ola#id')) |
|
17
|
|
|
->withQueryParams(['ola' => 'value']) |
|
18
|
|
|
->withAttribute('bar', 'foo') |
|
19
|
|
|
->withCookieParams(['cookie-name' => 'cookie-value']) |
|
20
|
|
|
->withParsedBody(['name' => 'value']) |
|
21
|
|
|
->withUploadedFiles([ |
|
22
|
|
|
'file' => new UploadedFile('file.jpg', 50, 0, 'file.jpg', 'image/jpg'), |
|
23
|
|
|
]) |
|
24
|
|
|
->withBody(new Stream('php://temp', 'r')) |
|
25
|
|
|
->withHeader('Content-Type', 'text/html'); |
|
26
|
|
|
|
|
27
|
|
|
Assert::create($request) |
|
|
|
|
|
|
28
|
|
|
->protocolVersion('1.1') |
|
29
|
|
|
->header('Content-Type', 'text/html') |
|
30
|
|
|
->hasHeader('Content-Type') |
|
31
|
|
|
->hasNotHeader('X-Content-Type') |
|
32
|
|
|
->requestTarget('/?ola') |
|
33
|
|
|
->uri('http://user:[email protected]/?ola#id') |
|
34
|
|
|
->method('GET') |
|
35
|
|
|
->attribute('bar', 'foo') |
|
36
|
|
|
->hasAttribute('bar') |
|
37
|
|
|
->hasParsedBody('name') |
|
38
|
|
|
->parsedBody('name', 'value') |
|
39
|
|
|
->hasUploadedFile('file') |
|
40
|
|
|
->hasQueryParam('ola') |
|
41
|
|
|
->queryParam('ola', 'value') |
|
42
|
|
|
->cookieParam('cookie-name', 'cookie-value') |
|
43
|
|
|
->hasCookieParam('cookie-name') |
|
44
|
|
|
->hasServerParam('DOCUMENT_ROOT') |
|
45
|
|
|
->serverParam('DOCUMENT_ROOT', '/www') |
|
46
|
|
|
->assertUri() |
|
47
|
|
|
->scheme('http') |
|
48
|
|
|
->authority('user:[email protected]') |
|
49
|
|
|
->host('dag.gal') |
|
50
|
|
|
->query('ola') |
|
51
|
|
|
->fragment('id') |
|
52
|
|
|
->path('/') |
|
53
|
|
|
->userInfo('user:pass') |
|
54
|
|
|
->port(null) |
|
55
|
|
|
->end() |
|
56
|
|
|
|
|
57
|
|
|
->assertBody() |
|
58
|
|
|
->isNotWritable() |
|
59
|
|
|
->isReadable() |
|
60
|
|
|
->isSeekable() |
|
61
|
|
|
->size(0); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testResponse() |
|
65
|
|
|
{ |
|
66
|
|
|
$response = (new Response()) |
|
67
|
|
|
->withHeader('Content-Type', 'text/html') |
|
68
|
|
|
->withStatus(200, 'Ok!'); |
|
69
|
|
|
|
|
70
|
|
|
$response->getBody()->write(<<<HTML |
|
71
|
|
|
<!DOCTYPE html> |
|
72
|
|
|
<html> |
|
73
|
|
|
<head> |
|
74
|
|
|
<title>Hello world</title> |
|
75
|
|
|
</head> |
|
76
|
|
|
<body> |
|
77
|
|
|
<h1>Ola mundo</h1> |
|
78
|
|
|
<div class="first">Ola mundo</div> |
|
79
|
|
|
<div class="second">Ola mundo</div> |
|
80
|
|
|
</body> |
|
81
|
|
|
</html> |
|
82
|
|
|
HTML |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
Assert::create($response) |
|
|
|
|
|
|
86
|
|
|
->protocolVersion('1.1') |
|
87
|
|
|
->header('Content-Type', 'text/html') |
|
88
|
|
|
->hasHeader('Content-Type') |
|
89
|
|
|
->hasNotHeader('X-Content-Type') |
|
90
|
|
|
->statusCode(200) |
|
91
|
|
|
->reasonPhrase('Ok!') |
|
92
|
|
|
->assertBody() |
|
93
|
|
|
->isWritable() |
|
94
|
|
|
->isReadable() |
|
95
|
|
|
->isSeekable() |
|
96
|
|
|
->size(225) |
|
97
|
|
|
->assertHtml() |
|
98
|
|
|
->count('div', 2) |
|
99
|
|
|
->has('h1') |
|
100
|
|
|
->hasNot('section') |
|
101
|
|
|
->contains('h1', 'mundo') |
|
102
|
|
|
->notContains('h1', 'mundor'); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: