samedi 2 mars 2019

Test Validator from RegisterController (Laravel)

I'm trying to create a test that check if the validation passed. I'm using the default RegisterController class that is provided by laravel and added fews validations.

Here my test:

    function testUpdateUserFalseBirthday()
{
    $user = factory(User::class)->create([
        'type' => 'A',
        'date_naissance' => '2018-01-01',
    ]);

    $attributes = factory(User::class)->raw(['birthday' => '1998-27-27']);

    $response = $this->put("/users/{$user->id}", $attributes);

    $this->assertEquals('2018-01-01', $user->fresh()->birthday);
}

Result:

Tests\Feature\UsersTest::testUpdateUser2 Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'2018-01-01' +'1998-27-27'

so no validation has been done, even tho its working if I go on the site web and create a new user, its would have refused that birthday date (1998-27-27).

I just can't seems to find how to call the validations, tried alots of exemple but nothing worked.

Aucun commentaire:

Enregistrer un commentaire