Search⌘ K
AI Features

A First Test

Explore how to set up a basic test in PHPUnit to confirm your testing environment works correctly. This lesson guides you through creating a simple assertion, running tests via the terminal, and interpreting the results to ensure your PHP testing setup is functional and reliable.

We'll cover the following...

Creating a new test file

When first installing a test runner like PHPUnit, it is a good idea to add a very simple test to show that everything is set up correctly. Let’s start by creating a new file called tests/HomepageTest.php. This file should contain the following code:

PHP
<?php
use PHPUnit\Framework\TestCase;
final class HomepageTest extends TestCase
{
/**
* @test
*/
public function phpunit_works(): void
{
self::assertTrue(true);
}
}

Running the test

In the Terminal ...