1

I'm learning Zend Framework 2 after the ZF2 "Getting Started" tutorial. Now I have a simple application a PHPUnit test of the IndexController (the code is copied from the capitel "Unit Testing" of the tutorial). The testing works. Now I'm trying to create a code coverage report:

# phpunit --coverage-html ./report

or

# phpunit --coverage-html ./report ApplicationTest/Controller/IndexControllerTest.php

I expect a coverage report of the whole folder test (first example) or the IndexControllerTest (second example).

What I'm currently getting is this report:

enter image description here

Why? And how can I make the code coverage script process the files/folders, I want to analyze.

EDIT:

I can navigate to my module folder and see the report for it:

enter image description here

But the questions are remaining the same: (1) Why does it work so and (2) how can I make the code coverage script process (only) the files/folders, I want to analyze.

1 Answer 1

5

You can include/exclude files or folders for code coverage using your phpunit.xml, see the phpunit manual.

Also you can ignore specific blocks of code from code coverage aggregation. See: http://www.phpunit.de/manual/3.2/en/code-coverage-analysis.html

PHPUnit code coverage is using xdebug to calculate the covered lines. If your IndexControllerTest also runs lines in order files they will show up in the coverage report as well.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your reply! Yes, it's possible to exclude some files or even folders. But why are folders var and usr displayed on the report page? How dose it look, when you create a coverage report?
Your IndexControllerTest also executes code in the usr folder. You can check which code is executed there by browsing deeper into it. If think your phpunit installation resided in the usr folder so this will be listed for code coverage as well, because php is running phpunit code. If you not specify any whitelist for code coverage in your configuration (phpunit.xml) phpunit will set the root for code coverage to the highest common map (/ in your case)
Your are right, thank you! <?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="Bootstrap.php"> <testsuite name="zf2sandbox"> <directory>./AlbumTest</directory> </testsuite> <filter> <whitelist> <directory suffix=".php">/var/www/sandbox/zf2sandbox/module/Album/src/Album/</directory> </whitelist> </filter> </phpunit>
Please remember to accept Bram's answer if it did correct your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.