簡體   English   中英

PHPUnit CodeIgniter生成夾具PHP致命錯誤:未找到類“ PHPUnit_Framework_TestCase”

[英]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生成固定裝置和php generate.php固定裝置時:

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文件中的類,或者至少它們的順序不正確? 有趣的是,它可以很好地運行測試,但不能生成固定裝置。

另外,我還使用composer安裝了phpunit,因此我也安裝了/ www / test / vendor / 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的類。 我不太確定為什么在項目名稱空間中找不到它時為什么不嘗試從“基礎”中加載它(這很可能是由於我自己的自動加載器出錯)。

我知道這是一個古老的問題,但是我會把它留在這里,以防可能對某人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM