1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of coisa/http. |
4
|
|
|
* |
5
|
|
|
* (c) Felipe Sayão Lobato Abreu <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace CoiSA\Http\Test\Handler; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Prophecy\Argument; |
15
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
17
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
18
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
19
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class AbstractMiddlewareTest |
23
|
|
|
* |
24
|
|
|
* @package CoiSA\Http\Test\Handler |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractMiddlewareTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** @var ObjectProphecy|RequestHandlerInterface */ |
29
|
|
|
protected $handler; |
30
|
|
|
|
31
|
|
|
/** @var ObjectProphecy|ServerRequestInterface */ |
32
|
|
|
protected $serverRequest; |
33
|
|
|
|
34
|
|
|
/** @var ObjectProphecy|ResponseInterface */ |
35
|
|
|
protected $response; |
36
|
|
|
|
37
|
|
|
/** @var MiddlewareInterface */ |
38
|
|
|
protected $middleware; |
39
|
|
|
|
40
|
|
|
public function setUp(): void |
41
|
|
|
{ |
42
|
|
|
$this->handler = $this->prophesize(RequestHandlerInterface::class); |
43
|
|
|
$this->serverRequest = $this->prophesize(ServerRequestInterface::class); |
44
|
|
|
$this->response = $this->prophesize(ResponseInterface::class); |
45
|
|
|
|
46
|
|
|
$this->handler->handle($this->serverRequest->reveal())->will([$this->response, 'reveal']); |
47
|
|
|
$this->response->withStatus(Argument::type('int'))->will([$this->response, 'reveal']); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testProcessMethodReturnResponse(): void |
51
|
|
|
{ |
52
|
|
|
$response = $this->middleware->process($this->serverRequest->reveal(), $this->handler->reveal()); |
53
|
|
|
$this->assertSame($this->response->reveal(), $response); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|