今天在學習Yii Framework中單元測試時,總是在運行“phpunit unit/DBTest.php”命令的時候出現以下錯誤,
PHP Notice: Please no longer include "PHPUnit/Framework.php". in /usr/share/php/PHPUnit/Framework.php on line 50
但自己是按照文檔上說的安裝了PHPUnit包了呀,後來發現想起來安裝過程中由於家裡網絡問題其中一個依賴包出錯了,但是別的包都提示安裝成功了,然後自己是把那個失敗的包PHP_CodeCoverage重新安裝的,然後運行unit的時候就出現了上面的錯誤,於是自己慢慢摸索,然後做了以下步驟後,問題總算被解決了。
1. 打開pear的auto_discover選項
view plaincopy to clipboardprint?$ sudo pear config-set auto_discover 1
$ sudo pear config-set auto_discover 12. 檢查已經安裝的phpunit和其依賴包
view plaincopy to clipboardprint?$ sudo pear list -a
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
DbUnit 1.0.3 stable
File_Iterator 1.2.6 stable
PHPUnit 3.5.15 stable
PHPUnit_MockObject 1.0.9 stable
PHPUnit_Selenium 1.0.3 stable
PHP_CodeCoverage 1.0.5 stable
PHP_Timer 1.0.2 stable
PHP_TokenStream 1.0.1 stable
Text_Template 1.1.0 stable
$ sudo pear list -a
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
DbUnit 1.0.3 stable
File_Iterator 1.2.6 stable
PHPUnit 3.5.15 stable
PHPUnit_MockObject 1.0.9 stable
PHPUnit_Selenium 1.0.3 stable
PHP_CodeCoverage 1.0.5 stable
PHP_Timer 1.0.2 stable
PHP_TokenStream 1.0.1 stable
Text_Template 1.1.0 stable3. 卸載所有pear.phpunit.de channel下安裝的和phpunit相關的包,這裡有先後順序,卸載的時候會有提示
view plaincopy to clipboardprint?$ sudo pear uninstall PHPUnit
$ sudo pear uninstall PHPUnit_MockObject
...
$ sudo pear uninstall PHPUnit
$ sudo pear uninstall PHPUnit_MockObject
...4. 重新安裝PHPUnit包
view plaincopy to clipboardprint?$ sudo pear install pear.phpunit.de/PHPUnit
$ sudo pear install pear.phpunit.de/PHPUnit5. 再次運行“phpunit unit/DBTest.php”,問題解決。
作者“kongxx的專欄”