Passed
Push — master ( c833e6...2cc74e )
by Felipe
02:42 queued 19s
created

ErrorHandlerMiddlewareTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3
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\Middleware;
12
13
use CoiSA\Http\Middleware\ErrorHandlerMiddleware;
14
use CoiSA\Http\Test\Handler\AbstractMiddlewareTest;
15
use Prophecy\Argument;
16
17
/**
18
 * Class ErrorHandlerMiddlewareTest
19
 *
20
 * @package CoiSA\Http\Test\Middleware
21
 */
22
final class ErrorHandlerMiddlewareTest extends AbstractMiddlewareTest
23
{
24
    public function setUp(): void
25
    {
26
        parent::setUp();
27
28
        $this->middleware = new ErrorHandlerMiddleware($this->handler->reveal());
29
30
        $this->serverRequest->withAttribute(Argument::type('string'), Argument::type(\Throwable::class))->will([$this->serverRequest, 'reveal']);
31
    }
32
33
    public function testSuccessExecutionReturnHandlerResponse(): void
34
    {
35
        $response = $this->middleware->process($this->serverRequest->reveal(), $this->nextHandler->reveal());
36
        $this->assertSame($this->nextResponse->reveal(), $response);
37
        $this->assertNotSame($this->response->reveal(), $response);
38
    }
39
40
    public function testOnExceptionReturnErrorHandlerResponse(): void
41
    {
42
        $this->nextHandler->handle($this->serverRequest->reveal())->willThrow(\Exception::class);
43
44
        $response = $this->middleware->process($this->serverRequest->reveal(), $this->nextHandler->reveal());
45
        $this->assertSame($this->response->reveal(), $response);
46
        $this->assertNotSame($this->nextResponse->reveal(), $response);
47
    }
48
}
49