Total Complexity | 4 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class MockRequestHandler implements RequestHandlerInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var ServerRequestInterface |
||
15 | */ |
||
16 | public $processedRequest; |
||
17 | |||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $responseStatus; |
||
22 | |||
23 | /** |
||
24 | * @var \Throwable|null |
||
25 | */ |
||
26 | private $handleException; |
||
27 | |||
28 | public function __construct(int $responseStatus = 200) |
||
29 | { |
||
30 | $this->responseStatus = $responseStatus; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @return static |
||
35 | */ |
||
36 | public function setHandleExcaption(?\Throwable $throwable) |
||
37 | { |
||
38 | $this->handleException = $throwable; |
||
39 | return $this; |
||
40 | } |
||
41 | |||
42 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
43 | { |
||
44 | if ($this->handleException !== null) { |
||
45 | throw $this->handleException; |
||
46 | } |
||
47 | $this->processedRequest = $request; |
||
48 | return new Response($this->responseStatus); |
||
49 | } |
||
51 |