2013-08-22 65 views
2

我想在本地運行OSX 10.8.4和MAMP Pro的PHP 5.4.1上使用phpunit測試。此外,我想用它爲Yii和我的IDE Netbeans。如何在OSX 10.8.4下使用MAMP 2.1.4爲Yii和Netbeans安裝phpunit?

我通過pear或這個通過composer閱讀了一些像這種方法的教程。我甚至試圖看起來像ppl在windows上做 - 它沒有成功。

我的方法總是導致這樣的錯誤

PHP Warning: include(): Failed opening 'PHP_Invoker.php'

PHP Warning: include(): Failed opening 'PHPUnit_Extensions_Database_TestCase.php'

PHP Warning: include(): Failed opening 'PHPUnit_Extensions_Story_TestCase.php'

Failed opening required 'PHPUnit/Extensions/SeleniumTestCase.php'

PHP Fatal error: Class 'CTestCase' not found

或PHPUnit的沒有被發現的。

回答

5

但最後我發現一個教程,給了我一個良好的開端。並且通過一些更多的研究,我發現了上述問題的解決方案。

在這裏,我只是想分享我的步驟,你可以走通的鏈接,讓它運行:)

第一步是按照Zank's tutorial

但是當我做了他的步驟後,我得到了幾個錯誤。因爲您必須安裝的模塊列表不完整。這結束了在下面的錯誤,當我試圖運行一個測試:

PHP Warning: include(): Failed opening 'PHP_Invoker.php'

PHP Warning: include(): Failed opening 'PHPUnit_Extensions_Database_TestCase.php'

PHP Warning: include(): Failed opening 'PHPUnit_Extensions_Story_TestCase.php'

第二步

所以我一派,想通了,我要做以下行太:

pear install phpunit/PHPUnit_Story 

pear install phpunit/DbUnit 

但是'invoker'問題並不那麼容易。因爲當你嘗試

pear install phpunit/PHP_Invoker 

它會導致這樣的錯誤

phpunit/PHP_Invoker requires PHP extension "pcntl"

,並安裝這個擴展MAMP是一個痛苦的屁股。但我在這裏found這個解決方案:

  • went to pear.phpunit.de
  • manually downloaded PHP_Invoker utility class
  • unzipped the file on my daughter's mac (I'm running Windows)
  • put the "Invoker" directory under C:\xampp\php\pear\PHP
  • put the "Invoker.php" file under C:\xampp\php\pear\PHP

爲了您的MAMP安裝的路徑應該是這樣的「/Applications/MAMP/bin/php/php5.4.10/lib」 - 進一步,我不得不重新命名「祈求.php'改爲'PHP_Invoker.php'。

第三步

在命令行現在一切都應該工作 - 寫一個測試,並嘗試一下像贊克的教程步驟一個鏈接。但是Netbeans呢?就像在Zank的教程中,我進入了phpunit路徑,右鍵單擊我的一個測試並選擇「運行測試」 - 錯誤!

PHP Fatal error: Class 'CTestCase' not found

解決方法可以找到here。當你不右鍵點擊'phpunit.xml'所在的文件夾時,會發生這種情況。但要避免這種情況,您可以執行以下操作:

  • 只需右鍵單擊帶有'phpunit.xml'的文件夾即可進行'運行測試'。
  • 或者去下您的測試性能 - > PHPUnit的並勾選「使用XML配置」 +選擇「phpunit.xml」文件

這就是它!

這裏有一些是interessting太鏈接: