生成 PHPUnit 代码覆盖率报告时无法重新声明类错误
使用Zend Framework 1.10和Thermony 2(Beta1)启动项目。我在自己的库代码中使用命名空间。
生成代码覆盖率报告时,我收到有关重新声明类的致命错误。为了提供更多信息,我已经在我的phpunit可执行文件中注释掉了xdebug_disable()调用,以便您可以看到函数跟踪(禁用局部变量输出,因为输出太多)。
这是我的终端输出:
$ phpunit PHPUnit 3.4.12 by Sebastian Bergmann. ........ Time: 4 seconds, Memory: 16.50Mb OK (8 tests, 14 assertions) Generating code coverage report, this may take a moment.PHP Fatal error: Cannot redeclare class Cob\Application\Resource\HelperBroker in /Users/Cobby/Sites/project/trunk/code/library/Cob/Application/Resource/HelperBroker.php on line 93 PHP Stack trace: PHP 1. {main}() /usr/local/zend/bin/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() /usr/local/zend/bin/phpunit:54 PHP 3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:146 PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:213 PHP 5. PHPUnit_Util_Report::render() /usr/local/zend/share/pear/PHPUnit/TextUI/TestRunner.php:478 PHP 6. PHPUnit_Framework_TestResult->getCodeCoverageInformation() /usr/local/zend/share/pear/PHPUnit/Util/Report.php:97 PHP 7. PHPUnit_Util_Filter::getFilteredCodeCoverage() /usr/local/zend/share/pear/PHPUnit/Framework/TestResult.php:623 Fatal error: Cannot redeclare class Cob\Application\Resource\HelperBroker in /Users/Cobby/Sites/project/trunk/code/library/Cob/Application/Resource/HelperBroker.php on line 93 Call Stack: 0.0004 322888 1. {main}() /usr/local/zend/bin/phpunit:0 0.0816 4114628 2. PHPUnit_TextUI_Command::main() /usr/local/zend/bin/phpunit:54 0.0817 4114964 3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:146 0.1151 5435528 4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:213 4.2931 16690760 5. PHPUnit_Util_Report::render() /usr/local/zend/share/pear/PHPUnit/TextUI/TestRunner.php:478 4.2931 16691120 6. PHPUnit_Framework_TestResult->getCodeCoverageInformation() /usr/local/zend/share/pear/PHPUnit/Util/Report.php:97 4.2931 16691148 7. PHPUnit_Util_Filter::getFilteredCodeCoverage() /usr/local/zend/share/pear/PHPUnit/Framework/TestResult.php:623
(我不知道为什么它显示错误两次...?
这是我的phpunit.xml:
<phpunit bootstrap="./code/tests/application/bootstrap.php" colors="true">
<!-- bootstrap.php changes directory to trunk/code/tests,
all paths below are relative to this directory. -->
<testsuite name="My Promotions">
<directory>./</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../application</directory>
<directory suffix=".php">../library/Cob</directory>
<exclude>
<!-- By adding the below line I can remove the error -->
<file>../library/Cob/Application/Resource/HelperBroker.php</file>
<directory suffix=".phtml">../application</directory>
<directory suffix=".php">../application/doctrine</directory>
<file>../application/Bootstrap.php</file>
<directory suffix=".php">../library/Cob/Tools</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="junit" target="../../build/reports/tests/report.xml" />
<log type="coverage-html" target="../../build/reports/coverage" charset="UTF-8"
yui="true" highlight="true" lowUpperBound="50" highLowerBound="80" />
</logging>
</phpunit>
我在哪些接缝内添加了一个标签来隐藏这个问题。我确实有另一个应用程序资源,但它没有问题(另一个是教义2资源)。我不确定为什么它特定于这个类,我的整个库都是自动加载的,所以它们在任何地方都没有任何包含/需要调用。我想应该注意的是,HelperBroker是文件系统中第一个源自library/ Cob的文件。
我在Snow Leopard上使用所有软件的最新版本(Zend Server,Zend Framework,Doctrine 2 Beta1,Phing,PHPUnit,PEAR)。