Level 7
Have you tried this solution https://laracasts.com/discuss/channels/general-discussion/l5-phpunit-testing-the-post-request-with-csrf/replies/13248 ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have the following test:
public function test___armazenar___usuario_autenticado___form_criar_novo_usuario()
{
//
// Setting up
//
$model = $this->criarModel();
$this->app->instance('UsuarioModel', $model);
Session::start();
//
// Visiting and Asserting...
//
$this->actingAs(Usuario::find(1))
->post('usuario', ["_token" => csrf_token()])
->withSession(['status' => trans('geral.sucesso')])
->seePageIs('/')
->seeStatusCode(302)
;
}
I can't fix TokenMismatchException.
Any ideias?
Please or to participate in this conversation.