Skip to content

Commit 9e19751

Browse files
committed
test: fix stub for php8.0
1 parent fec0471 commit 9e19751

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

tests/Feature/ResourceTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Illuminate\Http\Request;
88
use Test\app\Http\Resources\CommentResource;
99
use Test\app\Http\Resources\PostResource;
10-
use Test\app\Http\Resources\UserResource;
1110
use Test\app\Models\Comment;
1211
use Test\app\Models\Post;
1312
use Test\app\Models\User;
@@ -102,10 +101,10 @@ private function dataSeed()
102101

103102
private function getJsonResult(User $user, ?array $attributes = null, ?array $relationships = null)
104103
{
105-
$request = new Request([
106-
...($attributes !== null ? ['fields' => ['user' => implode(',', $attributes)]] : []),
107-
...($relationships !== null ? ['include' => implode(',', $relationships)] : []),
108-
]);
104+
$request = new Request(array_merge(
105+
($attributes !== null ? ['fields' => ['user' => implode(',', $attributes)]] : []),
106+
($relationships !== null ? ['include' => implode(',', $relationships)] : []),
107+
));
109108

110109
return array_filter([
111110
'data' => [
@@ -142,14 +141,18 @@ private function getJsonResult(User $user, ?array $attributes = null, ?array $re
142141
'updated_at' => $user->updated_at->format(DateTimeInterface::ATOM),
143142
],
144143
],
145-
'included' => array_filter([
146-
...(in_array('posts', $relationships ?? [])
147-
? $user->posts->mapInto(PostResource::class)->map->toArray($request)
148-
: []),
149-
...(in_array('comments', $relationships ?? [])
150-
? $user->comments->mapInto(CommentResource::class)->map->toArray($request)
151-
: []),
152-
])
144+
'included' => collect()
145+
->merge(
146+
in_array('posts', $relationships ?? [])
147+
? $user->posts->mapInto(PostResource::class)->map->toArray($request)
148+
: []
149+
)
150+
->merge(
151+
in_array('comments', $relationships ?? [])
152+
? $user->comments->mapInto(CommentResource::class)->map->toArray($request)
153+
: []
154+
)
155+
->toArray()
153156
]);
154157
}
155158
}

0 commit comments

Comments
 (0)