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

CallableHandlerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testHandleReturnsCallbackResponse() 0 8 1
A setUp() 0 4 1
A testInvalidCallbackThrowsTypeError() 0 6 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\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);
0 ignored issues
show
Bug introduced by
The type CoiSA\Http\Test\TypeError was not found. Did you mean TypeError? If so, make sure to prefix the type with \.
Loading history...
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