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
|
|
|
|