Creating Our First Browser Test
Let's create our first browser test.
We'll cover the following
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:
- 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.
- 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.). - 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 1400+ tech skills courses.