2015-02-05 57 views
0

錯誤:PHPUnit的安裝紙爲試圖運行測試時我得到的CakePHP 2.4

Fatal error: Class 'PHPUnit_Util_Diff' not found in Cake/TestSuite/Reporter/CakeHtmlReporter.php on line 267 

this question,並有答案,我需要安裝PHPUnit到3.6.x的避免了丟失的類錯誤。我如何安裝這個現在已過時的版本?

我使用作曲家這樣的嘗試:

composer global require "phpunit/phpunit=3.6.*" 

但我得到以下錯誤

Problem 1 
    - The requested package phpunit/phpunit could not be found in any version, there may be a typo in the package name. 

我試過PEAR用這個命令:

sudo pear install phpunit/PHPUnit-3.6.12 

但我得到這個錯誤:

Attempting to discover channel "phpunit"... 
Attempting fallback to https instead of http on channel "phpunit"... 
unknown channel "phpunit" in "phpunit/phpunit-3.6.12" 
invalid package name/package file "phpunit/phpunit-3.6.12" 
install failed 

我找到了一個答案here,它指向dereuromark's plugin,這已棄用,並建議我使用composer,因爲PHPUnit的pear通道已關閉。更不用說它是3.7.x版本,它缺少我需要的類。所以,我來了整整一圈。

tl; dr 如何爲CakePHP 2.4.x安裝PHPUnit 3.6.x?

更新:我檢查了在最新的CakePHP 2.x版本中使用了相同的類。另外,我應該提到,測試在一個類似的老版本的虛擬機上正確運行,而舊版本的虛擬機安裝了舊的PHPUnit。

+1

這個類在[** 3.7 **](https://github.com/sebastianbergmann/phpunit/blob/3.7.38/PHPUnit/Util/Diff.php)以及[** 3.6 **](https://github.com/sebastianbergmann/phpunit/blob/3.6.12/PHPUnit/Util/Diff.php)分支。 – ndm 2015-02-06 16:18:17

+0

@ndm噢,我完全錯過了......我設法混淆了另一個SO問題(缺失3.7)和我需要的問題。好的,更新會解決這個問題。 – 2015-02-06 21:17:56

回答

0

我設法解決了這個問題。由於我無法安裝廢棄的PHPUnit版本,因此我從Diff類(diff,diffToArray和longestCommonSubsequence)中刪除了缺少的函數,並將它們放入CakeHtmlReporter類中,因爲這是唯一引用它們的類。

之後,我將PHPUnit_Util_Diff::diff更改爲self::diff,即使缺少舊的CSS樣式,它現在也在工作,但我可以忍受這一點。

這不是我問的問題的答案,但也許它可以幫助別人,直到有更好的答案出現。

相關問題