CheckOps
PHPUnit
PHPUnit is the BSD-3-Clause, programmer-oriented testing framework for PHP and an instance of the xUnit architecture, created by Sebastian Bergmann and distributed as a PHAR or via Composer.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
PHPUnit is a programmer-oriented testing framework for PHP and, as its README says, an instance of the xUnit architecture for unit testing frameworks. Created and maintained by Sebastian Bergmann, it has been the foundation of PHP testing for two decades; frameworks such as Laravel and Symfony build their testing tools on top of it, and Pest runs on PHPUnit under the hood.
PHPUnit is distributed as a PHP Archive (PHAR) with all dependencies bundled, or through Composer. It follows a predictable release cycle with a new major version each February, and each major supports the PHP versions current at the time. Version 13.4.6 was released on 2 November 2026.
Modern PHPUnit uses PHP 8 attributes such as #[Test], #[DataProvider], #[CoversClass] and #[Group], replacing older docblock annotations, which were deprecated and then removed in recent majors. The XML configuration file (phpunit.xml) defines test suites, source directories for coverage, PHP settings and extensions.
How it compares: Pest offers a more expressive, closure-based syntax and nicer output while still running on PHPUnit, so the choice is mostly about style. Codeception adds acceptance and functional testing layers, and Behat covers BDD with Gherkin. For mutation testing, Infection works on top of PHPUnit or Pest test suites, and ParaTest runs PHPUnit tests in parallel.
In the quality loop, PHPUnit handles unit and integration testing for PHP applications and libraries, with code coverage via Xdebug or PCOV feeding coverage gates and mutation testing.
The source code is at sebastianbergmann/phpunit on GitHub under the BSD-3-Clause licence, with about 20,100 stars; the most recent commit was on 11 November 2026.
Test isolation options are another useful detail. By default all tests run in one PHP process, which is fast, but #[RunInSeparateProcess] or the processIsolation setting run tests in fresh processes when global state or static caches cannot be reset. PHPUnit also detects risky tests, such as tests without assertions or tests that produce unexpected output, and can be configured to fail on deprecations, notices and warnings, which helps teams prepare for new PHP versions. The TestDox output turns test method names into readable sentences, a lightweight way to document behaviour straight from the suite.
Features
- Assertions: A large set of assertions such as
assertSame,assertEquals,assertCount,assertJsonStringEqualsJsonStringand exception expectations. - Attributes: PHP 8 attributes for tests, data providers, groups, dependencies and coverage metadata.
- Data providers: Feed many data sets into one test method, with named data sets for readable failures.
- Test doubles: Built-in stubs and mock objects via
createStubandcreateMock. - Code coverage: Line, branch and path coverage with Xdebug or PCOV, exported to HTML, Clover, Cobertura and more.
- Configuration:
phpunit.xmldefines suites, source directories, bootstrap files and settings. - Events and extensions: A modern event system lets extensions hook into the test run.
- Reporting: JUnit XML, TeamCity and TestDox output for CI and readable documentation.
Pros
- Foundation of PHP testing: Laravel, Symfony and Pest all build on it.
- Strict by choice: Risky-test detection and fail-on-deprecation settings help teams keep suites clean and prepare for new PHP releases.
- Predictable releases: Clear yearly major release cycle and documented support periods.
- Free to use: Open source under the BSD-3-Clause licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 11 November 2026.
- Community: About 20,100 GitHub stars.
Cons
- Breaking majors: Each yearly major removes deprecated features, so upgrades need attention.
- Verbose syntax: Class-based tests are more verbose than Pest’s closures.
- Coverage needs an extension: Xdebug or PCOV must be installed for coverage.
- Built-in mocks are basic: Many teams prefer Mockery or Prophecy for complex doubles.
Usage and Links (Example)
Install with Composer and write a test:
composer require --dev phpunit/phpunit
<?php
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class PriceTest extends TestCase
{
public static function discounts(): array
{
return ['no discount' => [100, 0, 100], 'ten percent' => [100, 10, 90]];
}
#[Test]
#[DataProvider('discounts')]
public function appliesDiscount(int $price, int $pct, int $expected): void
{
$this->assertSame($expected, Price::apply($price, $pct));
}
}
Run tests with coverage (PCOV or Xdebug installed):
vendor/bin/phpunit --coverage-html coverage/
Practical tips:
- Pin the PHPUnit major in Composer and read the release announcement before upgrading.
- Declare a
<source>element inphpunit.xmlso coverage covers the right directories. - Add ParaTest for parallel runs and Infection for mutation testing once the suite is stable.
Resources:
Pricing
PHPUnit is free and open source under the BSD-3-Clause licence.
Recommended for?
- PHP developers writing unit and integration tests.
- Laravel and Symfony teams, whose testing tools sit on PHPUnit.
- Library authors needing a stable, standard test framework.
- Teams adopting mutation testing, since Infection builds directly on PHPUnit suites.
- Not a fit if your team prefers a more expressive syntax; Pest offers that on the same engine.
Conclusion
PHPUnit is the cornerstone of PHP testing: mature, well documented and the engine behind most PHP testing tools.
Keep up with its yearly majors, add coverage and mutation testing, and it will serve PHP projects of any size.
Compare
CheckOps pages that put PHPUnit next to related tools. There is no paid placement on these lists.
Roundups
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with PHPUnit side by side.
PPestPest is an MIT-licensed PHP testing framework built on PHPUnit with an expressive, closure-based API; Pest 5 (PHP 8.4+, PHPUnit 13) adds the Tia engine, an agent plugin, evals, PHPStan and Rector support.Compare with PHPUnit
CCodeceptionCodeception is an MIT-licensed full-stack PHP testing framework covering unit, functional, API and acceptance tests in one tool, with modules for WebDriver, REST, databases and frameworks such as Laravel and Symfony.Compare with PHPUnit
BBehatBehat is an MIT-licensed behaviour-driven development framework for PHP that runs Gherkin feature files against PHP context classes, often paired with Mink for browser testing.Compare with PHPUnit
IInfectionInfection is a BSD-3-Clause AST-based mutation testing framework for PHP that measures test effectiveness with Mutation Score Indicator metrics, supporting PHPUnit, Pest, Codeception and phpspec.Compare with PHPUnit
MMockeryMockery is a BSD-3-Clause mock object framework for PHP with a fluent, readable expectation API, usable with PHPUnit, Pest and other frameworks, and bundled with Laravel's testing tools.Compare with PHPUnit
Pphpspecphpspec is an MIT-licensed specification-oriented BDD toolset for PHP that helps you design classes by writing specs first, with code generation for missing classes and methods.Compare with PHPUnit