Search⌘ K
AI Features

Writing Tests for the Tours: Create a New Tour

Explore how to write automated tests for creating new tours in a PHP application. Learn to use PHPUnit to submit forms with file uploads, handle data reset for consistent test results, and maintain predictable application behavior during testing.

Adding a test for creating a new tour

We will write tests for the tours in a new file called tests/ToursTest.php.

We could start by creating a new tour and verifying if it shows up in the list of tours. We should use the client to go to /create-tour, provide some form data, submit it, and then go to /list-tours to verify that the new tour shows up in the list of tours.

Providing the path to an existing file

We already saw how to submit a form using the test client: we can provide an associative array where the ...