Completed
Pull Request — master (#2)
by Mathieu
04:35 queued 02:51
created

testSeeJsonTypedStructure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace LaravelFr\ApiTesting\Tests;
4
5
use Illuminate\Http\Response;
6
use PHPUnit_Framework_TestCase;
7
use LaravelFr\ApiTesting\AssertJsonResponse;
8
use LaravelFr\ApiTesting\Tests\Stubs\JsonSerializableTypedResourceStub;
9
use LaravelFr\ApiTesting\Tests\Stubs\JsonSerializableMixedResourcesStub;
10
11
class AssertJsonResponseTest extends PHPUnit_Framework_TestCase
12
{
13
    use AssertJsonResponse;
14
15 View Code Duplication
    public function testSeeJsonStructureEquals()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17
        $this->response = new Response(new JsonSerializableMixedResourcesStub);
18
19
        $this->seeJsonStructureEquals([
20
            'foo',
21
            'baz'    => ['*' => ['bar' => ['*'], 'foo']],
22
            'bars'   => ['*' => ['bar', 'foo']],
23
            'foobar' => ['foobar_foo', 'foobar_bar'],
24
        ]);
25
    }
26
27
    public function testJsonResponse()
28
    {
29
        $this->response = new Response(new JsonSerializableMixedResourcesStub);
30
31
        $this->assertEquals(
32
            (new JsonSerializableMixedResourcesStub)->jsonSerialize(),
33
            $this->jsonResponse()
34
        );
35
        $this->assertEquals(
36
            ['foobar_foo' => 'foo', 'foobar_bar' => 'bar'],
37
            $this->jsonResponse('foobar')
38
        );
39
        $this->assertEquals('bar', $this->jsonResponse('foobar.foobar_bar'));
40
    }
41
42
    public function testSeeJsonTypedStructure()
43
    {
44
        $this->response = new Response(new JsonSerializableTypedResourceStub);
45
46
        $this->seeJsonTypedStructure([
47
            'foo' => 'string',
48
            'bar' => 'integer',
49
            'foobar' => 'array',
50
            'baz' => 'boolean',
51
            'nested_foo' => [
52
                'foo' => 'string',
53
                'bar' => 'integer',
54
                'foobar' => 'array',
55
                'baz' => 'boolean',
56
                'double_nested_foo' => [
57
                    'foo' => 'string',
58
                    'bar' => 'integer',
59
                    'foobar' => 'array',
60
                    'baz' => 'boolean',
61
                ],
62
            ],
63
        ]);
64
    }
65
}
66