Test Failed
Push — master ( b89417...fc8a73 )
by Felipe
01:53
created

GuzzleHandlerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testHandlerImplementInterface() 0 3 1
A testHandleReturnResponseFromClient() 0 5 1
A setUp() 0 8 1
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;
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