Create coverage of just what was just tested

Each time I run unit tests of one class or the entire folder, phpunit generates coverage for the entire system because it is configured in phpunit.xml.
This is bad because it takes longer and runs out of PHP memory.

My phpunit.xml

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html --> <phpunit backupGlobals = "false" backupStaticAttributes = "false" colors = "true" convertErrorsToExceptions = "true" convertNoticesToExceptions = "true" convertWarningsToExceptions = "true" processIsolation = "false" stopOnFailure = "false" syntaxCheck = "false" bootstrap = "Bootstrap.php" > <testsuites> <testsuite name="Application Module Suite Test"> <directory>./Module1Test</directory> <directory>./Module2Test</directory> <directory>./Module3Test</directory> </testsuite> </testsuites> <filter> <whitelist> <directory>../module/Module1</directory> <directory>../module/Module2</directory> <directory>../module/Module3</directory> </whitelist> </filter> </phpunit> 

Is there a way to generate coverage of just what I'm testing right now, dynamically ?

Example
For the command below, I would like to generate coverage only for the Controller/ExampleController.php .

 phpunit Controller/ExampleController.php --coverage-html ~/Desktop/tests 

I am using PHPUnit 4.8 and 3.7, Sublime Text Editor and the application uses Zend Framework 2.

+7
php phpunit zend-framework2
source share
2 answers

From the PHPUnit version 5.6 manual:

The @covers annotation (see table B.1) can be used in the test code to indicate which method is testing the test method. If provided, only code coverage information for the specified method (s) will be considered. Example 11.2 shows an example.

See this link for an example: https://phpunit.de/manual/current/en/code-coverage-analysis.html#code-coverage-analysis.specifying-covered-methods.examples.BankAccountTest.php

Could this be useful for your scenario?

+1
source share

add processUncoveredFilesFromWhitelist parameter to True , as in https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.whitelisting-files

 <filter> <whitelist processUncoveredFilesFromWhitelist="true"> <directory>../module/Module1</directory> <directory>../module/Module2</directory> <directory>../module/Module3</directory> </whitelist> </filter> 
0
source share

All Articles