Strong opinions, weakly held

Unit testing PHP

Like many developers, I’ve become test infected. When I’m creating a new API in Java, I generally try to write tests that provide good coverage before writing my code. And, I think more importantly, when anyone finds a bug in my code, I write a test to duplicate the bug before working on fixing it, so that I can verify that I’ve fixed the bug and that it stays fixed.

Anyway, I want to do bring my PHP programming practices in line with my Java practices. Right now, I don’t write any tests for PHP at the Web layer, and I write basic command line scripts to test my PHP at lower layers. (I have a library that I’ve written that has a few basic assertion functions to make things easier.)

JUnit and Eclipse make testing a lot easier in the Java world, and I’m wondering if there’s something similar in the PHP world that will make me a happier programmer. Here’s what I’ve found so far:

Anybody tried any of these or know of any other approaches for PHP unit testing? Comments appreciated.


  1. We use simpletest at work as it’s the fullest featured that we’ve found. I’d use phpunit (I just dig it), but it’s still lagging in some areas but shows promise of catching up RSN. The nice thing is that, IIRC, there are means of using tests (and test suites) developed for one framework in another. Lemme try to find the details of that and if I find it, I’ll post a follow up comment. (Oh, and the web interface for simpletest is nice – I was using it all of yesterday testing various workflows through a webapp (asserTitle, assertWantedText, etc) that I’m currently working on in addition to being able to do TDD from the front end).

  2. Yeah, simpletest seems to be quite popular. Take a look at the sitepoint PHP forum (PHP Application Design) and you will find several topics on it, also one comparing it with phpunit. Also Chris (to whom you linked) is weighing in and talking about how Apache-Test comes into the equation.

  3. I’ve been using PHPUnit2 to write unittests for my Phlickr project (PHP5 and Flickr). It works well enough but if I were starting it now I’d probably go with SimpleTest. PHPUnit 1 is feature poor but if you’re going to be using the latest version of PHPUnit2 you’ll need PHP 5.1 which no ISPs offer. I’ve gotten pretty frustrated with it.

  4. Check out http://www.FissatoHosting.com the have custom offerings that can do PHP 5.1 or basically anything u need on the server

Leave a Reply

Your email address will not be published.


© 2019 rc3.org

Theme by Anders NorenUp ↑