This repository was archived by the owner on Feb 14, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +25
-23
lines changed Expand file tree Collapse file tree 6 files changed +25
-23
lines changed Original file line number Diff line number Diff line change @@ -13,14 +13,14 @@ public function jsonPaginate()
13
13
* Paginate the given query using JSON:API.
14
14
*
15
15
* @param int|string $perPage
16
- * @param array $columns
16
+ * @param array $columns
17
17
*
18
18
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
19
19
*/
20
20
return function ($ perPage = null , $ columns = ['* ' ]) {
21
21
$ perPage = $ perPage ?: $ this ->model ->getPerPage ();
22
22
$ clientPerPage = (int ) request ('page.size ' , config ('json-api.pagination.default_size ' ));
23
-
23
+
24
24
if (!$ perPage || $ perPage < $ clientPerPage ) {
25
25
$ perPage = $ clientPerPage ;
26
26
}
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ interface JsonApiable
6
6
{
7
7
/**
8
8
* Get a custom resource type for JSON:API formatting.
9
- *
10
- * @return string
9
+ *
10
+ * @return string
11
11
*/
12
12
public function resourceType (): string ;
13
13
}
Original file line number Diff line number Diff line change 4
4
5
5
use Illuminate \Contracts \Pagination \LengthAwarePaginator ;
6
6
use Illuminate \Support \Collection ;
7
+ use Illuminate \Support \Str ;
7
8
use SkoreLabs \JsonApi \Contracts \JsonApiable ;
8
9
use SkoreLabs \JsonApi \Http \Resources \JsonApiCollection ;
9
10
use SkoreLabs \JsonApi \Http \Resources \JsonApiResource ;
10
- use Illuminate \Support \Str ;
11
11
12
12
class JsonApi
13
13
{
14
14
/**
15
15
* Format the input contents to JSON:API.
16
- *
17
- * @param mixed $value
18
- * @return \SkoreLabs\JsonApi\Http\Resources\JsonApiResource
16
+ *
17
+ * @param mixed $value
18
+ *
19
+ * @return \SkoreLabs\JsonApi\Http\Resources\JsonApiResource
19
20
*/
20
21
public static function format ($ value )
21
22
{
@@ -28,9 +29,10 @@ public static function format($value)
28
29
29
30
/**
30
31
* Get resource type from a model.
31
- *
32
- * @param \Illuminate\Database\Eloquent\Model|string $model
33
- * @return string
32
+ *
33
+ * @param \Illuminate\Database\Eloquent\Model|string $model
34
+ *
35
+ * @return string
34
36
*/
35
37
public static function getResourceType ($ model )
36
38
{
Original file line number Diff line number Diff line change 6
6
use Illuminate \Support \Traits \Macroable ;
7
7
use PHPUnit \Framework \Assert as PHPUnit ;
8
8
use PHPUnit \Framework \AssertionFailedError ;
9
- use SkoreLabs \JsonApi \Testing \Concerns \HasRelationships ;
10
9
use SkoreLabs \JsonApi \Testing \Concerns \HasAttributes ;
11
10
use SkoreLabs \JsonApi \Testing \Concerns \HasCollections ;
12
11
use SkoreLabs \JsonApi \Testing \Concerns \HasIdentifications ;
12
+ use SkoreLabs \JsonApi \Testing \Concerns \HasRelationships ;
13
13
14
14
class Assert implements Arrayable
15
15
{
16
- use HasIdentifications,
17
- HasAttributes,
18
- HasRelationships,
19
- HasCollections,
20
- Macroable;
16
+ use HasIdentifications;
17
+ use HasAttributes;
18
+ use HasRelationships;
19
+ use HasCollections;
20
+ use Macroable;
21
21
22
22
/**
23
23
* @var string
@@ -38,7 +38,7 @@ class Assert implements Arrayable
38
38
* @var array
39
39
*/
40
40
protected $ relationships ;
41
-
41
+
42
42
/**
43
43
* @var array
44
44
*/
@@ -68,7 +68,7 @@ public static function fromTestResponse($response)
68
68
PHPUnit::assertArrayHasKey ('data ' , $ content );
69
69
$ data = $ content ['data ' ];
70
70
$ collection = [];
71
-
71
+
72
72
if (static ::isCollection ($ data )) {
73
73
$ collection = $ data ;
74
74
$ data = head ($ data );
Original file line number Diff line number Diff line change @@ -63,14 +63,14 @@ public function testCollectionsAtHasAttribute()
63
63
$ json ->at (1 )->hasAttribute ('title ' , 'Test Title 2 ' );
64
64
});
65
65
}
66
-
66
+
67
67
public function testCollectionsTakeByDefaultFirstItem ()
68
68
{
69
69
$ this ->get ('/ ' , ['Accept ' => 'application/json ' ])->assertJsonApi (function (Assert $ json ) {
70
70
$ json ->hasAttribute ('title ' , 'Test Title ' );
71
71
});
72
72
}
73
-
73
+
74
74
public function testCollectionsHasSize ()
75
75
{
76
76
$ this ->get ('/ ' , ['Accept ' => 'application/json ' ])->assertJsonApi (function (Assert $ json ) {
Original file line number Diff line number Diff line change @@ -31,13 +31,13 @@ public function setUp(): void
31
31
32
32
protected function defineDatabaseMigrations ()
33
33
{
34
- $ this ->loadMigrationsFrom (__DIR__ . '/database/migrations ' );
34
+ $ this ->loadMigrationsFrom (__DIR__ . '/database/migrations ' );
35
35
}
36
36
37
37
public function testJsonApiPaginationWithPageSize ()
38
38
{
39
39
$ response = $ this ->getJson ('/posts?page[size]=2 ' );
40
-
40
+
41
41
$ response ->assertJsonApi (function (Assert $ json ) {
42
42
$ json ->hasSize (2 );
43
43
});
You can’t perform that action at this time.
0 commit comments