Completed
Push — master ( dcf652...3d17c5 )
by Vincenzo
02:18
created

testThatThrowingAnExceptionWillBeCatchAndFormatted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
4
use Psr\Http\Message\RequestInterface;
5
use Psr\Http\Message\StreamInterface;
6
use Tests\Helpers\Stubs\ApiActionExceptionStub;
7
use Tests\Helpers\Stubs\ApiActionStub;
8
use Tests\Helpers\Stubs\ResponseStub;
9
10
class ApiActionTest extends PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @group App
14
     * @group ApiAction
15
     */
16
    public function testThatSettingSomeDataItWillGiveItBack()
17
    {
18
        $apiAction = new ApiActionStub(
19
            $this->getMock(RequestInterface::class),
20
            new ResponseStub(),
21
            []
22
        );
23
24
        $response = $apiAction->dispatch();
25
        $this->assertInstanceOf(StreamInterface::class, $response->getBody());
26
        $body = $response->getBody()->__toString();
27
        $this->assertNotEmpty($body);
28
    }
29
30
    /**
31
     * @group App
32
     * @group ApiAction
33
     * @group ApiActionException
34
     */
35
    public function testThatThrowingAnExceptionWillBeCatchAndFormatted()
36
    {
37
        $apiAction = new ApiActionExceptionStub(
38
            $this->getMock(RequestInterface::class),
39
            new ResponseStub(),
40
            []
41
        );
42
        $response = $apiAction->dispatch();
43
        $this->assertInstanceOf(StreamInterface::class, $response->getBody());
44
        $body = $response->getBody()->__toString();
45
        $this->assertNotEmpty($body);
46
        $code = 500;
47
        $jsonBody = json_decode($body);
48
        $this->assertEquals($code, $jsonBody->code);
49
    }
50
51
52
}
53