Summer Sale! All accounts are 50% off this week.

Mick79's avatar

How to submit form and move to next page with PHPUnit

I am in full on test mode at the moment but struggling.

I have a multi page user journey that I am looking to test. Here's what I have

$response->assertViewIs('view1');
  $this->post('/create-new-item', [
            'name' => 'Test',
        ]);
$response->assertViewIs('view2);

So submit the form on view1 which should then take you to view2 but this isn't happening. it's staying on view 1. What am I doing wrong?

Laravel 9.

EDITED TO ADD

Even if someone could point me at the official docs. I looked hard and couldn't find them for navigating forms in L9.

0 likes
2 replies
martinbean's avatar
Level 80

@mick79 You shouldn’t be trying to perform multiple requests in a single test; a test isn’t a web browser. Instead, execute a request and then make assertions about the response. If you expect to be redirected, then assert that:

$response = $this->post('/page-one', $data);

$response->assertRedirect('/page-two');
1 like

Please or to participate in this conversation.