PHPUnit "Class \"PHPUnit\Framework\TestCase\" not found" in CI
PHP could not find PHPUnit’s TestCase base class. Almost always PHPUnit itself is not installed in CI - typically because composer install --no-dev skipped dev dependencies - or the test bootstrap never loaded Composer’s autoloader.
What this error means
The test run fails immediately with "Class \"PHPUnit\\Framework\\TestCase\" not found" when loading a test class. PHPUnit, a require-dev dependency, is absent from vendor/.
PHP Fatal error: Uncaught Error: Class "PHPUnit\Framework\TestCase" not found
in /app/tests/UserTest.php:7Common causes
Dev dependencies were not installed
composer install --no-dev (common for production builds) skips require-dev, so PHPUnit is never installed. Running tests then fails to find TestCase.
The Composer autoloader was not loaded
A custom bootstrap that does not require vendor/autoload.php, or a missing/empty vendor/, means no class - including PHPUnit’s - can be autoloaded.
How to fix it
Install dev dependencies in the test job
The test stage must install require-dev, even if the deploy stage uses --no-dev.
composer install --no-interaction --prefer-dist
# NOT: composer install --no-dev (skips PHPUnit)Ensure the autoloader is loaded
Point PHPUnit’s bootstrap at Composer’s autoloader.
<!-- phpunit.xml -->
<phpunit bootstrap="vendor/autoload.php">Confirm PHPUnit is present and runnable
composer show phpunit/phpunit
vendor/bin/phpunit --versionHow to prevent it
- Install dev dependencies (no
--no-dev) in any job that runs tests. - Set
bootstrap="vendor/autoload.php"inphpunit.xml. - Run
vendor/bin/phpunit --versionearly to assert PHPUnit is installed.