12

I am learning the ropes with Unit testing Zend Framework applications. So far I have set up PHPUnit to work with Zend Framework and have started writing some simple Test Cases.

My issue is that I am wondering why Code Coverage does not work in spite of being set in the logging tag in my phpunit.xml.

I don't get any error but no coverage report is generated.

However it works when I run phpunit --coverage <dir>

The logging section of my phpunit is as below:

<phpunit bootstrap="./application/bootstrap.php" colors="true">
        <testsuite name="CI Test Suite">
            <directory>./</directory>
        </testsuite>
        <testsuite name="Library Test Suite">
            <directory>./library</directory>
        </testsuite>

        <filter>
            <whitelist>
                <directory suffix=".php">../application/</directory>
                <exclude>
                    <directory suffix=".phtml">../application</directory>
                    <file>../application/Bootstrap.php</file>
                    <file>../application/controllers/ErrorController.php</file>
                </exclude>
            </whitelist>
           <logging>
               <log type="coverage-html" target="./log/report" charset="UTF-8" yui="true"
   highlight="true" lowUpperBound="50" highLowerBound="80" />
               <log type="testdox" target="./log/testdox.html" />    
           </logging>
        </filter>
    </phpunit>

Anyone encounter this before? What is then likely problem?

1
  • 3
    I don't have my logging nested inside the filter.... that might make a bit of difference Commented Apr 23, 2012 at 16:43

1 Answer 1

27

Here is the phpunit.xml for one of my projects, this works fine. As you can see, the logging section is outside the filter section, so that is probably your issue as commented by Mark Baker. I chose this one as it is from a small project and is very simple.

<phpunit bootstrap="./bootstrap.php" colors="false">
    <testsuite name="HSSTests">
        <directory>./</directory>
    </testsuite>

    <filter>
        <whitelist>
            <directory suffix=".php">d:/wamp/app_hss/</directory>
            <exclude>
                <directory suffix=".phtml">d:/wamp/app_hss/</directory>
                <directory suffix=".php">d:/wamp/app_hss/tests/</directory>
            </exclude>
        </whitelist>
    </filter>

    <logging>
        <log type="coverage-html" target="./log/codeCoverage" charset="UTF-8"
            yui="true" highlight="true"
            lowUpperBound="50" highLowerBound="80"/>
        <log type="testdox-html" target="./log/testdox.html" />
    </logging>
</phpunit>

All the information you could ever need on this is in the PHPunit manual.

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

1 Comment

You are absolutely right! The logging section should not have been within the filter section.

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.