At the moment the expected location when calling assertCreatedWithClientId must not contain the expected id. This is because the assertion reads the id from the expected resource array and appends it to the provided URI.
However, this doesn't read nicely in tests. For example:
$post = Post::factory()->make();
$data = [
'type' => 'posts',
'id' => '7088eccc-a7cd-46f6-81f9-c553c9065dbd',
'attributes' => [
'content' => $post->content,
'slug' => $post->slug,
'title' => $post->title,
],
];
$response = $this
->jsonApi()
->expects('posts')
->withData($data)
->post('/api/v1/posts', $data);
$response->assertCreatedWithClientId(
'http://localhost/api/v1/posts',
$data
);
I think it reads better to do this:
$response->assertCreatedWithClientId(
'http://localhost/api/v1/posts/7088eccc-a7cd-46f6-81f9-c553c9065dbd',
$data
);
To fix in a non-breaking way, it would be good if the assertion accepted either. i.e. it can read the id from the provided $data, and check whether the URI already contains that id. If not, it can append it.
At the moment the expected location when calling
assertCreatedWithClientIdmust not contain the expected id. This is because the assertion reads theidfrom the expected resource array and appends it to the provided URI.However, this doesn't read nicely in tests. For example:
I think it reads better to do this:
To fix in a non-breaking way, it would be good if the assertion accepted either. i.e. it can read the
idfrom the provided$data, and check whether the URI already contains thatid. If not, it can append it.