Year:

more posts

Unit test code coverage in PHP

So we all know grown-up development projects need unit testing, and lots of it. In the LAMP world PHPUnit is almost the de-facto solution, with xUnit heritage to make people mumble supportively about best practices and cross-domain expertise (currently working in a Java-heavy environment).

Perhaps less known is the automation of code coverage analysis. Thanks to one of the several gems xdebug has to offer, this can be integrated into the unit testing fairly easily. Watch your versioning though, we had to pull newer ones than CentOs 5.3 had to offer.

Simple Usage

The configuration / command line arguments are fairly key but something like:



$ phpunit —coverage-html ~/workspace/project/tests/coverage \

—colors —verbose ~/workspace/project/

With any use of external libraries (eg PEAR) we found it necessary to exclude those directories (eg /usr/share/) explicitly else coverage of those libraries was generated too, which is hardly the point. Beware also of symlinks confusing it a little.

The output, though a bit oldschool, is easy enough to drill down into, and seeing red lights turn to green is a surprisingly good motivation for developers to add more test, or better still, think about exactly what isn’t being tested fully.

Static Code Analysis

Also worth mentioning while we’re there is one of the static code analysis tools: at work I’ve set up phpcs with some luck. Its tab support is far from perfect (a tab, apparently, is a fixed amount of spaces that you’ve forgotten to convert) but other than that it can have its uses, and great for enforcing coding standards in a larger dev team.

Posted by nick on Aug. 30, 2010 at 6:17 p.m.. It's all of 267 words

comments

Two comments.

Nuallesse wrote:
Mods, please move this to the correct section if I've posted it in the wrong one: It's worth a share Beauty secrets are hard to obtain, find all of yours here: http://www.instantacnetreatment.com <a href=http://www.fortisolutions.com>Forti Solutions</a> <a href="http://www.fortisolutions.com">Forti Solutions</a>
Sept. 1, 2010, 7:57 p.m. chooGnowcof wrote:
Very Interesting! Thank You<a href=http://ukegfvkwuergfku.com>!</a>
Yesterday, 3:44 a.m.

your comment

Wikis, internationalisation and a touch of fame

Symbian robo-duck

I’ve been working at Symbian for some time now and have, among other things, become de-facto developer for their heavily-customised Mediawiki installation. In fact it holds about 1,400 content pages and over 30,000 edits at last count.

It’s now available in six major languages as part of the effort to open up Symbian development to the world at large (yes, especially Japan and China at the moment). The functionality was brought in by the Polyglot extension, which we then massively customised (and even fixed a couple of bugs – should probably submit them upstream actually). Most significantly was the edit hook to auto-add articles to an appropriate language category (this is how we solved grouping otherwise unrelated pages by languge in the wiki) if it detected the page was a translation [subpage] of the “root” (English) page.

Turns out Hamish gave me some lovely credits too on the Symbian Blog. How nice!

Posted by nick on Nov. 11, 2009 at 7:39 p.m.. It's all of 154 words

comments

No comments yet. You could be the first. Wouldn't that be amazing?

your comment