Passed
Push — master ( 8ddff3...7c428f )
by Felipe
01:57
created

HttpPlugHandlerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

3 Methods

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