Completed
Push — master ( 6fa789...1e4339 )
by Mathieu
06:26
created

testSeeJsonStructureEquals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace LaravelFr\ApiTesting\Tests\AssertJsonResponse;
4
5
use Illuminate\Http\Response;
6
use PHPUnit_Framework_TestCase;
7
use LaravelFr\ApiTesting\AssertJsonResponse;
8
use Illuminate\Foundation\Testing\TestResponse;
9
use LaravelFr\ApiTesting\Tests\Stubs\JsonSerializableMixedResourcesStub;
10
11
class AssertJsonResponseForNewVersionTest extends PHPUnit_Framework_TestCase
12
{
13
    use AssertJsonResponse;
14
15
    private $response;
16
17
    public function setUp()
18
    {
19
        if (!class_exists(TestResponse::class)) {
20
            $this->markTestSkipped('Not compatible with this version.');
21
        }
22
        $this->response = new TestResponse(new Response(new JsonSerializableMixedResourcesStub));
23
    }
24
25
    public function testSeeJsonStructureEquals()
26
    {
27
        $this->assertTrue(TestResponse::hasMacro('seeJsonStructureEquals'));
28
29
        $this->response->seeJsonStructureEquals([
30
            'foo',
31
            'baz' => ['*' => ['bar' => ['*'], 'foo']],
32
            'bars' => ['*' => ['bar', 'foo']],
33
            'foobar' => ['foobar_foo', 'foobar_bar'],
34
        ]);
35
    }
36
37
    public function testJsonResponse()
38
    {
39
        $this->assertTrue(TestResponse::hasMacro('jsonResponse'));
40
41
        $this->assertEquals(
42
            (new JsonSerializableMixedResourcesStub)->jsonSerialize(),
43
            $this->response->jsonResponse()
44
        );
45
46
        $this->assertEquals(['foobar_foo' => 'foo', 'foobar_bar' => 'bar'], $this->response->jsonResponse('foobar'));
47
48
        $this->assertEquals('bar', $this->response->jsonResponse('foobar.foobar_bar'));
49
    }
50
}
51