3

I'm running a series of PHPunit tests and have a controller that is reporting 100% coverage. In the coverage report however, only 5 of its 84 lines of code are marked "green"

I'm wondering what factors might be causing this issue?

One interesting point that might be causing it is 'indirect calls'. This particular controller is the parent of a number of other controllers, and since so many other objects inherit from it maybe the code gets called for elsewhere... but then wouldn't it turn green?

As it stands the only method that is turning green is the __construct method.

I don't know if that's actually enough to go on, but if anyone has a bit more knowledge of how Unit Testing determines coverage I'd love to hear it.

Edit in response to `Gaurav's comment:

The phpunit command line is phpunit --configuration admin.xml

and admin.xml reads

 <phpunit bootstrap="./admin/applications/admin/bootstrap.php" colors="true">
     <testsuite name="AdminTestSuite">
        <directory suffix=".php">./admin/applications/admin/</directory>        
        <directory suffix=".php">./admin/applications/shared/</directory>
    </testsuite>
     <filter>
         <whitelist>
            <directory suffix=".php">../admin/applications/admin/controllers</directory>
            <directory suffix=".php">../admin/applications/shared/controllers</directory>           
            <directory suffix=".php">../admin/applications/shared/helpers</directory>
            <directory suffix=".php">../admin/lib/controllers</directory>           
            <directory suffix=".php">../admin/lib/helpers</directory>
            <directory suffix=".php">../admin/lib/models</directory>
            <directory suffix=".php">../admin/lib/utils</directory>         
         </whitelist>
         <blacklist>
                 <file>../dm_admin/applications/shared/controllers/DashboardController.php</file>
            <directory suffix=".php">../admin/lib/crons</directory>
         </blacklist>                
     </filter>
     <logging>
         <log type="coverage-html" target="/projects/ut/admin/" charset="UTF-8"
             yui="true" highlight="true"
             lowUpperBound="50" highLowerBound="80"/>
         <log type="testdox-html" target="/projects/ut/admin/testdox.html" />
     </logging>
 </phpunit>

In response to jakenoble:

the helper is reading 100% coverage The report reading 100% coverage on the helper

but inside we see Some text at the top of one of the methods - 1099 lines in all

It goes on for 1099 lines, with the occasional green... but no red.

Alex C
  • 16,624
  • 18
  • 66
  • 98
  • 1
    It doesn't matter how the code has been called. If any line is executed then it will be green. Please let me know how do you execute phpunit command and possibly phpunit.xml file code – Gaurav Jan 26 '11 at 17:25
  • Can you post a screen shot of the code coverage? – Jake N Jan 26 '11 at 23:17

1 Answers1

0

The code coverage report shows three different scores: classes, methods and functions, and lines.

Classes is a report on the number of classes tested in an entity. So, if you have one class per file, and you test a part of that class, it shows as you testing 100% of the classes.

If you have two classes in a file, and you test one class, you'll have 50% class coverage.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jason Lotito
  • 294
  • 2
  • 4
  • But lines that are being run are not changing colour. They're all just "white" – Alex C Jan 27 '11 at 16:21
  • Hrm, yeah, that's another issue entirely. Not sure about that. The XML file you are using is the same as mine as far as code coverage config options go as well. Silly question, but can you verify that the lines are being properly modified at the HTML level? – Jason Lotito Jan 27 '11 at 19:05
  • Just to help a bit more, you'll see lineCov for lines that are covered, lineNoCov for lines that aren't, and lineDeadCode, all as HTML classes. At least, that's what they are for me. – Jason Lotito Jan 27 '11 at 19:10