Flawyte Flawyte - 2 years ago 186
PHP Question

PHPUnit can't found the "TestCase" class

To run my tests using the project's PHPUnit I do the following :

php vendor/bin/phpunit tests/SomeClassTest.php
which works fine given the following class declaration :

class SomeClassTest extends PHPUnit_Framework_TestCase {
public function test_someMethod() {}

But it fails when I do this :

use PHPUnit\Framework\TestCase;

class SomeClassTest extends TestCase {
public function test_someMethod() {}

I get
PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found

Answer Source

Class TestCase exists since PHPUnit 5.4. You can see it on github if you set 5.3 tag (look for ForwardCompatibility folder) or you can compare doc for 5.3 and 5.4 in the 2. Writing Tests for PHPUnit section where it says:

"ClassTest inherits (most of the time) from PHPUnit_Framework_TestCase." for PHPUnit 5.3


"ClassTest inherits (most of the time) from PHPUnit\Framework\TestCase." for PHPUnit 5.4

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download