Development Workflow

PHPUnit 12: Project Setup and Test Discovery

Configure PHPUnit for a PHP project and make test discovery repeatable across developer machines and CI.

Overview

PHPUnit is a widely used test framework for PHP. Its configuration, supported PHP versions and command-line options vary by major release, so select a PHPUnit version compatible with the PHP runtime used by the project.

Install as a development dependency

Use Composer to add a compatible PHPUnit release as a development dependency. Keep test tooling out of production installation where appropriate, and commit composer.lock so contributors and CI install the same dependency graph.

Organize tests

A common layout keeps application code under src/ and tests under tests/. Configure test suites and source directories explicitly in phpunit.xml or phpunit.xml.dist.

Run consistently

Use the project's Composer script as the documented entry point, for example composer test. This avoids every developer inventing different command flags.

Verify the configuration

Run PHPUnit from a clean checkout and confirm that the expected tests are discovered. Consult the official PHPUnit manual for the version installed; do not copy configuration attributes from a different major version without checking compatibility.

Share this page Help other developers discover this resource.