Completed
Push — master ( f730e7...231cf5 )
by John
03:07
created

getGetDataAndContentFromException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Tests\Test;
10
11
use KleijnWeb\SwaggerBundle\Test\ApiResponseErrorException;
12
use Symfony\Component\HttpFoundation\Response;
13
14
/**
15
 * @author John Kleijn <[email protected]>
16
 */
17
class ApiResponseErrorExceptionTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @test
21
     */
22
    public function exceptionMessageWillIncludeValidationErrors()
23
    {
24
        $exception = new ApiResponseErrorException(
25
            '',
26
            (object)[
27
                'message' => 'Validation failed',
28
                'errors'  => ['a' => 'invalid reason 1', 'b' => 'invalid reason 2'],
29
            ],
30
            Response::HTTP_BAD_REQUEST
31
        );
32
        $this->assertRegExp('#\[a\]: invalid reason 1\n\[b\]: invalid reason 2#', $exception->getMessage());
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function getGetDataAndContentFromException()
39
    {
40
        $data    = (object)[
41
            'message' => 'Reason',
42
            'extra'   => 'foo',
43
        ];
44
        $content = 'TheContent';
45
46
        $exception = new ApiResponseErrorException($content, $data, Response::HTTP_BAD_REQUEST);
47
48
        $this->assertSame($data, $exception->getData());
49
        $this->assertSame($content, $exception->getContent());
50
    }
51
}
52