1

I'm using PHP 5.6.24 with PHPUnit 5.5.4 and XDebug 2.4.1 and I reach a code coverage of 0,83%. However, before I was using PHP 5.6.0 with PHPUnit 4.7.7 and XDebug 2.3.3 and reached a code coverage of more than 84%.

I found out that since PHP 5.5.x you need to have a phpunit.xml with a whitelist configured. This was new for me, so I added the following file:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./</directory>
            <file></file>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-html" target="../results/report" lowUpperBound="35" highLowerBound="70"/>
    </logging>
    <testsuites>
        <testsuite name="DTS">
            <directory>./</directory>
        </testsuite>
    </testsuites>
</phpunit>

The unit tests still work. When I run them by command line I still see that all tests are executed successfully, but it's just the code coverage report which has such odd result.

0

1 Answer 1

0

I am running 5.5.4, which is the latest stable release, 5.6 is a beta release. I added the logging to mine to see if it would work, and it did. It generated a HTML report that was in the report directory that showed me percentages correctly. Here is my phpunit.xml file

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
    <testsuite name="Full Suite">
        <directory>tests/</directory>
    </testsuite>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-html" target="report"/>
    </logging>
</phpunit>

So it could be the beta release, but you can at least see my xml file and know that it works with 5.5.4. Good luck!

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

6 Comments

Thanks for your input. I used your file as a basis (with modification of my paths), but I still got the same results. (I'm also using the latest stable PHPUnit 5.5.4, never tried the beta version)
That's too bad, hoping it was something little...(sorry I misread your original post and saw PHP 5.6 and thought it was PHPUnit 5.6, hence the beta confusion)...I am running PHP 5.6 as well. I can only suggest to set up some kind of simple test case and see if it runs then just to check your environment. Good luck!
Does phpunit has any specific requirements about folder/test structure? I doubt so, because it finds and executes all test cases? What is see is that all of my 3793 tests are executed successfully, but only 13 / 822 test methods have code coverage.
Yes, if it is finding tests through self discovery (asking it to test an entire directory) it is looking for files named like this: *Test.php. I just noticed, that you have the same directory white listed as your test directory, maybe that is it? In other words, it is a good idea to put the tested code in a separate directory structure (such as src) and the test cases in another directory say "tests", then whitelist the src only to indicate how much of the code targeted for testing is covered.You can see what I mean in my project (and the phpunit.xml):github.com/1HappyPlace/clio
Well, your suggestion did the trick. Thus, I moved all the source code into a "src" sub folder and the test code in a "tests" sub folder. Now I got proper code coverage. At least for a very small sub set of my code for which I tried it. I have some refactoring work to do (changing include paths etc.to match the new directory structure) Thanks Katie!
|

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.