Search code examples
phpzend-frameworkphpunitcode-coveragephp-5.3

"Cannot redeclare class" error when running PHPUnit with Code Coverage


PHPUnit seems to execute properly (appropriate tests are executed & pass), but during code coverage an error is thrown. We are using PHPUnit 3.5 with ZF 1.11. Any insight would be greatly appreciated!

(FYI: I looked at some related StackOverflow posts, but nothing seemed to solve this issue for us.)

[24-Jan-2012 00:11:09 UTC] PHP Fatal error:  Cannot redeclare class Zend_View_Helper_FormSpecial in /home/za/application/modules/proposal/views/helpers/FormSpecial.php on line 23
[24-Jan-2012 00:11:09 UTC] PHP Stack trace:
[24-Jan-2012 00:11:09 UTC] PHP   1. {main}() /usr/local/zend/bin/phpunit:0
[24-Jan-2012 00:11:09 UTC] PHP   2. PHPUnit_TextUI_Command::main() /usr/local/zend/bin/phpunit:49
[24-Jan-2012 00:11:09 UTC] PHP   3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:129
[24-Jan-2012 00:11:09 UTC] PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:188
[24-Jan-2012 00:11:09 UTC] PHP   5. PHP_CodeCoverage_Report_HTML->process() /usr/local/zend/share/pear/PHPUnit/TextUI/TestRunner.php:363
[24-Jan-2012 00:11:09 UTC] PHP   6. PHP_CodeCoverage->getSummary() /usr/local/zend/share/pear/PHP/CodeCoverage/Report/HTML.php:128
[24-Jan-2012 00:11:09 UTC] PHP   7. PHP_CodeCoverage->processUncoveredFilesFromWhitelist() /usr/local/zend/share/pear/PHP/CodeCoverage.php:354

Thanks!

Chris


Solution

  • The error means that /home/za/application/modules/proposal/views/helpers/FormSpecial.php is declaring a class named Zend_View_Helper_FormSpecial which is already declared by some other module--probably .../Zend/View/Helper/FormSpecial.php in the Zend Framework. If you intended to replace Zend's FormSpecial with your own, you need to give it a different class name.

    The problem is that PHP_CodeCoverage will load every PHP file in the whitelist that hasn't already been loaded. If one of those modules defines a class with the same name, you get this error.