Passed
Push — master ( ed3da1...0fa97a )
by Felipe
03:03 queued 01:12
created

PsrHttpClientHandlerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
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\PsrHttpClientHandler;
14
use PHPUnit\Framework\TestCase;
15
use Prophecy\Prophecy\ObjectProphecy;
16
use Psr\Http\Client\ClientInterface;
17
use Psr\Http\Message\RequestInterface;
18
use Psr\Http\Message\ResponseInterface;
19
use Psr\Http\Message\ServerRequestInterface;
20
use Psr\Http\Server\RequestHandlerInterface;
21
22
/**
23
 * Class PsrHttpClientHandlerTest
24
 *
25
 * @package CoiSA\Http\Test
26
 */
27
final class PsrHttpClientHandlerTest extends TestCase
28
{
29
    /** @var ClientInterface|ObjectProphecy */
30
    private $client;
31
32
    /** @var ObjectProphecy|RequestInterface */
33
    private $request;
34
35
    /** @var ObjectProphecy|ServerRequestInterface */
36
    private $serverRequest;
37
38
    /** @var ObjectProphecy|ResponseInterface */
39
    private $response;
40
41
    /** @var PsrHttpClientHandler */
42
    private $handler;
43
44
    public function setUp(): void
45
    {
46
        $this->client        = $this->prophesize(ClientInterface::class);
47
        $this->request       = $this->prophesize(RequestInterface::class);
48
        $this->serverRequest = $this->prophesize(ServerRequestInterface::class);
49
        $this->response      = $this->prophesize(ResponseInterface::class);
50
        $this->handler       = new PsrHttpClientHandler($this->client->reveal());
51
52
        $this->client->sendRequest($this->request->reveal())->will([$this->response, 'reveal']);
53
        $this->client->sendRequest($this->serverRequest->reveal())->will([$this->response, 'reveal']);
54
    }
55
56
    public function testHandlerImplementInterfaces(): void
57
    {
58
        $this->assertInstanceOf(ClientInterface::class, $this->handler);
59
        $this->assertInstanceOf(RequestHandlerInterface::class, $this->handler);
60
    }
61
62
    public function testHandleReturnResponseFromClient(): void
63
    {
64
        $response = $this->handler->handle($this->serverRequest->reveal());
65
        $client   = $this->client->reveal();
66
        $this->assertEquals($client->sendRequest($this->serverRequest->reveal()), $response);
67
    }
68
69
    public function testSendRequestReturnResponseFromClient(): void
70
    {
71
        $response = $this->handler->sendRequest($this->request->reveal());
72
        $client   = $this->client->reveal();
73
        $this->assertEquals($client->sendRequest($this->request->reveal()), $response);
74
75
        $response = $this->handler->sendRequest($this->serverRequest->reveal());
76
        $this->assertEquals($client->sendRequest($this->serverRequest->reveal()), $response);
77
    }
78
}
79