PHPUnit is the standard testing framework for PHP applications, providing developers with tools to write and automate unit tests. Whether you are building Laravel applications, WordPress plugins, Symfony bundles, or custom PHP projects, PHPUnit helps ensure your code behaves correctly before deployment. This guide covers installing PHPUnit on Fedora Linux, with multiple versions available to match your PHP environment and project requirements.
PHPUnit Version and PHP Requirements
Before installing PHPUnit, understanding the version compatibility matrix helps you choose the right release. Each PHPUnit major version requires a specific minimum PHP version, and newer PHPUnit releases drop support for older PHP versions. Fedora 43 ships with PHP 8.4 by default, which supports all currently maintained PHPUnit versions.
| PHPUnit Version | PHP Requirement | Support Status | Package Name |
|---|---|---|---|
| PHPUnit 12 | PHP 8.3+ | Active (bug fixes until Feb 2027) | phpunit12 |
| PHPUnit 11 | PHP 8.2+ | Active (bug fixes until Feb 2026) | phpunit11 |
| PHPUnit 10 | PHP 8.1+ | Life Support (PHP compatibility only) | phpunit10 |
| PHPUnit 9 | PHP 7.3+ | End of Life | phpunit9 |
| PHPUnit 8 | PHP 7.2+ | End of Life | phpunit8 |
For detailed version support timelines, see the official PHPUnit supported versions page. New projects should use PHPUnit 12 or 11 for active bug fixes; legacy projects may require older versions for compatibility with existing test suites.
Choose Your PHPUnit Installation Method
Fedora provides PHPUnit packages through multiple channels. The default repositories include all major versions, while the Remi repository offers slightly newer patch releases for users who need the absolute latest fixes.
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| DNF (Fedora Repos) | Fedora Updates | Distribution default | Automatic via DNF upgrades | Most users who want stable, tested packages |
| Remi Repository | Remi RPM | Latest patch releases | Automatic via DNF upgrades | Users needing the newest bug fixes immediately |
For most users, the Fedora repository method is recommended because it requires no additional setup and provides well-tested packages that integrate cleanly with the distribution. The Remi repository offers marginally newer patch versions (for example, 10.5.60 vs 10.5.59) but requires adding a third-party source.
Install PHPUnit from Fedora Repositories
This method uses packages from Fedora’s official repositories, which are maintained by the Fedora PHP SIG (Special Interest Group) and receive updates through standard system upgrades.
Step 1: Update Your System
Before installing new packages, refresh your system to ensure all repositories are synchronized and existing packages are current:
sudo dnf upgrade --refresh
Step 2: Install PHPUnit
Next, install your preferred PHPUnit version using DNF. Each major version has a dedicated package with a version-numbered command:
PHPUnit 12 (recommended for new projects):
sudo dnf install phpunit12
For PHP 8.2+ projects, use version 11:
sudo dnf install phpunit11
For PHP 8.1+ projects, use version 10:
sudo dnf install phpunit10
You can install multiple PHPUnit versions simultaneously. Each version installs a separate binary (
phpunit12,phpunit11,phpunit10, etc.), allowing you to run different versions for different projects. Aphpunitsymlink points to the newest installed version.
Step 3: Verify the Installation
Finally, confirm PHPUnit installed correctly by checking the version. The output confirms the tool is accessible and shows the PHP runtime it will use:
phpunit12 --version
Expected output:
PHPUnit 12.5.4 by Sebastian Bergmann and contributors.
You can also verify which binary the phpunit symlink points to:
ls -la /usr/bin/phpunit
lrwxrwxrwx 1 root root 9 Dec 15 00:00 /usr/bin/phpunit -> phpunit12
Install PHPUnit from Remi Repository
The Remi repository, maintained by Remi Collet (a Fedora PHP packager), provides the latest PHPUnit patch releases. This method is useful if you need specific bug fixes that have not yet propagated to Fedora’s official repositories.
Step 1: Add the Remi Repository
If you have not already configured the Remi repository, add it using this command. The $(rpm -E %fedora) expression automatically detects your Fedora version:
sudo dnf install https://rpms.remirepo.net/fedora/remi-release-$(rpm -E %fedora).rpm -y
For complete Remi repository setup including GPG key verification, PHP version module management, and troubleshooting common configuration issues, see our Remi RPM repository guide for Fedora.
Step 2: Install PHPUnit from Remi
Once Remi is configured, install PHPUnit with the --enablerepo=remi flag to pull packages from the Remi repository:
sudo dnf --enablerepo=remi install phpunit12
Replace phpunit12 with phpunit11, phpunit10, phpunit9, or phpunit8 depending on your requirements.
Step 3: Verify the Installation
Confirm the Remi version installed correctly:
phpunit12 --version
PHPUnit 12.5.4 by Sebastian Bergmann and contributors.
Optional: Switch PHP Versions with Remi Modules
Fedora 43 ships with PHP 8.4, which supports all PHPUnit versions. However, if your project requires a specific PHP version, Remi provides modular PHP streams. First, list available PHP versions:
dnf module list php
Name Stream Profiles Summary php remi-7.4 common [d], devel, minimal PHP scripting language php remi-8.0 common [d], devel, minimal PHP scripting language php remi-8.1 common [d], devel, minimal PHP scripting language php remi-8.2 common [d], devel, minimal PHP scripting language php remi-8.3 common [d], devel, minimal PHP scripting language php remi-8.4 common [d], devel, minimal PHP scripting language php remi-8.5 common [d], devel, minimal PHP scripting language
To enable a specific PHP version (for example, PHP 8.3 for PHPUnit 12 compatibility testing):
sudo dnf module reset php
sudo dnf module enable php:remi-8.3
Most users do not need to switch PHP versions. Only use this if your project specifically requires a different PHP release than the system default. For PHP installation details, see our PHP on Fedora guide.
Create and Run a Test Case
With PHPUnit installed, you can create a simple test case to verify everything works correctly. This example demonstrates the basic testing workflow.
Create the Test File
Create a new PHP file with a test class. The class must extend PHPUnit\Framework\TestCase and contain methods prefixed with test:
nano ~/ExampleTest.php
Add the following test case:
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class ExampleTest extends TestCase
{
public function testAddition(): void
{
$this->assertSame(2, 1 + 1);
}
public function testStringContains(): void
{
$this->assertStringContainsString('Hello', 'Hello World');
}
}
Save the file by pressing Ctrl+O, then Enter, then exit with Ctrl+X.
Run the Tests
Execute the test file with PHPUnit. The framework automatically discovers test methods and reports results:
phpunit ~/ExampleTest.php
Expected output showing both tests passed:
PHPUnit 12.5.4 by Sebastian Bergmann and contributors. Runtime: PHP 8.4.16 .. 2 / 2 (100%) Time: 00:00.002, Memory: 8.00 MB OK (2 tests, 2 assertions)
The dots (..) represent successful tests. For a more detailed view, use the --testdox flag:
phpunit --testdox ~/ExampleTest.php
PHPUnit 12.5.4 by Sebastian Bergmann and contributors. Runtime: PHP 8.4.16 .. 2 / 2 (100%) Time: 00:00.002, Memory: 8.00 MB Example ✔ Addition ✔ String contains OK (2 tests, 2 assertions)
Remove PHPUnit
If you no longer need PHPUnit, remove it along with any unused dependencies. DNF automatically cleans up packages that were installed solely as dependencies.
To remove a specific PHPUnit version:
sudo dnf remove phpunit12
Alternatively, to remove all installed PHPUnit versions at once:
sudo dnf remove phpunit*
Optional: Remove the Remi Repository
If you added the Remi repository solely for PHPUnit and no longer need it, you can remove it from your system:
The Remi repository provides many PHP-related packages beyond PHPUnit, including newer PHP versions, Redis, and other extensions. Only remove it if you are certain no other installed packages depend on this repository. Removing Remi while other packages still require it may cause update conflicts or leave orphaned packages.
sudo dnf remove remi-release
After removal, verify PHPUnit is no longer installed:
phpunit --version
bash: phpunit: command not found
Troubleshooting
Class Not Found Errors
If PHPUnit reports that it cannot find test classes, the error typically looks like this:
PHPUnit 12.5.4 by Sebastian Bergmann and contributors. No tests executed!
This usually means your test file does not follow PHPUnit’s naming conventions. Ensure your test classes end with Test (for example, ExampleTest), and test methods must begin with test (for example, testAddition). Additionally, confirm the file is readable and the class name matches the filename.
PHP Version Mismatch
If PHPUnit fails to run with errors about unsupported PHP versions, you may see output similar to:
This version of PHPUnit requires PHP >= 8.3. You are using PHP 8.1.27.
To check your current PHP version:
php --version
PHP 8.4.16 (cli) (built: Dec 16 2025 16:03:34) (NTS gcc x86_64) Copyright (c) The PHP Group Built by Fedora Project Zend Engine v4.4.16, Copyright (c) Zend Technologies
Compare the output with the version matrix at the beginning of this guide. If your PHP version is too old for your chosen PHPUnit release, either upgrade PHP using Remi modules or install an older PHPUnit version that matches your PHP release.
Command Not Found
If running phpunit returns “command not found” after installation, first verify the package is actually installed:
rpm -q phpunit12
Expected output if installed correctly:
phpunit12-12.5.4-1.fc43.noarch
If the package is installed but the command remains unavailable, check that /usr/bin is in your PATH:
echo $PATH | grep -o '/usr/bin'
This should output /usr/bin. If missing, add it to your shell profile or start a new terminal session.
Conclusion
PHPUnit is now configured on your Fedora system with access to versions 8 through 12. You can run tests against existing projects, develop new test suites with the --testdox flag for readable output, or switch between versions depending on project requirements. For comprehensive testing documentation including mocks, data providers, and code coverage, see the official PHPUnit documentation.