Why does PHPUnit execute code when creating a coverage report?

Expensive stackoverflowers, We are developing a cakephp based web application. CakePHP is a little difficult to use in a TDD manner, and so we are trying to develop the smallest amount of code that is possible for the structure itself by extracting all the business logic into classes that are independent of cakephp. This way we can test our libraries with phpunit with minimal problems. However, we want to include the unverified code in our coverage report more than anything in order to keep track of the amount of glue code between the cake and our libraries that we cannot verify. The problem is that when you say phpunit to account for this code, it is crazy parsing and executing cakephp code, and it breaks with a bang. My question is: why does phpunit execute this code at all? Something we do not understand and are not doing wrong here? Here is the phpunit.xml file we use:

<?xml version="1.0" encoding="utf-8" ?> <phpunit backupGlobals="true" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false" testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"> <filter> <whitelist addUncoveredFilesFromWhitelist="true"> <directory suffix=".php">app</directory> <exclude> <directory suffix=".php">tests</directory> <directory suffix=".php">app/webroot</directory> <directory suffix=".php">app/plugins</directory> <directory suffix=".php">app/vendors</directory> <directory suffix=".php">app/config</directory> <directory suffix=".php">app/tmp</directory> <directory suffix=".php">cake</directory> <directory suffix=".php">vendors</directory> </exclude> </whitelist> </filter> </phpunit> 

Thanks for any help.

+4
source share
2 answers

You need to add cakephp files to the blacklist . You must do this in your xml configuration file:

 <filter> <blacklist> <directory suffix=".php">/path/to/files</directory> <file>/path/to/file</file> <exclude> <directory suffix=".php">/path/to/files</directory> <file>/path/to/file</file> </exclude> </blacklist> </filter> 

More info here

+3
source

Why does phpunit execute this code at all?

He does this because he needs to get information about classes, methods, and functions that are also not covered. It includes found files and uses Reflection to open all class information. This is easier than manually analyzing and analyzing the parsed PHP file tokens .

0
source

All Articles