Passed
Push — master ( ad0000...6744b7 )
by Felipe
01:50
created

testHandleReturnsCallbackResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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