PHPUnit CodeIgniter生成夹具PHP致命错误:Class';PHPUnit_Framework_T


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

所以安装了PHPUnit和CodeIgniter:

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

无法下载PEAR,因为它已被弃用。所以不得不下载phpunit phar文件:

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

所以能够让一些测试正常运行。将我的phpunit.phar移到/usr/local/bin并在测试目录上运行

php /usr/local/bin/phpunit.phar

所有测试都运行正常。但是当我尝试运行php generate fixtures和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

它似乎没有在phar文件中找到类,或者至少它们的顺序不正确?有趣的是,它可以很好地运行测试,但不能生成fixture。

此外,我还使用composer安装了phpunit,所以我也安装了/www/test/vvendor/bin/phpunit。

如有任何帮助,我们将不胜感激。

尽管我没有使用CodeIgniter,但我的代码中也遇到了同样的问题。尝试运行测试将导致错误消息:

未找到类"PHPUnit_Framework_TestCase"

值得一提的是,我在测试类声明中添加了一个反斜杠,从而解决了这个问题。

// 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

这似乎与名称空间和phpunit中内置的自动加载器有关。我有自己的项目代码自动加载器,它似乎试图从我的代码中加载phpunit的类。我真的不知道为什么它在项目命名空间中找不到它时,却没有尝试从"base"加载它(这很可能是由于我自己的自动加载程序出现故障)。

我知道这是一个老问题,但我会把它留在这里,以防它对某个地方有帮助。