这个致命错误来自哪里? cakephp phpunit

时间:2015-09-05 16:59:23

标签: testing phpunit cakephp-3.0

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

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

然后,我用

烤了一个帮手
bin/cake bake helper Progress

并在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一起安装的最新版本,则无关紧要。来自何处以及如何解决这个问题?

非常感谢!

1 个答案:

答案 0 :(得分:0)

当你有一个本地的CakePHP安装时,不要使用全局PHPUnit安装,因为你可以看到这会发生冲突,看看堆栈跟踪,你是从/usr/bin/phpunit开始,然后它跳进/home/matthias/www/foobar/vendor/phpunit/phpunit/...

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

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

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