testSeeJsonStructureEquals()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
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
    public function setUp()
16
    {
17
        if (!class_exists(TestResponse::class)) {
18
            $this->markTestSkipped('Not compatible with this version.');
19
        }
20
21
        $this->stub = new JsonSerializableMixedResourcesStub;
0 ignored issues
show
Bug introduced by
The property stub 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...
22
        $this->response = new TestResponse(new Response($this->stub));
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...
23
    }
24
25
    public function testSeeJsonStructureEquals()
26
    {
27
        $this->assertTrue(TestResponse::hasMacro('assertJsonStructureEquals'));
28
29
        $this->response->assertJsonStructureEquals($this->stub->structure());
30
    }
31
32
    public function testSeeJsonTypedStructure()
33
    {
34
        $this->assertTrue(TestResponse::hasMacro('seeJsonTypedStructure'));
35
36
        $this->response->seeJsonTypedStructure($this->stub->typedStructure());
37
    }
38
39
    public function testJsonResponse()
40
    {
41
        $this->assertTrue(TestResponse::hasMacro('jsonResponse'));
42
43
        $this->assertEquals(['foobar_foo' => 'foo', 'foobar_bar' => 212], $this->response->jsonResponse('foobar'));
44
45
        $this->assertEquals(212, $this->response->jsonResponse('foobar.foobar_bar'));
46
    }
47
}
48