I want to test the json test response contain different values, in this case error messages, like so:
public function testFieldsAreRequired()
{
$this->postJson('/posts', [])
->assertStatus(422)
->assertJsonValidationErrors([
'name',
'email',
'date_of_birth',
])
->assertJsonFragment([
'The name field is required.'
])
->assertJsonFragment([
'The email field is required.'
])
->assertJsonFragment([
'The date of birth field is required.'
]);
}
This approach is not very efficient. I'm looking for an approach, like so:
.....
->assertJsonMessage([
'The name field is required.',
'The email field is required.',
'The date of birth field is required',
]);
Like above, I don't need to specify keys and different values.
But assertJsonMessage
is a protected method, so I'm not sure about original design and using this approach.
H
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire