Creating Our First Browser Test

Let's create our first browser test.

Adding a test for the homepage

In the first real test that we will now create, a GET request will be made to the homepage (/) and it will be verified if the server returns the right page. We need several things for that:

  1. The PHP web server should already be running before we run the test. This will be taken care of by Panther, which is a PHPUnit extension that starts the PHP web server for us before it runs the first test.
  2. We should be able to make that GET request to the server inside our test. This will also be provided by Panther. It offers a client that can navigate the website as if it were a real person (make requests, click on links, fill out forms, set cookies, etc.).
  3. Finally, we should check if the page contains something that we expect to be there. This is provided by the Symfony DomCrawler component, which we can use to inspect the response and make an assertion about it.

Get hands-on with 1200+ tech skills courses.