Code Coverage in CakePHP 1.2 Test Suite

Super fresh in the SVN builds of CakePHP 1.2 is the new code coverage analysis. If you are living on the bleeding edge of cake development or just want a preview of the neat things to come once 1.2 is complete read on.

The guys at debuggable have contributed a fantastic tool to the testing suite for CakePHP 1.2. Code coverage reporting! It requires that you have Xdebug installed on your development machine. If you don’t have Xdebug installed you can get it from Xdebug . There are a ton of benfits from using Xdebug, from saving time to being able to profile scripts, it really is an essential development tool. If you haven’t tried it out you really owe it to yourself to give it a whirl. But enough gushing about Xdebug.

Code coverage reports

The code coverage reports in the the test suite provide quick svn diff like coverage reports of lines executed on the test subject during your test. The subject is auto-magically derived from the filename of the test. Yet another situation where adhering to naming conventions is beneficial. The code coverage report highlights what lines in the subject class were executed and what lines were not. A summary percentile is also provided, giving you an instant look at how much coverage your tests are providing. All in all some really useful tools that make testing and developing with cake easier and more to the point.


I’ve tried to use Xdebug with cakePHP testing framework… the problem is that the Apache server crashes when trying to analyse code coverage!!!
I’ve heard that Xdebug is bugged is it true?

Houcem on 3/23/09

Houcem: This is an issue that pops up on some installs. I haven’t been able to figure out a reason for why it happens to some installs of Apache but not others. What I did to fix it was change line 115 of code_coverage_manager.php to be


This fixed the segmentation faults for me, hope it helps.

mark story on 3/23/09

I also am getting a fault when trying to view code coverage. Most of the time the server will fail, but once in a while the page loads, but no code coverage is displayed.

I am using the latest 1.2.2 stable

Any chance you guys are both developing on an OSX setup? (I am)

Adam on 4/7/09

Adam: I am on osx, however the segmentation faults are not limited to OSX. I know people who have had them on windows and ubuntu as well. I know that the change I suggested earlier in the comments fixed the issue in most cases.

mark story on 4/7/09

Hey Mark, yeah that actually worked on my iMac. When I tried and posted above it was on my MBP.

I guess it is good as a temporary solution.


Adam on 4/11/09

Hi Mark,
Just to report. I had the same problem related by Houcem and the solution you pointed is still the fastest.
Maybe this bug still persists in the xdebug extension (if it is really an xdebug-side bug).

Anyway thanks for the tip.

Charles on 1/4/10

I was getting Segmentation faults still in 1.3, but your code_coverage_manager.php suggestion did the trick.

Thanks god for google and your blog. =)

Nick on 2/2/10

^ Ubuntu 9.10 OS BTW.

Nick on 2/2/10

Comments are not open at this time.