mardi 26 janvier 2016

Validation rules work with html form, but not with phpunit test

I wrote a test class for my api to check if everything is still working. But at one point it fails:

//post exam
$this->post('modul/foo/exam', [
    'date' => '01-01-2016'
])
    ->assertResponseStatus(200);

//post exam again
$this->post('modul/foo/exam', [
    'date' => '01-01-2016'
])
    ->assertResponseStatus(422);

I have a validation rule for date

'date' => 'date:required|unique:exams,date,NULL,id,modul_id,' . \Route::input('modul')->id,

it says that you can only create one exam for a date for one modul. When I echo out the id i get 1 on both cases.

But when I test the second test returns 200, not 422.

The rule works perfectly when I use it with my html form, so is there something special by testing?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire