Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...?
The PHPUnit documentation says used to say to include/require PHPUnit/Framework.php, as follows:
require_once ('PHPUnit/Framework/TestCase.php');
UPDATE
As of PHPUnit 3.5, there is a built-in autoloader class that will handle this for you:
require_once 'PHPUnit/Autoload.php';
Thanks to Phoenix for pointing this out!
Class 'PHPUnit_Framework_TestCase' not found
There is a difference between namespace structure between PHPUnit
<6 and PHPUnit
6.
You may consider the following solution for backward compatibility:
// backward compatibility
if (!class_exists('\PHPUnit\Framework\TestCase') &&
class_exists('\PHPUnit_Framework_TestCase')) {
class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
}
The old PHPUnit
versions use \PHPUnit_Framework_TestCase
but the new one uses \PHPUnit\Framework\TestCase
. With the backward compatibility applied you can use the class name that is compatible with the new version of PHPUnit
(i.e. \PHPUnit\Framework\TestCase
) and it is going to work also with older versions.
Update
In order to cover support for PHP 5.3 you have to remove a \
character before the alias class, i.e.
class_alias('\PHPUnit_Framework_TestCase', 'PHPUnit\Framework\TestCase');
Fatal error: Class 'PHPUnit_Framework_TestCase' not found
Are you trying to run the test in a web browser? This confused me for a while. PHPUnit tests are written to be run on the command line.
PHP unit - Class 'PHPUnit_Framework_TestCase' not found
You appear to have one, or both of two problems.
- Not using Composer, This will also provide a vendor/autoload.php file, that will automatically pull in any files that have been included via the composer.json file.
- The latest version of PHPunit (v>6.0) no longer uses the long class names. the still-supported v5+ does though.
The recommended mechanism to install PHPunit 5.7 is:
composer require --dev phpunit/phpunit:^5.7
Alternatively, it can be downloaded as a single phpunit.phar that can be run much as any other PHP script.
Related Topics
Rest API Authorization & Authentication (Web + Mobile)
Accessing Laravel .Env Variables in Blade
PHP Cli Getting Input from User and Then Dumping into Variable Possible
Calculate Total Seconds in PHP Dateinterval
Use One Laravel Migrations Table Per Database
Create Image from Url Any File Type
Show/Hide Fields Depending on Select Value
PHP PHP_Network_Getaddresses: Getaddrinfo Failed: No Such Host Is Known
MySQL Select from Tables Based on Multiple Rows
How to Run Single Test Method with PHPunit
Correct Indentation of HTML and PHP Using Vim
Adding Three Months to a Date in PHP
Php/Symfony/Doctrine Memory Leak
How to Parse a CSV File to Grab the Column Names First Then the Rows That Relate to It