Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Class resolve issue for classes in the same directory when running PHPUnit test cases

I installed PHPUnit and my Test class looks like this:

require_once 'PHPUnit/Framework/TestCase.php';

class Test extends PHPUnit_Framework_TestCase {...}

When I execute the PHP script in Eclipse, I get the following error:

Fatal error: Class 'PHPUnit_Framework_Assert' not found in .../PEAR/PHPUnit/Framework/TestCase.php on line 99

So I created a general PHP classloading test:

  • A.php and B.php in the same directory

A.php:

class AA {}

B.php:

class BB extends AA {}
new BB();

When executing the PHP script B.php I get the same error:

Fatal error: Class 'AA' not found in .../B.php on line 2

There must be an option for PHP to be able to resolve these classes otherwise PHPUnit could not work. Any ideas?

Thank you.

like image 781
user498380 Avatar asked Nov 15 '11 17:11

user498380


1 Answers

You should not be loading / require

require_once 'PHPUnit/Framework/TestCase.php';

in your tests at all. The normal phpunit runner should be able to figure that out.

Usually IDEs should care about setting phpunit up properly (or invoking it properly) but if that doesn't work out requiring

require_once 'PHPUnit/Autoload.php';

That should do the trick then as this is whats needed to make PHPUnit working

like image 55
edorian Avatar answered Sep 20 '22 21:09

edorian