|
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
|
|
|
use CoiSA\Http\Handler\HttpPlugHandler; |
|
12
|
|
|
use Http\Client\HttpClient; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
17
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class HttpPlugHandlerTest |
|
21
|
|
|
*/ |
|
22
|
|
|
final class HttpPlugHandlerTest extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var HttpClient|ObjectProphecy */ |
|
25
|
|
|
private $client; |
|
26
|
|
|
|
|
27
|
|
|
/** @var ServerRequestInterface|ObjectProphecy */ |
|
28
|
|
|
private $serverRequest; |
|
29
|
|
|
|
|
30
|
|
|
/** @var ResponseInterface|ObjectProphecy */ |
|
31
|
|
|
private $response; |
|
32
|
|
|
|
|
33
|
|
|
/** @var HttpPlugHandler */ |
|
34
|
|
|
private $handler; |
|
35
|
|
|
|
|
36
|
|
|
public function setUp(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->client = $this->prophesize(HttpClient::class); |
|
39
|
|
|
$this->serverRequest = $this->prophesize(ServerRequestInterface::class); |
|
40
|
|
|
$this->response = $this->prophesize(ResponseInterface::class); |
|
41
|
|
|
$this->handler = new HttpPlugHandler($this->client->reveal()); |
|
42
|
|
|
|
|
43
|
|
|
$this->client->sendRequest($this->serverRequest->reveal())->will([$this->response, 'reveal']); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testHandlerImplementInterface() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->assertInstanceOf(RequestHandlerInterface::class, $this->handler); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testHandleReturnResponseFromClient() |
|
52
|
|
|
{ |
|
53
|
|
|
$response = $this->handler->handle($this->serverRequest->reveal()); |
|
54
|
|
|
$client = $this->client->reveal(); |
|
55
|
|
|
$this->assertEquals($client->sendRequest($this->serverRequest->reveal()), $response); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|