Hi @browniecoffee Can you put the code of your test?
Aug 5, 2019
5
Level 2
unexpected errors for my test
Hello,
I on my tests yet and I have unexpected errors.
............ 23 / 23 (100%)
Time: 30.1 seconds, Memory: 30.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",
"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:111
/home/audrey/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:201
/home/audrey/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:160
FAILURES!
Tests: 23, Assertions: 71, Failures: 1.
But all my fields are filled
result `dump($response)`
#data: array:6 [
"category" => 1
"user_id" => 1
"title" => "Ab iste esse qui fugit quas exercitationem vitae molestias."
"thumbnail" => "891833a5f5421160f20fb75c62d07989.jpg"
"material_id" => array:2 [
0 => 1
1 => 2
]
"content" => "Aliquid quaerat dolorem dolorem nihil architecto eligendi. Optio autem est molestias incidunt quas illum."
]
#initialRules: array:7 [
"category" => "required"
"title" => "required|unique:projects|min:10|max:80"
"thumbnail" => "nullable|image|max:5000"
"material" => "required|array|min:1"
"material.*" => "nullable|alpha_num|between:3,200|distinct"
"material.0" => "required"
"content" => "required|min:10"
]
#rules: array:6 [
"category" => array:1 [
0 => "required"
]
"title" => array:4 [
0 => "required"
1 => "unique:projects"
2 => "min:10"
3 => "max:80"
]
"thumbnail" => array:3 [
0 => "nullable"
1 => "image"
2 => "max:5000"
]
"material" => array:3 [
0 => "required"
1 => "array"
2 => "min:1"
]
"material.0" => array:1 [
0 => "required"
]
"content" => array:2 [
0 => "required"
1 => "min:10"
]
]
.blade.php
<form id="project-create-form" action="{{route('projets.store')}}" method="POST" enctype="multipart/form-data">
@csrf
<div class="categories-box">
<div class="presentation">
Choisir une catégorie
</div>
<div>
@if($errors->has('category'))
<div class="error-box">
<small><i class="fa fa-times" aria-hidden="true"></i> {{$errors->first('category')}}</small>
</div>
@endif
<div class="categories">
@foreach ($categories as $enName => $frName)
<div>
<label for="{{$enName}}">
<input type="radio" id="{{$enName}}" name="category" class="category">
<span>{{$frName}}</span>
</label>
</div>
@endforeach
</div>
</div>
</div>
<div class="uk-margin">
@if($errors->has('title'))
<div class="error-box">
<small><i class="fa fa-times" aria-hidden="true"></i> {{$errors->first('title')}}</small>
</div>
@endif
<div class="input-and-characters-num">
<input class="uk-input post-title" name="title" type="text" maxlength="{{$maxChars}}"
placeholder="Titre du projet">
<div class="characters-num" id="charNum">{{$maxChars}}</div>
</div>
</div>
<div class="uk-margin">
@if($errors->has('thumbnail'))
<div class="error-box">
<small><i class="fa fa-times" aria-hidden="true"></i> {{$errors->first('thumbnail')}}</small>
</div>
@endif <div class="thumbnail-box">
<label for="thumbnail" class="thumbnail-label">
<i class="fa fa-cloud-upload" aria-hidden="true"></i>
ajouter une image thumnail pour votre projet !
<input type="file" id="thumbnail" name="thumbnail" class="thumbnail">
<div id="image_preview">
</div>
</label>
</div>
</div>
<div class="uk-margin inputs-box">
<div class="presentation">
<h4>Liste des besoins</h4>
<small>Ajoutez ce dont vous avez besoin pour ce projet</small>
</div>
<div class="boxes">
@if($errors->has('material.*'))
<div class="error-box">
<small><i class="fa fa-times" aria-hidden="true"></i> {{$errors->first('material.*')}}</small>
</div>
@endif
@for($i = 1; $i <=3 ; $i++) @php if($i==1){
$button='material-add-button' ; $icon='fa-plus' ;
$placeholder='ex: 5 boîtes en carton' ;
} else {
$button='material-remove-button' ;
$icon='fa-times' ; $placeholder='' ;
}
@endphp
<div class="input-box" id="input-box-{{$i}}">
<input class="uk-input material-input" name="material[]" id="{{$i}}" type="text"
placeholder="{{$placeholder}}">
<button class="uk-button {{$button}}" type="button" id="btn-{{$i}}"><i class="fa {{$icon}}"
aria-hidden="true"></i>
</button>
</div>
@endfor
</div>
</div>
//my test
/*
* @test
*/
public function the_fields_are_filled()
{
$user = factory(User::class)->create();
$project = factory(Project::class)->create();
$cat = factory(Category::class)->create();
$material = factory(Material::class, 2)->create();
$mat1 = Material::find(1);
$mat2 = Material::find(2);
// dd($mat1, $mat2);
//relation between user and projects
$user->projects()->save($project);
// relation between project and user
$project->user()->associate($user)->save();
//relation between project and material
// $project->materials()->save($material);
//si plusieurs materiaux
$project->materials()->saveMany([$mat1, $mat2]);
//relation between material and project
$mat1->project()->associate($project)->save();
$mat2->project()->associate($project)->save();
// dd($project->materials->all());
//relation between project and category
$project->category()->save($cat);
//relation between category and project
$cat->categorizable()->associate($project)->save();
// dd($matId = $project->materials->pluck('id'));
// dd($user->projects);
// dd($user->projects);
$response = $this->actingAs($user)->post(route('projets.store'),
[
'category' => $project->category->id,
'user_id' => $project->user->id,
'title' => $project->title, //pb -> titre déjà pris
'thumbnail' =>$project->thumbnail, // pas de thumbnail
'material[0]' => $project->materials->pluck('name'), // pas de materiels
'content' => $project->content
]
);
// dump($response);
$response->assertStatus(302)->assertSessionHasNoErrors();
}
I don't know why. Can you help me please?
Level 2
@punksolid Hi ! Sorry to answer to just now. My problem is fixed !
https://laracasts.com/discuss/channels/testing/session-has-unexpected-errors-1?page=1#reply=529841
Thank you
Please or to participate in this conversation.