Hello again.
I have a problem for my second test. I trying to test, for this time, that all my fields are filled.
I have this error in my console:
PHPUnit 7.5.13 by Sebastian Bergmann and contributors.
..........F............. 24 / 24 (100%)
Time: 4.55 minutes, Memory: 28.00 MB
There was 1 failure:
1) Tests\Feature\ProjectCreationTest::the_fields_are_filled
Session has unexpected errors:
[
"Il semblerait que ce titre soit déjà pris",
"Le titre doit est composé d'au moins 10 caractères",
"The thumbnail must be an image.",
"The material field is required.",
"Vous devez inscrire au moins un matériel pour ce projet"
]
Failed asserting that true is false.
/var/www/html/goshr/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:991
/var/www/html/goshr/tests/Feature/ProjectCreationTest.php:68
/home/audrey/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:201
/home/audrey/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:160
My factory seems to be O.K.
<?php
/* @var $factory \Illuminate\Database\Eloquent\Factory */
use App\Project;
use Faker\Generator as Faker;
$factory->define(Project::class, function (Faker $faker) {
return [
'user_id' => function () {
return factory(App\User::class)->create()->id;
},
'title' => $faker->word(4),
'thumbnail' =>$faker->image('public/images/',640,480, null, false),
'material_id'=> function () {
return factory(App\Material::class)->create()->id;
},
'content' => $faker->text()
];
});
and my test too
/**
* Fields are filled.
*
* @return void
* @test
*/
public function the_fields_are_filled()
{
$user = factory(User::class)->make();
$projects = factory(Project::class, 3)
->create()
->each(function ($project) {
$project->category()->save(factory(Category::class)->make());
});
foreach($projects as $project){
$response = $this->actingAs($user)->post(route('projets.store'),[
'category' => $project->category->id ,
'user_id' => $project->user_id,
'title' => $project->title,
'thumbnail' =>$project->thumbnail,
'material_id' => $project->material_id,
'content' => $project->content
]);
}
$response->assertStatus(302)->assertSessionHasNoErrors();
}
I'm not sure but I'm think my loop is the problem, but it seems to be neccesary.
Do you know why my test isn't true ?
Thank by advance.