Completed
Pull Request — master (#2)
by Mathieu
08:19
created

AssertJsonResponseTest::testJsonResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace LaravelFr\Tests;
4
5
use Illuminate\Http\Response;
6
use LaravelFr\ApiTesting\Tests\Stubs\JsonSerializableMixedResourcesStub;
7
use LaravelFr\ApiTesting\AssertJsonResponse;
8
use LaravelFr\ApiTesting\Tests\Stubs\JsonSerializableTypedResourceStub;
9
use PHPUnit_Framework_TestCase;
10
11
class AssertJsonResponseTest extends PHPUnit_Framework_TestCase
12
{
13
    use AssertJsonResponse;
14
15 View Code Duplication
    public function testAssertArrayStructureEquals()
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);
0 ignored issues
show
Bug introduced by
The property response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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