Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Add assertJsonMissingExact method to TestResponse.php #21881

Merged
merged 3 commits into from
Oct 31, 2017
Merged

[5.5] Add assertJsonMissingExact method to TestResponse.php #21881

merged 3 commits into from
Oct 31, 2017

Conversation

Gimcrack
Copy link
Contributor

@Gimcrack Gimcrack commented Oct 30, 2017

As it is currently written, the assertJsonMissing method will fail if any portion of the Json fragment is found in the response. Consider this example.

// response
[
    [
        'name' => 'John Doe',
        'created_at' => '2017-10-30'
    ],
];

Now we want to make sure that the response doesn't include a record for Jane Doe.

$this->assertJsonMissing( [
    'name' => 'Jane Doe',
    'created_at' => '2017-10-30'
]);

It is obviously not the same record, but the test will fail because the created_at values are the same.

Found unexpected JSON fragment: 

["created_at":"2017-10-30"]

within
...

@Gimcrack Gimcrack changed the title Add assertJsonMissingExact method to TestResponse.php [5.5] Add assertJsonMissingExact method to TestResponse.php Oct 30, 2017
@taylorotwell
Copy link
Member

I don't understand your comment. The two dates are the same?

@Gimcrack
Copy link
Contributor Author

@taylorotwell In this example, I want to test that the Jane Doe record is not in the response. It's obviously not, but the test fails because the two records have the same value for created_at. The test fails if any of the unexpected attributes are found in the response, but I want it to fail if all of the unexpected attributes are found in the response.

I can see use cases for the method as-is, so I added a new method to test that the exact Json fragment is missing.

I hope this clears it up. Cheers.

@taylorotwell taylorotwell merged commit 2b4aa9f into laravel:5.5 Oct 31, 2017
@taylorotwell
Copy link
Member

I see. Thanks.

taylorotwell pushed a commit that referenced this pull request Nov 1, 2017
* Revert "[5.5] Add assertJsonMissingExact method to TestResponse.php (#21881)"

This reverts commit 2b4aa9f.

* Revert "Add 'filter by attribute' functionality (#21898)"

This reverts commit edc6398.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants