PHPUnit / DUSK testing routes that contain ID's

86 views Asked by At

I am working on my first DUSK (which is based on PHPUnit) tests. I am creating a customer and going to their show page. The UUID is created upon save in the database, and is used as part of the route from that point on. Routes can handle unknown uuid because they have a wildcard syntax.

Route::get('/customer/{uuid}/show', 'App\Http\Controllers\CustomerController@show')->name('customer.show');

Does PHPUnit/DUSK have something similar?

This is what I have tired but the assert fails.

   ...

   ->press('NEW CUSTOMER')
   ->waitForLocation('/customer/create')
   ->type('first_name', 'John')
   ->type('last_name', 'Doe')
   ->type('date_of_birth', '03/03/1933')
   ->press('SAVE')
   ->waitForLocation('/customer/{uuid}/show')
   ->assertPathIs('/customer/{uuid}/show');

TLDR: Does PHPUnit allow wildcards in route assertions?

1

There are 1 answers

0
Ilia Yatsenko On

How do you suppose it to work? Client have to know the UUID in some way. There are 3 options:

  1. Return UUID of newly created customer in the response body.
  2. Return HTTP 301 response from server with the location of created resource, i.e. just redirect client to the new customer's page.
  3. And the last one - to generate UUID on client side, instead than generating it on backend. This way client will be automatically aware of the UUID of new customer.