-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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 assertValidationErrors and assertJsonCount to TestResponse #21917
Conversation
I really like However, this does not work as expected if all your responses have a top-level data key (or something similar) How about adding an optional key (w/ a default value of $response->assertJsonCount(3, "data")
$response->assertJsonCount(9, "data.*.contacts") You should be able to assertCount on the result of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix this PHP Docblocks and you're ready to go 😄
@@ -294,6 +315,22 @@ public function assertJson(array $data, $strict = false) | |||
} | |||
|
|||
/** | |||
* Assert that the response json has the expected count. | |||
* @param int $count | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be:
/**
* Assert that the response json has the expected count.
*
* @param int $count
* @return $this
*/
* Assert that the response has validation errors for the given keys. | ||
* | ||
* @param string|array $keys | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be:
/**
* Assert that the response has validation errors for the given keys.
*
* @param string|array $keys
* @return $this
*/
I think it is better to have a provision for custom validation messages and localisation |
I agree that assertJsonCount isn't very helpful without being able to provide a key. |
@taylorotwell Good catch. Now if you are using pagination or similar you can specify a key.
|
Rebase your commits to a single one 😊 If you don’t know how: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html |
@Gabriel-Caruso there is an option to squash while merging the PR. So Taylor can take care of that |
@Dylan-DPC Oh, I didn’t know about this option 😱😍 |
In the release notes this is mentioned as added |
This commit adds two assert helpers to the TestResponse class.
assertValidationErrors( string|array $keys )
Asserts that the given key(s) are in the
errors
key of the Json response.Sample use case - validating a new user
assertJsonCount( int $count )
Asserts that the response data has the expected count.
Sample use case - getting a user resource index