【问题标题】:Where comes this Fatal error from? cakephp phpunit这个致命错误来自哪里? cakephp phpunit
【发布时间】:2015-09-05 16:59:22
【问题描述】:

我用 composer 创建了一个 cakephp3 项目。

composer create-project --prefer-dist cakephp/app foobar

然后,我烘焙了一个助手

bin/cake bake helper Progress

并将 helper-example 复制粘贴到 cakephp testing tutorial 切换目录并执行phpunit说

PHP Fatal error:  Class Cake\TestSuite\Fixture\FixtureInjector contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (PHPUnit_Framework_TestListener::addWarning) in /home/matthias/www/isbn.localhost/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php on line 173
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:42
PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:138
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:186
PHP   5. PHPUnit_TextUI_TestRunner->handleConfiguration() /home/matthias/www/foobar/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:145
PHP   6. require_once() /home/matthias/www/foobar/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:771

Fatal error: Class Cake\TestSuite\Fixture\FixtureInjector contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (PHPUnit_Framework_TestListener::addWarning) in /home/matthias/www/foobar/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php on line 173

Call Stack:
    0.0001     225152   1. {main}() /usr/bin/phpunit:0
    0.0031     515440   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:42
    0.0031     516064   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:138
    0.6384    6931096   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:186
    0.6384    6932312   5. PHPUnit_TextUI_TestRunner->handleConfiguration() /home/matthias/www/foobar/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:145
    0.6458    7043088   6. require_once('/home/matthias/www/foobar/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php') /home/matthias/www/foobar/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:771

使用全局安装的 phpunit 4.2.6 还是使用 composer 安装的最新版本都没有关系。这是从哪里来的,我该如何解决?

非常感谢!

【问题讨论】:

    标签: testing phpunit cakephp-3.0


    【解决方案1】:

    当你有一个本地的 CakePHP 安装时,不要使用全局 PHPUnit 安装,你可以看到这会发生冲突,查看堆栈跟踪,你从 /usr/bin/phpunit 开始,然后它跳转到 @ 987654324@.

    话虽如此,您似乎在您的 CakePHP 应用程序中安装了“错误”的 PHPUnit 版本,上述方法 addWarning 是在 PHPUnit 5.1 alpha 中引入的!整个 5.x 分支还不稳定,CakePHP 还不兼容 刚刚updated(尚未发布)支持更改,所以现在你应该安装稳定4.x 分支,比如

    $ composer require --dev phpunit/phpunit:~4.0
    

    不幸的是,prefer-stable 选项(在 CakePHP 应用程序框架 composer.json 中默认设置为 true)在这里似乎没有帮助,因为 Composer 在未指定版本时会选择 ~5.1@dev你自己的(即使只是*)。

    【讨论】:

    • 工作完美!谢谢。
    • @MatthiasMoritz 几个小时前我刚刚看到 CakePHP was updated 支持 PHPUnit 更改。不过,如果你真的没有特定的理由使用不稳定的 5.x 分支,你最好使用稳定的 4.x 分支。
    猜你喜欢
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 2021-11-14
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    相关资源
    最近更新 更多