Passed
Push — master ( c833e6...2cc74e )
by Felipe
02:42 queued 19s
created

HttpPlugHandlerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 3
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\HttpPlugHandler;
14
use Http\Client\HttpClient;
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 HttpPlugHandlerTest
23
 *
24
 * @package CoiSA\Http\Test
25
 */
26
final class HttpPlugHandlerTest extends TestCase
27
{
28
    /** @var HttpClient|ObjectProphecy */
29
    private $client;
30
31
    /** @var ObjectProphecy|ServerRequestInterface */
32
    private $serverRequest;
33
34
    /** @var ObjectProphecy|ResponseInterface */
35
    private $response;
36
37
    /** @var HttpPlugHandler */
38
    private $handler;
39
40
    public function setUp(): void
41
    {
42
        $this->client        = $this->prophesize(HttpClient::class);
43
        $this->serverRequest = $this->prophesize(ServerRequestInterface::class);
44
        $this->response      = $this->prophesize(ResponseInterface::class);
45
        $this->handler       = new HttpPlugHandler($this->client->reveal());
46
47
        $this->client->sendRequest($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->sendRequest($this->serverRequest->reveal()), $response);
60
    }
61
}
62