Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add uncovered files to PHPUnit code coverage report of the Yii application
    primarykey
    data
    text
    <p>I am currently trying to get the code coverage report for a PHP application based on <a href="http://www.yiiframework.com/">Yii framework</a>.</p> <p>Code coverage gets generated by <a href="http://www.phpunit.de/manual/3.6/en/code-coverage-analysis.html">PHPUnit 3.6</a>, and I am using <a href="http://www.phpunit.de/manual/3.6/en/code-coverage-analysis.html#code-coverage-analysis.including-excluding-files">whitelist approach</a> to source files filtering.</p> <p>Problem is, when I set the option <code>addUncoveredFilesFromWhitelist="true"</code>, code coverage breaks with the following error: </p> <pre><code>Generating code coverage report, this may take a moment.PHP Warning: include(CButtonColumn.php): failed to open stream: No such file or directory in /home/hijarian/systems/yii/framework/YiiBase.php on line 418 PHP Stack trace: PHP 1. {main}() /usr/bin/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46 PHP 3. PHPUnit_TextUI_Command-&gt;run() /usr/share/php/PHPUnit/TextUI/Command.php:125 PHP 4. PHPUnit_TextUI_TestRunner-&gt;doRun() /usr/share/php/PHPUnit/TextUI/Command.php:187 PHP 5. PHP_CodeCoverage_Report_HTML-&gt;process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:373 PHP 6. PHP_CodeCoverage-&gt;getReport() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:133 PHP 7. PHP_CodeCoverage_Report_Factory-&gt;create() /usr/share/php/PHP/CodeCoverage.php:141 PHP 8. PHP_CodeCoverage-&gt;getData() /usr/share/php/PHP/CodeCoverage/Report/Factory.php:65 PHP 9. PHP_CodeCoverage-&gt;processUncoveredFilesFromWhitelist() /usr/share/php/PHP/CodeCoverage.php:173 PHP 10. include_once() /usr/share/php/PHP/CodeCoverage.php:516 PHP 11. YiiBase::autoload() /home/hijarian/systems/yii/framework/YiiBase.php:0 PHP Warning: include(): Failed opening 'CButtonColumn.php' for inclusion (include_path='.:/home/hijarian/projects/lexgarant/webapp/protected/components:/home/hijarian/projects/lexgarant/webapp/protected/models:/usr/share/php:/usr/share/pear') in /home/hijarian/systems/yii/framework/YiiBase.php on line 418 PHP Stack trace: PHP 1. {main}() /usr/bin/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46 PHP 3. PHPUnit_TextUI_Command-&gt;run() /usr/share/php/PHPUnit/TextUI/Command.php:125 PHP 4. PHPUnit_TextUI_TestRunner-&gt;doRun() /usr/share/php/PHPUnit/TextUI/Command.php:187 PHP 5. PHP_CodeCoverage_Report_HTML-&gt;process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:373 PHP 6. PHP_CodeCoverage-&gt;getReport() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:133 PHP 7. PHP_CodeCoverage_Report_Factory-&gt;create() /usr/share/php/PHP/CodeCoverage.php:141 PHP 8. PHP_CodeCoverage-&gt;getData() /usr/share/php/PHP/CodeCoverage/Report/Factory.php:65 PHP 9. PHP_CodeCoverage-&gt;processUncoveredFilesFromWhitelist() /usr/share/php/PHP/CodeCoverage.php:173 PHP 10. include_once() /usr/share/php/PHP/CodeCoverage.php:516 PHP 11. YiiBase::autoload() /home/hijarian/systems/yii/framework/YiiBase.php:0 PHP Fatal error: Class 'CButtonColumn' not found in /home/hijarian/projects/lexgarant/webapp/protected/components/CLexgarantButtonColumn.php on line 4 PHP Stack trace: PHP 1. {main}() /usr/bin/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46 PHP 3. PHPUnit_TextUI_Command-&gt;run() /usr/share/php/PHPUnit/TextUI/Command.php:125 PHP 4. PHPUnit_TextUI_TestRunner-&gt;doRun() /usr/share/php/PHPUnit/TextUI/Command.php:187 PHP 5. PHP_CodeCoverage_Report_HTML-&gt;process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:373 PHP 6. PHP_CodeCoverage-&gt;getReport() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:133 PHP 7. PHP_CodeCoverage_Report_Factory-&gt;create() /usr/share/php/PHP/CodeCoverage.php:141 PHP 8. PHP_CodeCoverage-&gt;getData() /usr/share/php/PHP/CodeCoverage/Report/Factory.php:65 PHP 9. PHP_CodeCoverage-&gt;processUncoveredFilesFromWhitelist() /usr/share/php/PHP/CodeCoverage.php:173 PHP 10. include_once() /usr/share/php/PHP/CodeCoverage.php:516 </code></pre> <p>(It's interesting by itself, why there is three almost identical errors instead of just one.) When <code>addUncoveredFilesFromWhitelist="false"</code> code coverage generates successfully, but, of course, without the files not covered by tests.</p> <p>Files of the Yii framework placed in the <code>$HOME/systems/yii/</code> directory.</p> <p>Application I'm trying to cover placed in the <code>$HOME/projects/$APPNAME/</code>.</p> <p>Here's my <code>phpunit.xml</code>:</p> <pre><code>&lt;phpunit bootstrap="bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false"&gt; &lt;filter&gt; &lt;!-- DO NOT SET TO "true" CODE COVERAGE WILL BREAK --&gt; &lt;whitelist addUncoveredFilesFromWhitelist="false"&gt; &lt;directory suffix=".php"&gt;..&lt;/directory&gt; &lt;exclude&gt; &lt;directory suffix=".php"&gt;../config/&lt;/directory&gt; &lt;directory suffix=".php"&gt;../messages/&lt;/directory&gt; &lt;directory suffix=".php"&gt;../tests/&lt;/directory&gt; &lt;directory suffix=".php"&gt;../runtime/&lt;/directory&gt; &lt;directory suffix=".php"&gt;/home/hijarian/systems/yii/framework/&lt;/directory&gt; &lt;/exclude&gt; &lt;/whitelist&gt; &lt;/filter&gt; &lt;logging&gt; &lt;log type="coverage-html" target="report/html" title="Lexgarant Online" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70" /&gt; &lt;/logging&gt; &lt;testsuites&gt; &lt;testsuite name="All_Unit_Tests"&gt; &lt;directory&gt;./unit/models/&lt;/directory&gt; &lt;directory&gt;./unit/logic/&lt;/directory&gt; &lt;directory&gt;./unit/components/&lt;/directory&gt; &lt;/testsuite&gt; &lt;/testsuites&gt; &lt;selenium&gt; &lt;browser name="Firefox" browser="*firefox" /&gt; &lt;/selenium&gt; &lt;/phpunit&gt; </code></pre> <p>I have all the tests placed under the <code>protected/tests</code> directory in the application's catalogue, as described in the <a href="http://www.yiiframework.com/doc/guide/1.1/en/test.overview#test-environment-setup">Test Environment Setup</a> in The Definitive Guide to Yii.</p> <p>PHPUnit is invoked as follows:</p> <pre><code>cd $APPDIR/protected/tests/ phpunit </code></pre> <p>The unit testing itself goes smoothly, only code coverage breaks. </p> <p>Maybe I should set up the exlude list to exclude directories with Yii's classes, but I am somewhat afraid of this experience because there's dozens of folders, Yii is a highly modular system. Of course, if it's an only solution...</p> <hr> <p>EDIT: So, for curious about it, full solution looks like this:</p> <p>phpunit.xml</p> <pre><code>&lt;php&gt; &lt;!-- HACK --&gt; &lt;includePath&gt;YIIPATH/framework/zii/widgets/grid&lt;/includePath&gt; &lt;/php&gt; &lt;filter&gt; &lt;whitelist addUncoveredFilesFromWhitelist="true"&gt; &lt;directory suffix=".php"&gt;../models/&lt;/directory&gt; &lt;directory suffix=".php"&gt;../components/&lt;/directory&gt; &lt;!-- any other directories you want to check --&gt; &lt;/whitelist&gt; &lt;/filter&gt; </code></pre> <p>Just replace YIIPATH placeholder with real path to Yii framework.</p> <p>It <em>definitely</em> has something to do with <code>CButtonColumn</code>, but for now I'm just using this hack with <code>includePath</code> and happy about it. Removing the hack brings this whole bug alive.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload