2011-12-05 41 views
12

我想單元測試使用PHPUnit 3.6.4的Zend Framework應用程序。我在我的命令提示符下嘗試此命令時出現以下錯誤。Zend_Test_PHPUnit_Constraint_DomQuery :: evaluate()的聲明應該與PHPUnit_Framework_Constraint :: evaluate()的聲明兼容

C:\xampp\htdocs\testsample\tests>phpunit --configuration phpunit.xml 
PHPUnit 3.6.4 by Sebastian Bergmann. 

Configuration read from C:\xampp\htdocs\testsample\tests\phpunit.xml 

←[31;1mE←[0m←[31;1mE←[0m.. 

Time: 0 seconds, Memory: 10.00Mb 

There were 2 errors: 

1) IndexControllerTest::testIndexWithMessageAction 
Declaration of Zend_Test_PHPUnit_Constraint_DomQuery::evaluate() should be compatible   
with that of PHPUnit_Framework_Constraint::evaluate() 

C:\xampp\htdocs\hive\library\Zend\Test\PHPUnit\Constraint\DomQuery.php:40 
C:\xampp\htdocs\hive\library\Zend\Test\PHPUnit\ControllerTestCase.php:512 
C:\xampp\htdocs\testsample\tests\application\controllers\IndexControllerTest.php 
:14 
C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:925 
C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:787 
C:\xampp\php\PEAR\PHPUnit\Framework\TestResult.php:649 
C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:734 
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:772 
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:745 
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:705 
C:\xampp\php\PEAR\PHPUnit\TextUI\TestRunner.php:325 
C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php:187 
C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php:125 
C:\xampp\php\phpunit:44 

2) IndexControllerTest::testIndexNoMessageAction 
Declaration of Zend_Test_PHPUnit_Constraint_ResponseHeader::evaluate() should be 
compatible with that of PHPUnit_Framework_Constraint::evaluate() 

C:\xampp\htdocs\hive\library\Zend\Test\PHPUnit\Constraint\ResponseHeader.php:400 

C:\xampp\htdocs\hive\library\Zend\Test\PHPUnit\ControllerTestCase.php:769 
C:\xampp\htdocs\hive\library\Zend\Test\PHPUnit\ControllerTestCase.php:769 
C:\xampp\htdocs\testsample\tests\application\controllers\IndexControllerTest.php 
:22 
C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:925 
C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:787 
C:\xampp\php\PEAR\PHPUnit\Framework\TestResult.php:649 
C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:734 
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:772 
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:745 
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:705 
C:\xampp\php\PEAR\PHPUnit\TextUI\TestRunner.php:325 
C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php:187 
C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php:125 
C:\xampp\php\phpunit:44 

←[37;41m←[2KFAILURES! 
←[0m←[37;41m←[2KTests: 4, Assertions: 10, Errors: 2. 
←[0m←[2K 
Generating code coverage report, this may take a moment. 

爲什麼我得到這個錯誤?我做錯了什麼?請幫助我

回答

19

Zend Framework 1應用程序目前並可能持續相當長一段時間,只能使用PHPUnit 3.5.x正常運行。

請參閱downgrade phpunit 3.6 to 3.5.15關於如何降級到3.5

Zend Framework 2將再次支持當前版本的PHPUnit

+0

它的工作謝謝:) – Srivathsa

+2

看到這個[問題](HTTP://framework.zend。 com/issues/browse/ZF-11828)在ZF Bugtracker中。 –

+0

解決方法:不會修復 – max4ever

2

從來沒有想過我會回答一個2歲後,我遇到了檸同樣的問題,通過修改誰的Zend庫君子發現this網站和它的工作對我來說(我couldn`t降級......) 希望它會幫助別人:-)

4

可以使用PHPDoc的@expectedException命令抑制版本不兼容錯誤:

/** 
* test bad url 
* @requires PHPUnit 3.5.15 
* @expectedException PHPUnit_Framework_Error_Notice 
* // Zend Framework 1.X cannot use anything greater than PHPUnit 3.5.15 
* */ 
public function test_InvalidUrl_wrong_action() 
{ 
    $this->dispatch('/index/fake'); 
    $this->assertController('error','should be the error controller'); 
    $this->assertAction('error','should be the error action'); 
    $this->assertResponseCode(200); 
} 
相關問題