I'm doing Code Coverage reports for a project and there's a ton of files that are included or required while tests are running that are not actually required to be tested or added to coverage reports (I'm using Zend Framework 2; config + Module files are the culprit here).
Is there an easy way to simply ignore the file pattern modules/*/Module.php
?
This is my blacklist:
<filter>
<blacklist>
<directory>config</directory>
<directory>vendor</directory>
<directory>module/*/config</directory>
</blacklist>
</filter>
However, adding <file>module/*/Module.php</file>
has no effect on html code coverage reports; adding it has no effect whatsoever on including Module.php
files in the coverage reports.
Zend Framework is booted up in the phpunit bootstrap.php
file with the usual
Application::init(require "config/application.test.php")
Short of adding the Module.php
file for every single module to the blacklist, is there any way PHPUnit can actually do this correctly? I'm not looking for answers that use the setUp
method in PHPUnit's test cases; I'm looking for a configuration.
I'm using PHPUnit 4.7 + 4.8.
So, in order to exclude multiple files with the same name, <file>
normally wont do a thing as it will only match a single file exactly.
The solution is to use <directory>
, but to use the suffix attribute;
<phpunit
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
<testsuites>
<testsuite name="Test Suite">
<!-- functional tests -->
<directory>tests</directory>
<!-- unit tests -->
<directory>module/*/test</directory>
</testsuite>
</testsuites>
<!-- ignore folders for code coverage -->
<filter>
<blacklist>
<directory>config</directory>
<directory>vendor</directory>
<directory>module/*/config</directory>
<directory suffix="Module.php">module/*</directory>
</blacklist>
</filter>
</phpunit>
<directory suffix="Module.php">module/*</directory>
will match multiple files that end in Module.php
within the top level of the module's directory, including Module.php
itself.
Since there's no reason for any other php file to be in that directory in Zend Framework 2, it seems to be the best way to go about it.
Where did u add your file tag ?
This is my blacklist
tag it's working for me.
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="Bootstrap.php"
colors="true"
stopOnError="true"
stopOnFailure="false"
strict="true"
verbose="true">
<testsuites>
<testsuite name="All Modules">
<directory>../module/*/tests/*Test</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">../vendor</directory>
<directory suffix=".php">../config</directory>
<directory suffix=".php">../data</directory>
<directory suffix=".php">../module/*/src/*/Controller</directory>
<file>../module/*/Module.php</file>
<file>../module/*/src/*/Factory/*ControllerFactory.php</file>
<directory suffix=".php">../module/*/tests/*</directory>
</blacklist>
</filter>
<php>
<ini name="memory_limit" value="2047M" />
</php>
<logging>
<log type="coverage-html" target="../build/tests/coverage/" charset="UTF-8"
yui="true" highlight="false"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="../build/tests/clover.xml"/>
<log type="junit" target="../build/tests/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>
I have this structure :
- module
- vendor
- tests
- phpunit.xml
- public
- build.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With