A good day, gentlemen.
I am a student of programming, at that moment I am studying how to make unit tests using Laravel 5.3
In my tests I came across the following problem:
My little system only aims to register products in a database. After inserting the data into the forms send to my store function of my control where I make my validations:
public function store(Request $request)
{
$this->validate($request, [
'nome' => 'bail|required|unique:produtos|min:2',
'valor' => 'bail|required|min:0.1|numeric|'
]);
Produto::create($request->all());
return redirect('produtos');
}
I would like to make tests that capture if these validates are actually working, but I am not able to do this.
Follow the code below:
class ProdutoTest extends TestCase
{
use DatabaseTransactions;
public function testExample()
{
$this->visit('produtos/create')
->type("a", 'nome')
->type(15, 'valor')
->press('Cadastrar')
->seePageIs('produtos/create');
Produto::create([
'nome' => '45',
'valor' => '77'
]) ;
}
}
By what I could understand in this test I am just testing my form, and creating data entered directly into the database.
How do I test my validates?
PS: "The names and organization of the test code are pretty clueless, since I have not set the haha ..."