Skip to content

PHPUnit

Clio Brichaut edited this page Jan 14, 2023 · 1 revision

What is it?

"PHPUnit is a programmer-oriented testing framework for PHP." [source]

Setup

  1. Install the package with ./vendor/bin/sail composer require phpunit/phpunit --dev (in wsl terminal) or composer require phpunit/phpunit --dev (in the php container).

  2. Create the /app/.env.testing file containing the details of the testing environment, including the test database:

APP_ENV=testing

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=testing
DB_USERNAME=sail
DB_PASSWORD=password
  1. Use the example tests (in /app/app/tests/Unit/ExampleTest.php and /app/app/tests/Feature/ExampleTest.php) to create your tests.

Usage

Run the tests with ./vendor/bin/sail artisan test (or an alternative command).

The output should look like this:

Using the artisan command
image
Using the phpunit command
image

Clone this wiki locally