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