Completed
Push — master ( 632840...f0c648 )
by Alexander
02:14
created

MockRequestHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace Yiisoft\Yii\Web\Tests\Middleware\Mock;
5
6
use Nyholm\Psr7\Response;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
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
    }
50
}
51