mercredi 11 juillet 2018

Laravel assertJson not seeing the response that is being returned

I'm trying to write a simple test to make sure the authentication is working correctly ( Laravel 5.6 ) as seen below;

public function it_requires_name_and_email_and_password_to_register()
{
    $response = $this->post('/api/register');
    $response->assertStatus(422)
        ->assertJson([
            'name' => 'The name field is required.',
            'email' => 'The email field is required.',
            'password' => 'The password field is required.',
        ]);
}

But for some reason its failing even though the request has the required information.

The following is what phpunit is returning;

There was 1 failure:

1) Tests\Unit\AuthenticationTest::it_requires_name_and_email_and_password_to_register
Unable to find JSON:

[{
    "name": "The name field is required.",
    "email": "The email field is required.",
    "password": "The password field is required."
}]

within response JSON:

[{
    "message": "The given data was invalid.",
    "errors": {
        "name": [
            "The name field is required."
        ],
        "email": [
            "The email field is required."
        ],
        "password": [
            "The password field is required."
        ]
    }
}].


Failed asserting that an array has the subset Array &0 (
    'name' => 'The name field is required.'
    'email' => 'The email field is required.'
    'password' => 'The password field is required.'
).
--- Expected
+++ Actual
@@ @@

         )

-    [name] => The name field is required.
-    [email] => The email field is required.
-    [password] => The password field is required.
 )

Am i missing something?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire