-1
Dear, do a lot of research and I haven’t found the solution to what I need.
I want to take a test of my application, which in this case is a register of countries. The application works perfectly.
The Controller calls the correct Routes, called by the correct commands (GET, POST, PATCH, DELETE): - view -> parents.view - Insert -> pais.Insert - store -> parents.store - Edit -> parents.Edit - update -> parents.update - delete -> parents.delete
I created the test routine as below:
public function testHTML() : void {
// inclusão normal
$registro = [
'codpais' => 1,
'nompais' => 'Brasil',
'sigpais' => 'BRA',
'_token' => csrf_token()
];
// chamo o evento post, com os dados
$response = $this->call( 'POST', 'pais', $registro);
$response->assertStatus(302);
// pesquiso se o registro está no banco.
// Caso contrário quero retornar um erro
// Até aqui aparentemente funcionou
$pesq = Pais::find($registro['codpais']);
if ($pesq->codpais != $registro['codpais']) {
throw new Exception('Erro no cadastro de país.');;
}
// quero fazer um inclusão do mesmo registro
// mas quero saber o erro que foi retornado
// mas recebo o status = 302.
$response = $this->call( 'POST', 'pais', $registro);
print "\nPasso 2 ->" . $response->getStatusCode() . "\n";
}
I wanted to test if there was an error message, which I sent via Session::flash, inside the Controller. That’s possible?
How do you do this test? Several examples I see have to mount an API, where I return the registry via json, but I want to test the user application.
Do I want the impossible?
On hold Tonico Bittencourt