|
1
|
|
|
<?php namespace Nimo\Tests; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* User: mcfog |
|
5
|
|
|
* Date: 15/9/13 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
use Interop\Http\Server\RequestHandlerInterface; |
|
9
|
|
|
use Nimo\AbstractHandler; |
|
10
|
|
|
use Nimo\AbstractMiddleware; |
|
11
|
|
|
use Nimo\Handlers\CallableHandler; |
|
12
|
|
|
use PHPUnit\Framework\Assert; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
15
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
16
|
|
|
|
|
17
|
|
|
abstract class NimoTestCase extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
protected function throwHandler() |
|
20
|
|
|
{ |
|
21
|
|
|
return CallableHandler::wrap(function (ServerRequestInterface $request) { |
|
|
|
|
|
|
22
|
|
|
throw new \Exception('should throw'); |
|
23
|
|
|
}); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return ServerRequestInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function getRequestMock() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getMockForAbstractClass(ServerRequestInterface::class); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return ResponseInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function getResponseMock() |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->getMockForAbstractClass(ResponseInterface::class); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
protected function assertedHandler(ServerRequestInterface $expectedRequest, ResponseInterface $response) |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
return new class($expectedRequest, $response) extends AbstractHandler |
|
45
|
|
|
{ |
|
46
|
|
|
use RememberConstructorParamTrait; |
|
47
|
|
|
|
|
48
|
|
|
protected function main(): ResponseInterface |
|
49
|
|
|
{ |
|
50
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
|
51
|
|
|
list($expectedRequest, $response) = $this->params; |
|
52
|
|
|
Assert::assertSame($expectedRequest, $this->request); |
|
53
|
|
|
return $response; |
|
54
|
|
|
} |
|
55
|
|
|
}; |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
View Code Duplication |
protected function assertedNoopMiddleware( |
|
|
|
|
|
|
60
|
|
|
ServerRequestInterface $expectedRequest, |
|
61
|
|
|
ServerRequestInterface $passedRequest = null |
|
62
|
|
|
) { |
|
63
|
|
|
return new class($expectedRequest, $passedRequest) extends AbstractMiddleware |
|
64
|
|
|
{ |
|
65
|
|
|
use RememberConstructorParamTrait; |
|
66
|
|
|
|
|
67
|
|
|
protected function main(): ResponseInterface |
|
68
|
|
|
{ |
|
69
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
|
70
|
|
|
list($expectedRequest, $passedRequest) = $this->params; |
|
71
|
|
|
Assert::assertSame($expectedRequest, $this->request); |
|
72
|
|
|
return $this->delegate($passedRequest); |
|
73
|
|
|
} |
|
74
|
|
|
}; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
protected function assertedMiddleware( |
|
|
|
|
|
|
78
|
|
|
ServerRequestInterface $expectedRequest, |
|
79
|
|
|
RequestHandlerInterface $expectedHandler, |
|
80
|
|
|
ResponseInterface $response |
|
81
|
|
|
) { |
|
82
|
|
|
return new class($expectedRequest, $expectedHandler, $response) extends AbstractMiddleware |
|
83
|
|
|
{ |
|
84
|
|
|
use RememberConstructorParamTrait; |
|
85
|
|
|
|
|
86
|
|
|
protected function main(): ResponseInterface |
|
87
|
|
|
{ |
|
88
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
|
89
|
|
|
list($expectedRequest, $expectedHandler, $response) = $this->params; |
|
90
|
|
|
Assert::assertSame($expectedRequest, $this->request); |
|
91
|
|
|
Assert::assertSame($expectedHandler, $this->handler); |
|
92
|
|
|
return $response; |
|
93
|
|
|
} |
|
94
|
|
|
}; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
View Code Duplication |
protected function throwMiddleware( |
|
|
|
|
|
|
98
|
|
|
ServerRequestInterface $expectedRequest, |
|
99
|
|
|
RequestHandlerInterface $expectedHandler, |
|
100
|
|
|
\Throwable $throwable |
|
101
|
|
|
) { |
|
102
|
|
|
return new class($expectedRequest, $expectedHandler, $throwable) extends AbstractMiddleware |
|
103
|
|
|
{ |
|
104
|
|
|
use RememberConstructorParamTrait; |
|
105
|
|
|
|
|
106
|
|
|
protected function main(): ResponseInterface |
|
107
|
|
|
{ |
|
108
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
|
109
|
|
|
list($expectedRequest, $expectedHandler, $throwable) = $this->params; |
|
110
|
|
|
Assert::assertSame($expectedRequest, $this->request); |
|
111
|
|
|
Assert::assertSame($expectedHandler, $this->handler); |
|
112
|
|
|
throw $throwable; |
|
113
|
|
|
} |
|
114
|
|
|
}; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.