简体   繁体   中英

PHPUnit CodeIgniter Generate Fixtures PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found

So have PHPUnit and CodeIgniter installed:

http://d.hatena.ne.jp/Kenji_s/20120117/1326763908

Couldn't download the PEAR as its been deprecated. So had to download the phpunit phar file:

http://phpunit.de/manual/4.0/en/installation.html#installation.phar

So was able to get some tests to run properly. Moved my phpunit.phar to /usr/local/bin and ran on the tests dir:

php /usr/local/bin/phpunit.phar

And all the tests ran correctly. But when i tried to run the php generate fixtures and php generate.php fixtures:

PHP Fatal error:  Class 'PHPUnit_Framework_TestCase' not found in  /www/test/application/third_party/CIUnit/libraries/CIUnitTestCase.php on line 15

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /www/test/application/third_party/CIUnit/libraries/CIUnitTestCase.php on line 15

Seems like its not finding the classes inside the phar file or at least they are not in the correct order? What is funny is that it runs the tests fine but not the generate fixtures.

Additionally i also installed using composer the phpunit so i have a /www/test/vendor/bin/phpunit installed as well.

Any help would be appreciated.

I had the same problem in my code, although I do not use the CodeIgniter. Trying to run tests would result in the error message:

Class 'PHPUnit_Framework_TestCase' not found

For what it's worth I had this fixed by adding a backslash to my test class declaration.

// Before
namespace IMAVendor\Super\Duper;

class MyClassTest extends PHPUnit_Framework_TestCase

// After
namespace IMAVendor\Super\Duper;

class MyClassTest extends \PHPUnit_Framework_TestCase
                          ^
                Added this backslash here

This seems to have something to do with namespaces and the autoloader that's built in phpunit. I have my own autoloader for the project code and it seems that it was trying to load the phpunit's classes from my code. I'm not really sure why it didn't try to load it from the 'base' when it wasn't able to find it in the projects namespace (This may very well be due to my own autoloader being faulty).

I know this is an old question, but I'll just leave this here in case it may help somebody somewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM