2015-09-05 32 views
1

我用composer創建了一個cakephp3項目。這是從何而來的致命錯誤? cakephp phpunit

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

然後,我烤了一個幫手與

bin/cake bake helper Progress 

而且在CakePHP的testing tutorial 目錄切換和執行phpunit copypasted幫手,例如說

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安裝的最新版本,則需要考慮。這是從哪裏來的,以及如何解決這個問題?

非常感謝!

回答

0

不要使用全局的PHPUnit安裝,當你有一個是本地的CakePHP安裝,你可以看到這會發生衝突,看看堆棧跟蹤,你在/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的應用骨架composer.json設置爲true)似乎並沒有幫助在這裏,作爲作曲家會選擇[email protected]時不指定你自己的一個版本(即使它只是*)。

+0

Works perfekt!謝謝。 –

+0

@MatthiasMoritz幾個小時前我剛剛看到[** CakePHP更新了**](https://github.com/cakephp/cakephp/pull/7355)以支持PHPUnit的更改。不過,如果你真的沒有特別的理由來使用不穩定的5.x分支,那麼使用穩定的4.x分支最好。 – ndm

相關問題