Giter Club home page Giter Club logo

php-code-coverage's Introduction

phpunit/php-code-coverage

Latest Stable Version CI Status Type Coverage codecov

Provides collection, processing, and rendering functionality for PHP code coverage information.

Installation

You can add this library as a local, per-project dependency to your project using Composer:

composer require phpunit/php-code-coverage

If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:

composer require --dev phpunit/php-code-coverage

Usage

<?php declare(strict_types=1);
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\Driver\Selector;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlReport;

$filter = new Filter;

$filter->includeFiles(
    [
        '/path/to/file.php',
        '/path/to/another_file.php',
    ]
);

$coverage = new CodeCoverage(
    (new Selector)->forLineCoverage($filter),
    $filter
);

$coverage->start('<name of test>');

// ...

$coverage->stop();


(new HtmlReport)->process($coverage, '/tmp/code-coverage-report');

php-code-coverage's People

Contributors

alexshadow007 avatar bastien-phi avatar danielpalme avatar dekker-m avatar derickr avatar dvdoug avatar edorian avatar fabpot avatar grahamcampbell avatar jeroendedauw avatar jrfnl avatar jseniuk avatar kelunik avatar krakjoe avatar localheinz avatar maks3w avatar mvorisek avatar pborreli avatar pfeigl avatar remicollet avatar rohm1 avatar rpkamp avatar sebastianbergmann avatar slamdunk avatar staabm avatar theseer avatar tombevers avatar tysonandre avatar wes0617 avatar whatthejeff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-code-coverage's Issues

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 68 bytes)

D:\Apache2\htdocs\zendFrameworkBasedProject>phpcov --clover d:\phpcov.clover.xml --html d:\phpcov .\public\index.php

[10-Oct-2010 22:11:48] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 68 bytes) in D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML\Node\File.php on line 636
[10-Oct-2010 22:11:48] PHP Stack trace:
[10-Oct-2010 22:11:48] PHP 1. {main}() D:\ZendServer\bin\phpcov:0
[10-Oct-2010 22:11:48] PHP 2. PHP_CodeCoverage_TextUI_Command::main() D:\ZendServer\bin\phpcov:51
[10-Oct-2010 22:11:48] PHP 3. PHP_CodeCoverage_Report_HTML->process() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\TextUI\Command.php:217
[10-Oct-2010 22:11:48] PHP 4. PHP_CodeCoverage_Report_HTML->addItems() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML.php:135
[10-Oct-2010 22:11:48] PHP 5. PHP_CodeCoverage_Report_HTML->addItems() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML.php:222
[10-Oct-2010 22:11:48] PHP 6. PHP_CodeCoverage_Report_HTML->addItems() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML.php:222
[10-Oct-2010 22:11:48] PHP 7. PHP_CodeCoverage_Report_HTML->addItems() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML.php:222
[10-Oct-2010 22:11:48] PHP 8. PHP_CodeCoverage_Report_HTML->addItems() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML.php:222
[10-Oct-2010 22:11:48] PHP 9. PHP_CodeCoverage_Report_HTML->addItems() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML.php:222
[10-Oct-2010 22:11:48] PHP 10. PHP_CodeCoverage_Report_HTML_Node_Directory->addFile() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML.php:214
[10-Oct-2010 22:11:48] PHP 11. PHP_CodeCoverage_Report_HTML_Node_File->__construct() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML\Node\Directory.php:156
[10-Oct-2010 22:11:48] PHP 12. PHP_CodeCoverage_Report_HTML_Node_File->loadFile() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML\Node\File.php:166
[10-Oct-2010 22:11:48] PHP 13. explode() D:\ZendServer\bin\PEAR\PHP\CodeCoverage\Report\HTML\Node\File.php:636

Replace RGraph with a FLOSS JavaScript charting library

PHP_CodeCoverage currently uses (and bundles) RGraph to render the charts of the code coverage dashboard in the HTML code coverage report. It has been brought to my attention that the license of RGraph is not compatible with the BSD-style licence that PHP_CodeCoverage uses.

Code Coverage Ignore Options

I have a question, however, about code coverage integration with xdebug. We have sparsely put codeCoverageIgnoreStart/End annotations around our code, but we would like to get the ACTUAL coverage. Is there a way to tell PHPUnit to ignore the start/end comments for a specific run?

Is that something that I could change PHPUnit to do and have it driven by a argument passed into the test, or is that buried in xdebug?

I would basically like to have two outputs:
% covered including the code between the comments
% covered excluding the code between the comments.

Please tell me if you think that is worthwhile and if you could point me to a place to put that code in, I would be grateful!

phpcov assumes there are classes

Notices is being thrown when phpcov is run on the following script (run as phpcov --html cov test.php ):

derick@kossu:~/dev/php/xdebug-demos$ cat test.php

Closing curly of methods not considered dead code

Given this class
namespace Foo;

class TestCurly
{
  public function foo($bar)
  {
    if($bar==1)
      return 1;
    elseif($bar==2)
      return 2;
    elseif($bar==3)
      return 3;
  }
}

Try to run this test:
public function testCoverage()
{
$curly=new \Foo\TestCurly;
$curly->foo(1);
$curly->foo(2);
$curly->foo(3);
}

The last line of method foo will not be considered dead code but "not executed" instead

Coverage for "break" in switch.

I have some "switch" statements in my sources... so the problem is: I could not get lines with "break" to be marked as tested in html report, is it know issue?

Add option to disable the PHP_Token_Stream cache

Moved here from sebastianbergmann/php-token-stream#13

I am using PHPUnit coverage data generator, which in turn uses PHP_Token_Stream. The problem is if the project has many big files, the cache stored inside PHP_Token_Stream gets too big and pushes PHP out of memory. I wouldn't mind running without the cache - at least it gets to finish - but there's no option to turn the cache off.

Update PEAR package for PHP_Token_Stream_Autoload

I have upgraded all pear package, but PHP_CodeCoverage stopps working because it directly loads PHP/Token/Stream/CachingFactory.php instead of the new Autoload.php. I have seen the changes made on the repository - but there is no new release so far with these changes.

If it needs more time, I will patch my copy of CodeCovergae by myself but I would prefer a new package releae.

Wrong list of methods for a class when using lambdas

I have a code like this:

  public function renderException($e, $output)
  {
    $strlen = function ($string)
    {
      return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
    };

  // ...

In the HTML report, the renderException() method is currently completely ignored and instead, an empty function (the anonymous function) shows up in the list of methods.

Selenium code coverage with PHPUnit

When PHPUnit is run with --coverage-html option for any class that extends the PHPUnit_Extensions_SeleniumTestCase, it deletes all files from the root directory. This is for PHPUnit version 3.4.13.

Broken code coverage report for PHPT tests.

I'm currently running PHPUnit 3.5 and XDebug 2.1.0 on PHP 5.3.3 (OSX). For the past couple of years, I've been running PHPT tests in PHPUnit via this file:

http://code.google.com/p/tarzan-aws/source/browse/trunk/_tests/cloudwatch/AllTests.php?r=347

I typically use the code coverage feature of PHPUnit.

phpunit --colors --coverage-html ./_coverage_report AllTests.php

More recently, it's been generating reports that give me 100% PASSED (lines 0/0). I first noticed this within the last 90-ish days. Any ideas what could be causing the issue?

Thanks! :)

xdebug.coverage_enable issue

It breaks phpunit instance and such fix is not working (phpunit.xml):

<php>
    <ini name="xdebug.coverage_enable" value="On"></ini>
</php>

Code coverage report fails to generate

After running some test the code coverage report fails to generate (see errors). This only occurs with types coverage-clover and coverage-html. The junit type is generated correctly.

I'm using PHPUnit 3.6RC2 and PHP_CodeCoverage 1.1.0RC1.

Errors:

Writing code coverage data to XML file, this may take a moment.

PHP Warning: require(/usr/share/php/PHP/CodeCoverage/Report/Factory.php): failed to open stream: No such file or directory in /usr/share/php/PHP/CodeCoverage/Autoload.php on line 92
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->run() /usr/share/php/PHPUnit/TextUI/Command.php:124
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:182
PHP 5. PHP_CodeCoverage_Report_Clover->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:302
PHP 6. PHP_CodeCoverage->getReport() /usr/share/php/PHP/CodeCoverage/Report/Clover.php:85
PHP 7. php_codecoverage_autoload() /usr/share/php/PHP/CodeCoverage/Autoload.php:0

Warning: require(/usr/share/php/PHP/CodeCoverage/Report/Factory.php): failed to open stream: No such file or directory in /usr/share/php/PHP/CodeCoverage/Autoload.php on line 92

Call Stack:
0.0002 638224 1. {main}() /usr/bin/phpunit:0
0.0041 1334648 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
0.0042 1335536 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:124
0.1630 18894616 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:182
0.6120 22479752 5. PHP_CodeCoverage_Report_Clover->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:302
0.6120 22481768 6. PHP_CodeCoverage->getReport() /usr/share/php/PHP/CodeCoverage/Report/Clover.php:85
0.6120 22482296 7. php_codecoverage_autoload() /usr/share/php/PHP/CodeCoverage/Autoload.php:0

PHP Fatal error: require(): Failed opening required '/usr/share/php/PHP/CodeCoverage/Report/Factory.php' (include_path='/var/www/printconcept.local/backend/application/../library:/var/www/printconcept.local/backend/library:.:/usr/share/php:/usr/share/pear') in /usr/share/php/PHP/CodeCoverage/Autoload.php on line 92
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->run() /usr/share/php/PHPUnit/TextUI/Command.php:124
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:182
PHP 5. PHP_CodeCoverage_Report_Clover->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:302
PHP 6. PHP_CodeCoverage->getReport() /usr/share/php/PHP/CodeCoverage/Report/Clover.php:85
PHP 7. php_codecoverage_autoload() /usr/share/php/PHP/CodeCoverage/Autoload.php:0

Fatal error: require(): Failed opening required '/usr/share/php/PHP/CodeCoverage/Report/Factory.php' (include_path='/var/www/printconcept.local/backend/application/../library:/var/www/printconcept.local/backend/library:.:/usr/share/php:/usr/share/pear') in /usr/share/php/PHP/CodeCoverage/Autoload.php on line 92

Call Stack:
0.0002 638224 1. {main}() /usr/bin/phpunit:0
0.0041 1334648 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
0.0042 1335536 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:124
0.1630 18894616 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:182
0.6120 22479752 5. PHP_CodeCoverage_Report_Clover->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:302
0.6120 22481768 6. PHP_CodeCoverage->getReport() /usr/share/php/PHP/CodeCoverage/Report/Clover.php:85
0.6120 22482296 7. php_codecoverage_autoload() /usr/share/php/PHP/CodeCoverage/Autoload.php:0

phpunit.xml:

<logging>
    <log type="coverage-html" target="./log/coverage" title="SomeTitle" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70" />
    <log type="coverage-clover" target="./log/clover.xml" />
    <log type="junit" target="./log/junit.xml" logIncompleteSkipped="false" />
</logging>

Use PHP_TokenStream

Use PHP_TokenStream instead of PHP_CodeCoverage_Util::getClassesInFile() and PHP_CodeCoverage_Util::getFunctionsInFile().

Wrong Code Coverage when forceCoversAnnotation and addUncoveredFilesFromWhitelist parameters are used simultaneously

Problem

When forceCoversAnnotation="true" and addUncoveredFilesFromWhitelist="true" used at the same time, files and directories uncovered using addUncoveredFilesFromWhitelist option are not added to coverage report.

If forceCoversAnnotation="false" everything works as expected.

Details

The reason is, that the uncovered files found in PHP_CodeCoverage->processUncoveredFilesFromWhitelist() method are passed to append() method (line 520):

$this->append($data, 'UNCOVERED_FILES_FROM_WHITELIST');

later (in ->append()) they would be passed to applyCoversAnnotationFilter() (line 256):

$this->applyCoversAnnotationFilter($data, $id); 
//  equals to $this->applyCoversAnnotationFilter($data,  'UNCOVERED_FILES_FROM_WHITELIST');

and than emptied in applyCoversAnnotationFilter() lines (421-423)

       ...
       else if ($this->forceCoversAnnotation) {
            $data = array();
        }

because $id ('UNCOVERED_FILES_FROM_WHITELIST') is not an instance of PHPUnit_Framework_TestCase and forceCoversAnnotation is on.

Proposed solution

Before passing files to applyCoversAnnotationFilter, it should be checked whether $id == 'UNCOVERED_FILES_FROM_WHITELIST'

See b4a1e18 for 1.0 branch.

PHPUnit_Util_Log_CodeCoverage_Database is not optional via PHPUnit_TextUI_TestRunner (PHPUnit 3.4.13)

So, PHPUnit_Util_Log_CodeCoverage_Database's performance is not so great for large test suites.

We utilise the database logging functionality to view what tests have run, and when; but we're more than happy with generating HTML code coverage reports.

Unfortunately, if you specify log-in-database; you cannot avoid logging code coverage too.

PHPUnit_TextUI_TestRunner::doRun()
...
if (isset($arguments['testDatabaseDSN']) &&
isset($arguments['testDatabaseLogRevision']) &&
extension_loaded('pdo')) {
$writeToTestDatabase = TRUE;
} else {
$writeToTestDatabase = FALSE;
}
....
if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
if ($writeToTestDatabase) {
$this->printer->write(
"\nStoring code coverage and software metrics data in " .
"database.\nThis may take a moment."
);

            require_once 'PHPUnit/Util/Log/CodeCoverage/Database.php';

            $testDb = new PHPUnit_Util_Log_CodeCoverage_Database($dbh);
            $testDb->storeCodeCoverage(
              $result,
              $dbListener->getRunId(),
              $arguments['testDatabaseLogRevision'],
              $arguments['testDatabasePrefix']
            );

            $this->printer->write("\n");
        }

PHPUnit 3.6.0RC1 gives errors on PHP_Code_Coverage

Hi,

I was testing PHPUnit 3.6.0RC1 for our test suite and I got following errors on PHP_Code_Coverage which also has been upgraded.

Warning: Missing argument 1 for text_template_autoload(), called in /usr/share/php/PHP/CodeCoverage.php on line 555 and defined in /usr/share/php/Text/Template/Autoload.php on line 46

Call Stack:
0.0002 638216 1. {main}() /usr/bin/phpunit:0
0.0038 1307808 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
0.0038 1308680 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:125
0.1458 17232656 4. PHPUnit_TextUI_Command->createRunner() /usr/share/php/PHPUnit/TextUI/Command.php:136
0.1473 17537008 5. PHPUnit_TextUI_TestRunner->__construct() /usr/share/php/PHPUnit/TextUI/Command.php:213
0.1481 17701096 6. PHP_CodeCoverage->__construct() /usr/share/php/PHPUnit/TextUI/TestRunner.php:91
0.1487 17785944 7. PHP_CodeCoverage->prefillBlacklist() /usr/share/php/PHP/CodeCoverage.php:129
0.1532 17864592 8. text_template_autoload() /usr/share/php/PHP/CodeCoverage.php:555

Notice: Undefined variable: class in /usr/share/php/Text/Template/Autoload.php on line 58

Call Stack:
0.0002 638216 1. {main}() /usr/bin/phpunit:0
0.0038 1307808 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
0.0038 1308680 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:125
0.1458 17232656 4. PHPUnit_TextUI_Command->createRunner() /usr/share/php/PHPUnit/TextUI/Command.php:136
0.1473 17537008 5. PHPUnit_TextUI_TestRunner->__construct() /usr/share/php/PHPUnit/TextUI/Command.php:213
0.1481 17701096 6. PHP_CodeCoverage->__construct() /usr/share/php/PHPUnit/TextUI/TestRunner.php:91
0.1487 17785944 7. PHP_CodeCoverage->prefillBlacklist() /usr/share/php/PHP/CodeCoverage.php:129
0.1532 17864592 8. text_template_autoload() /usr/share/php/PHP/CodeCoverage.php:555

Catchable fatal error: Argument 1 passed to PHP_CodeCoverage_Filter::addFilesToBlacklist() must be an array, null given, called in /usr/share/php/PHP/CodeCoverage.php on line 555 and defined in /usr/share/php/PHP/CodeCoverage/Filter.php on line 108

Call Stack:
0.0002 638216 1. {main}() /usr/bin/phpunit:0
0.0038 1307808 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
0.0038 1308680 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:125
0.1458 17232656 4. PHPUnit_TextUI_Command->createRunner() /usr/share/php/PHPUnit/TextUI/Command.php:136
0.1473 17537008 5. PHPUnit_TextUI_TestRunner->__construct() /usr/share/php/PHPUnit/TextUI/Command.php:213
0.1481 17701096 6. PHP_CodeCoverage->__construct() /usr/share/php/PHPUnit/TextUI/TestRunner.php:91
0.1487 17785944 7. PHP_CodeCoverage->prefillBlacklist() /usr/share/php/PHP/CodeCoverage.php:129
0.1534 17864672 8. PHP_CodeCoverage_Filter->addFilesToBlacklist() /usr/share/php/PHP/CodeCoverage.php:555

Line in heredoc marked as not executed in special case

When a line in a heredoc ends with a ${} construct the following line is marked as not executed:

<?php

$a = 'foo';

$b = <<<EOF
the line after this is marked as not executed ${a}

EOF;

$c = <<<EOF
the line after ${a} is marked as executed

EOF;

Bug: Fatal error: Uncaught exception 'ReflectionException' with message ...

... Method MySource_Tests_Channels_DisallowSelfActionsUnitTest::DisallowSelfActions() does not exist' in /usr/lib/php/PHP/CodeCoverage/Util.php:218

I want create coverage reports for the PHP_CodeSniffer itself, their sniffs and my own sniffs.
So I call phpunit from the commandline:
phpunit --coverage-clover=/results/PHPUnit/Clover/clover.xml --verbose /PHP_CodeSniffer/tests/AllTests.php
but I got the error mentioned above with this stack trace:
#0 /usr/lib/php/PHP/CodeCoverage/Util.php(218): ReflectionMethod->construct('MySource_Tests...', 'DisallowSelfAct...')
#1 /usr/lib/php/PHP/CodeCoverage.php(502): PHP_CodeCoverage_Util::getLinesToBeCovered('MySource_Tests
...', 'DisallowSelfAct...')
#2 /usr/lib/php/PHP/CodeCoverage.php(236): PHP_CodeCoverage->applyCoversAnnotationFilter(Array, Object(MySource_Tests_Channels_DisallowSelfActionsUnitTest))
#3 /Users/sok/Sites/projekte/t3dev/forge/hudson/hudson-helpers/tools/PHPUnit/PHPUnit-3.5/PHPUnit/Framework/TestResult.php(642): PHP_CodeCoverage->append(Array, Object(MySource_Tests_Channels_DisallowSelfActionsUnitTest), Array)
#4 /Users/sok/Sites/projekte/t3dev/forge/hudson/hudson-helpers/tools/PHPUnit/PHPUnit-3.5/PHPUnit/Framework/TestCase.php(599): PHPUnit_Framework_TestResult->run(Object(MySource in /usr/lib/php/PHP/CodeCoverage/Util.php on line 218

PHPUnit expect an function inside the *UnitTest.php file, but there is none. Writing tests for PHP_CodeSniffer sniffs are a little bit different, so there is no method with this name necessary.

If I call phpunit alone, all test will execute.

Clover coverage report counts ignored methods

PHP_CodeCoverage_Report_Clover::process() should make sure at least one line of a method is not ignored before incrementing the number of methods in a class. It should probably do the same thing for classes.

sfYaml and other coverage components not in project-under-test show up in coverage report

When running a test suite that contains test cases that either throw exceptions or use setExpectedException (not sure which is the real trigger), the HTML coverage report will include sfYaml and related Symfony components in the coverage report. The dashboard report will highlight these as a high risk due to 0% coverage.

I would expect these to be omitted from the report.

Code Coverage "False Positive" on a single line.

I needed to change the following code:

if(empty($hash[$name]))
    throw new MacrosException(sprintf('Undefined macro %s in "%s" (%s).', $macro, $code, $context));

To

if(empty($hash[$name])) {
    throw new MacrosException(sprintf('Undefined macro %s in "%s" (%s).', $macro, $code, $context));
}

(added paranthesis) with PHPUnit 3.5.13 to get a correct code coverage report. The exception is not thrown, but with the initial code, the line was reported as covered.

(UNIX file endings on a win32 box).

I'm unsure if this a php-code-coverage, a phpunit or a xdebug issue, so opted for here.

@covers does not work on standalone functions

The @covers comment element does not work on functions that are not defined as part of a class or interface. For example, it will not work on a function that is defined in a library.

Wrong coverage when a testcase is run multiple times

When a TestCase is run multiple times within a test suite, code coverage information is wrong.
We are doing this in our project to test the same code under different configuration such as db, db+memcached, db+memcached+sphinx, master slave database. Both html and clover reports are affected by this bug.

As soon as a test is run multiple times, all the uncovered code is treated as a comment. This result as everything appears as 100% covered.
This was not happening with phpunit 3.4

I've managed to create a minimal test case reproducing this issue. I've put the test case in this gist https://gist.github.com/609633

I have created a temporary fix by modifying the append function in CodeCoverage.php to suffix the test id by a uniq identifier so that coverage information from multiple runs of the same TestCase doesn't colide in the report.

public function append(array $data, $id = NULL, array $filterGroups = array('DEFAULT'))
{
    [.............]
    if (!empty($data)) {
        if ($id instanceof PHPUnit_Framework_TestCase) {
            $status           = $id->getStatus();
            $id               = get_class($id) . '::' . $id->getName() . '::' . uniqid('hack_');
            $this->tests[$id] = $status;
        }
[.....]
}

Some files are seemingly ignored in code coverage

When trying to calculate code coverage for a project certain files in a directory are seemingly ignored.

Screenshot evidence

However, as you can see from the directory listing there are 3 other files which phpcc is apparently ignoring:

matt@matt-lappy:/var/www/kohana/system/classes/kohana/config(3.2/feature/3000-config-rewrite)$ ll
total 32
drwxr-xr-x  3 matt matt 4096 2011-06-11 01:11 ./
drwxr-xr-x 12 matt matt 4096 2011-06-11 01:11 ../
drwxr-xr-x  2 matt matt 4096 2011-06-11 01:11 file/
-rw-r--r--  1 matt matt  485 2011-06-11 01:11 file.php
-rw-r--r--  1 matt matt 2976 2011-06-11 01:11 group.php
-rw-r--r--  1 matt matt  581 2011-06-11 01:11 reader.php
-rw-r--r--  1 matt matt  392 2011-06-11 01:11 source.php
-rw-r--r--  1 matt matt  744 2011-06-11 01:11 writer.php

Command used to generate the test results is:

phpunit --bootstrap=modules/unittest/bootstrap.php --coverage-html=/var/www/kohana/build/coverage --log-junit=/var/www/kohana/build/logs/junit.xml --coverage-clover=/var/www/kohana/build/logs/clover.xml modules/unittest/tests.php 2>&1

We have a custom test suite which has to whitelist specific files due to the way the codebase is structured. I modified the test suite factory to list files that have been whitelisted:

/**
 * Creates the test suite for kohana
 *
 * @return PHPUnit_Framework_TestSuite
 */
static function suite()
{
    static $suite = NULL;

    if ($suite instanceof PHPUnit_Framework_TestSuite)
    {
        return $suite;
    }

    $files = Kohana::list_files('tests');

    $suite = new PHPUnit_Framework_TestSuite;

    self::addTests($suite, $files);

    var_dump(PHP_CodeCoverage_Filter::getInstance()->getWhitelist());

    return $suite;
}

Running the suite gives:

  [54]=>
  string(60) "/var/www/kohana/system/classes/kohana/config/file/reader.php"
  [55]=>
  string(53) "/var/www/kohana/system/classes/kohana/config/file.php"
  [56]=>
  string(54) "/var/www/kohana/system/classes/kohana/config/group.php"
  [57]=>
  string(55) "/var/www/kohana/system/classes/kohana/config/reader.php"
  [58]=>
  string(55) "/var/www/kohana/system/classes/kohana/config/source.php"
  [59]=>
  string(55) "/var/www/kohana/system/classes/kohana/config/writer.php"
  [60]=>
  string(48) "/var/www/kohana/system/classes/kohana/config.php"

Source of the mentioned files can be found here.

Installed pear packages:

        Installed packages, channel pear.phpunit.de:
        ============================================
        Package            Version State
        DbUnit             1.0.2   stable
        File_Iterator      1.2.6   stable
        PHPUnit            3.5.14  stable
        PHPUnit_MockObject 1.0.9   stable
        PHPUnit_Selenium   1.0.3   stable
        PHP_CodeCoverage   1.0.4   stable
        PHP_Timer          1.0.0   stable
        PHP_TokenStream    1.0.1   stable
        Text_Template      1.1.0   stable
        phpcpd             1.3.2   stable
        phploc             1.6.1   stable

static variables aren't covered

<?php
class Example_Model_Feedback
{
    public function getFeedbackForm()
    {
        static $form = null;

        if (!$form) {
            $form = new Example_Form_Feedback();
        }

        return $form;
    }
}

xdebug.coverage_enable setting not recognized

This block in Xdebug.php is not right. When I set this in php.ini, it is not recognized, so this always dies.

if (version_compare(phpversion('xdebug'), '2.2.0-dev', '>=') &&
    !ini_get('xdebug.coverage_enable')) {
    die("You need to set xdebug.coverage_enable=On in your php.ini.\n");
}

Also, should you not at least use print('message'); exit(1)? die() does not set an error status.

selfFilter

Hi, I'm trying phpunit 3.6 with coverage and it breaks. The reason is the following:
I dont know why xdebug_get_code_coverage() returns, among many files the following:
["path/to/a/correct/file/already/in/array.php(444) : assert code"]=>
array(1) {
[1]=>
int(1)
}

Of course, that's not a file.
Thin is than in previous versions of PHP_CodeCoverage

In append fucntion there was a call to this method:
applySelfFilter(&$data)

{   
    foreach (array_keys($data) as $filename) {
        if (!$this->filter->isFile($filename)) {
            unset($data[$filename]);
            continue;
        }
    ....

That solved the problem but that method is not there anymore

Closures look strange in code coverage reports (html)

Run the following file with phpunit and have a look at the html code coverage report:

<?php
function foo($data) {
    usort($data, function($a, $b) {
        if ($a == $b) {
            return 0;
        }

        return ($a < $b) ? -1 : 1;
    });
    return $data;
}

class FooTest extends PHPUnit_Framework_TestCase {
    public function testClosure() {
        PHP_CodeCoverage_Filter::getInstance()->addFileToWhitelist(__FILE__);
        $data = array(2, 4, 1, 3);
        $sortedData = foo($data);
        $this->assertSame(array(1, 2, 3, 4), $sortedData);
    }
}

The closure is listed as $a, $b)

Incorrect code coverage calculation of multiline function calls

Given a function call with multiple arguments, formatted over several lines, ie.

class Test {
    function simpleTestFunction($arg1, $arg2, $arg3) {
            $this->_privFunc(
                    $arg1,
                    $arg2,
                    $arg3
            );
    }
    private function _privFunc($arg1, $arg2, $arg3) {
            echo $arg1 . $arg2 . $arg3;
    }
}

and a unit test:

class UnitTestTest extends PHPUnit_Framework_TestCase {
    public function testTest()
    {
            $test = new Test();
            $test->simpleTestFunction("1","2","3");
    }
}

The output of --coverage-html states that the first line

$this->_privFunc(

is not executed, which leads to wrong coverage results.

Filter: Whitelist Directory Won't Recurse

In tracking down an problem with a Whitelist issue preventing Code_Coverage to run from PHPUnit, I discovered that directory recursion is causing a problem. See previous detail on this closed issue:
sebastianbergmann/phpunit#241

See my last two comments for details, but here is the key:

I've narrowed it down to a directory recursion problem. Removing a sub-directory within the problem directory, so that it only contains one file, eliminates the problem. So, the expected directory recursion has issues with sub-directories when using <directory> within a <whitelist>. (Potentially in <blacklist> too as I expect they are treated similarly, but I have not tested that.)

Do not `include` uncovered files

In PHP_CodeCoverage::processUncoveredFilesFromWhitelist, uncovered files are included using include_once. This in effect executes the file, causes all sorts of trouble.

For example, on one machine I want to generate code coverage reports from PHPUnit, but because I miss a certain library that I need for some of the tests, I temporarily exclude that specific test (using e.g. --exclude-group). But now the files that the excluded unittest would have covered become uncovered files to PHP_CodeCoverage. This causes them to be included by PHP_CodeCoverage::processUncoveredFilesFromWhitelist. And then everything dies with a fatal error (because the excluded file has a require_once to the non-existant library).

I don't see the need to have PHP_CodeSniffer include the uncovered files. Surely there is a way to figure out which lines of a PHP file have executable code on them without using xdebug's get_code_coverage function?. Perhaps PHP's tokeniser could be used here instead?

Attach links to Class Complexity scatter chart

In the Class Complexity chart, each class on the graph ("+" point) allows resting over it to see the class name, and turns the cursor into a pointer (e.g., indicating it's clickable). But clicking on it does nothing.

Would be useful to allow clicking that point to take you directly to the coverage report for that class.

Patch Coverage

Given a Clover XML logfile and a patch file, the phpcov CLI tool should be able to figure out whether all changed/new lines are covered.

code coverage HTML generation doesn't work properly with process isolation

When using process isolation, class PHPUnit_Framework_TestCase use a "job" to execute a PHP script build with a PHPUnit_Util_Template object.

If code coverage is activated, xdebug return coverage for all script files and the unamed php script "-". PHPUnit filtered all scripts from phpunit framework but don't filter "-" script.

The code coverage html result is unusable because it cannot determine the "root" directory.

To solve this issue, the simplest way is to add a "unset($codeCoverage['-']);" juste after the "xdebug_get_code_coverage" in method "PHPUnit_Framework_TestResult::run"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.