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

CallableHandlerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
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\CallableHandler;
14
use PHPUnit\Framework\TestCase;
15
use Prophecy\Prophecy\ObjectProphecy;
16
use Psr\Http\Message\ResponseInterface;
17
use Psr\Http\Message\ServerRequestInterface;
18
19
/**
20
 * Class CallableHandlerTest
21
 *
22
 * @package CoiSA\Http\Test
23
 */
24
final class CallableHandlerTest extends TestCase
25
{
26
    /** @var ObjectProphecy|ServerRequestInterface */
27
    private $serverRequest;
28
29
    /** @var ObjectProphecy|ResponseInterface */
30
    private $response;
31
32
    public function setUp(): void
33
    {
34
        $this->serverRequest = $this->prophesize(ServerRequestInterface::class);
35
        $this->response      = $this->prophesize(ResponseInterface::class);
36
    }
37
38
    public function testInvalidCallbackThrowsTypeError(): void
39
    {
40
        $handler = new CallableHandler(function (): void {
41
        });
42
        $this->expectException(\TypeError::class);
43
        $handler->handle($this->serverRequest->reveal());
44
    }
45
46
    public function testHandleReturnsCallbackResponse(): void
47
    {
48
        $response = $this->response;
49
        $callback = function () use ($response) {
50
            return $response->reveal();
51
        };
52
        $handler = new CallableHandler($callback);
53
        $this->assertEquals($callback($this->serverRequest->reveal()), $handler->handle($this->serverRequest->reveal()));
54
    }
55
}
56