|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace VGirol\JsonApiAssert\Laravel\Asserts\Content; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Testing\TestResponse; |
|
6
|
|
|
use PHPUnit\Framework\Assert as PHPUnit; |
|
7
|
|
|
use VGirol\JsonApiAssert\Members; |
|
8
|
|
|
|
|
9
|
|
|
trait AssertPagination |
|
10
|
|
|
{ |
|
11
|
|
|
public static function assertResponseHasNoPaginationLinks(TestResponse $response): void |
|
12
|
|
|
{ |
|
13
|
|
|
// Decode JSON response |
|
14
|
|
|
$json = $response->json(); |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
if (!isset($json[Members::LINKS])) { |
|
17
|
|
|
PHPUnit::assertTrue(true); |
|
18
|
|
|
|
|
19
|
|
|
return; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
$links = $json[Members::LINKS]; |
|
23
|
|
|
static::assertHasNoPaginationLinks($links); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public static function assertResponseHasPaginationLinks(TestResponse $response, $expected) |
|
27
|
|
|
{ |
|
28
|
|
|
// Decode JSON response |
|
29
|
|
|
$json = $response->json(); |
|
30
|
|
|
|
|
31
|
|
|
static::assertHasLinks($json); |
|
32
|
|
|
$links = $json[Members::LINKS]; |
|
33
|
|
|
static::assertPaginationLinksEquals($expected, $links); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public static function assertResponseHasNoPaginationMeta(TestResponse $response): void |
|
37
|
|
|
{ |
|
38
|
|
|
// Decode JSON response |
|
39
|
|
|
$json = $response->json(); |
|
40
|
|
|
|
|
41
|
|
|
if (!isset($json[Members::META])) { |
|
42
|
|
|
static::assertNotHasMember(Members::META, $json); |
|
43
|
|
|
|
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$meta = $json[Members::META]; |
|
48
|
|
|
static::assertHasNoPaginationMeta($meta); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function assertResponseHasPaginationMeta(TestResponse $response, $expected, $path = null) |
|
52
|
|
|
{ |
|
53
|
|
|
// Decode JSON response |
|
54
|
|
|
$json = $response->json(); |
|
55
|
|
|
|
|
56
|
|
|
if ($path !== null) { |
|
57
|
|
|
$json = static::getJsonFromPath($json, $path); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
static::assertHasMeta($json); |
|
61
|
|
|
$meta = $json[Members::META]; |
|
62
|
|
|
static::assertHasMember('pagination', $meta); |
|
63
|
|
|
$pagination = $meta['pagination']; |
|
64
|
|
|
PHPUnit::assertEquals($expected, $pagination); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function assertResponseHasNoPagination(TestResponse $response) |
|
68
|
|
|
{ |
|
69
|
|
|
static::assertResponseHasNoPaginationLinks($response); |
|
70
|
|
|
static::assertResponseHasNoPaginationMeta($response); |
|
71
|
|
|
if (isset($json[Members::META])) { |
|
|
|
|
|
|
72
|
|
|
$meta = $json[Members::META]; |
|
73
|
|
|
JsonApiAssert::assertNotHasMember('pagination', $meta); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public static function assertResponseHasPagination(TestResponse $response, $expectedLinks, $expectedMeta) |
|
78
|
|
|
{ |
|
79
|
|
|
static::assertResponseHasPaginationLinks($response, $expectedLinks); |
|
80
|
|
|
static::assertResponseHasPaginationMeta($response, $expectedMeta); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.