【问题标题】:PHPUnit intallation for CakePHP 2.4CakePHP 2.4 的 PHPUnit 安装
【发布时间】:2015-04-06 00:39:12
【问题描述】:

我在尝试运行测试时遇到的错误:

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

根据this question 和那里的答案,我需要安装 PHPUnit 3.6.x 以避免缺少 Class 错误。如何安装这个现已弃用的版本?

我试过像这样使用作曲家:

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 的梨形通道已关闭。更不用说它是 3.7.x 版本,它缺少我需要的类。所以,我绕了一圈。

tl;dr 如何为 CakePHP 2.4.x 安装 PHPUnit 3.6.x?

更新:我检查了在最新的 CakePHP 2.x 版本中使用了相同的类。另外,我应该提到测试在安装了较旧 PHPUnit 的类似但较旧的 VM 上正确运行。

【问题讨论】:

  • 类在3.73.6 分支中都很好。
  • @ndm 哦,伙计,我完全错过了......我设法将另一个 SO 问题缺失的课程(在 3.7 中缺失)与我需要的问题混为一谈。好的,更新会解决这个问题。

标签: cakephp phpunit composer-php


【解决方案1】:

TL;DR:PHPUnit 3.6 不再可供安装。

PHPUnit 3.6 仅作为 PEAR 包提供。 The PEAR Channel that hosted PHPUnit, pear.phpunit.de, was shut down on December 31, 2014.

【讨论】:

  • 感谢您的回复!我看到即使 3.7 也有我需要的东西,我不应该盲目地遵循其他 SO 问题/答案......
【解决方案2】:

我设法解决了这个问题。由于我无法安装已弃用的 PHPUnit 版本,因此我从 Diff 类(diff、diffToArray 和longestCommonSubsequence)中取出缺少的函数并将它们放入 CakeHtmlReporter 类,因为这是唯一引用它们的函数。

之后,我将PHPUnit_Util_Diff::diff 更改为self::diff,现在它可以工作了,尽管它缺少旧的 CSS 样式,但我可以忍受。

这不是我所问问题的答案,但也许它可以帮助其他人,直到出现更好的答案。

【讨论】:

    猜你喜欢
    • 2014-12-22
    • 2014-04-20
    • 2012-06-17
    • 2023-04-04
    • 2017-06-22
    • 2018-10-09
    • 2017-12-22
    • 2011-09-10
    • 1970-01-01
    相关资源
    最近更新 更多