I’m getting an error with PHPUnit Code_Coverage when using Composer’s autoload.php as the bootstrap file. I’ve created my own boostrap.php file and simply include each file individually and everything works fine. Have I stumbled onto a Composer bug, or am I making an error somewhere?
// Edit: I’m using the newest (to-date) versions of everything: PHPUnit 3.7.12, Code_Coverage 1.2.7, Composer b51a4a7
Fatal error: Cannot redeclare class C3\CDN\EdgeCast in /Users/kperrine/Projects/edgecast-custom-reports/src/C3/CDN/EdgeCast.php on line 11
Call Stack:
0.0017 641760 1. {main}() /Applications/MAMP/bin/php/php5.3.14/bin/phpunit:0
0.2232 1111312 2. PHPUnit_TextUI_Command::main() /Applications/MAMP/bin/php/php5.3.14/bin/phpunit:46
0.2232 1112040 3. PHPUnit_TextUI_Command->run() /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/TextUI/Command.php:129
0.3027 4636952 4. PHPUnit_TextUI_TestRunner->doRun() /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/TextUI/Command.php:176
21.5764 6604032 5. PHP_CodeCoverage_Report_HTML->process() /Users/kperrine/Projects/edgecast-custom-reports/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:384
21.5764 6604240 6. PHP_CodeCoverage->getReport() /Users/kperrine/Projects/edgecast-custom-reports/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/HTML.php:120
21.5768 6663512 7. PHP_CodeCoverage_Report_Factory->create() /Users/kperrine/Projects/edgecast-custom-reports/vendor/phpunit/php-code-coverage/PHP/CodeCoverage.php:158
21.5769 6663512 8. PHP_CodeCoverage->getData() /Users/kperrine/Projects/edgecast-custom-reports/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Factory.php:64
21.5769 6663512 9. PHP_CodeCoverage->addUncoveredFilesFromWhitelist() /Users/kperrine/Projects/edgecast-custom-reports/vendor/phpunit/php-code-coverage/PHP/CodeCoverage.php:190
21.5769 6664408 10. PHP_CodeCoverage->processUncoveredFileFromWhitelist() /Users/kperrine/Projects/edgecast-custom-reports/vendor/phpunit/php-code-coverage/PHP/CodeCoverage.php:535
21.5778 6757272 11. include_once('/Users/kperrine/Projects/edgecast-custom-reports/src/C3/CDN/EdgeCast.php') /Users/kperrine/Projects/edgecast-custom-reports/vendor/phpunit/php-code-coverage/PHP/CodeCoverage.php:558
My phpunit.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="C3 EdgeCast Tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="log/report" charset="UTF-8"
highlight="false" lowUpperBound="35" highLowerBound="70"/>
</logging>
</phpunit>
The problem was with my use of namespaces in the project. My project namespace is
C3\CDN\EdgeCast(note the capital ‘C’ in EdgeCast), but when I used the namespace in the test file I accidentally typeduse C3\CDN\Edgecast;(note the lower case ‘c’ in Edgecast). The difference in the name caused either CodeCoverage or Composer (I don’t know which exactly) to think the class hadn’t been included and thus tried to include it again.Moral of the story: Always double check your class and namespace names.