0
A good day gentlemen.
I am a programming student, at this time I am studying how to perform unit tests using the Laravel 5.3
In my tests I came across the following problem:
My small system only aims to register products in a database. After entering the data in the Formularies send to my function store of my control where I do 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 do tests that capture whether these validates are actually working, but I am not able to perform such a procedure.
Follow the code:
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'
]) ;
}
}
From what I could understand in this test I’m just testing my form, and creating data directly in the database.
How do I test my validates ?
PS:"The names and organization of the test code are quite clueless, since I have not yet set haha..."