Skip to content

Expected location for assertCreatedWithClientId #14

@lindyhopchris

Description

@lindyhopchris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions