About the Author

Chris Shiflett

Hi, I’m Chris: web craftsman, community leader, husband, father, and partner at Fictive Kin.


Power PHP Testing

The tutorial that Geoff Young and I gave at ApacheCon has sparked some discussion (mostly via email) that I think will lead to better testing tools for PHP developers. A PDF of our slides is now available:

Geoff also has some tarballs available that let you test a very simple PHP library (functions.inc) with Apache-Test, Simple-Test, PHPUnit, and phpt:

One of the tarballs demonstrates how to use the Simple-Test testing library within the Apache-Test testing framework. This is thanks to the work of Mike Lively, who has documented his work in his blog:

His most recent tarball contains everything you need to use these two tools together.

After we mentioned TAP (Test Anything Protocol) to Sebastian Bergmann, he added TAP support to PHPUnit. Now, at least conceptually, you can also use PHPUnit to write your tests. This gives PHP developers three choices for writing tests within the Apache-Test framework:

  • The bundled PHP port of Test::More
  • Simple-Test with the TAP Reporter
  • PHPUnit with the TAP Logger

We've also been discussing the various advantages and disadvantages of each tool as well as how we might be able to help make testing easier for PHP developers. One of the perspectives I've been highlighting is best stated by Matthew Weier O'Phinney in his blog:

I find writing the tests tedious. In Simple-Test, as in PHPUnit, you need to create a class that sets up the testing harness, and then you create a method for each test you wish to run, and so on. I found it incredibly time consuming.

I don't think Matthew knew about Apache-Test's Test::More library (it's as simple and straightforward as phpt tests), but this illustrates one of the disadvantages of testing tools that require a lot of overhead - they raise the barrier of entry (and they don't really fit in with the "PHP way" of solving problems as simply and directly as possible). This was one of the reasons why I ported Perl's Test::More library to PHP - it's very simple and doesn't get in your way. It also works with many mature testing tools already available (such as Apache-Test), because it's TAP-compliant.

Sebastian says he's working on adding phpt support to PHPUnit in an attempt to lower the barrier of entry.

On a related note, it looks like there will be a talk about this stuff at the 2006 PHP Quebec conference called Using Test::Harness to Test PHP Applications:

The Perl community has long had a very powerful unit-testing tool available: Test::Harness and friends. It uses what the Perl people call TAP - the Test Anything Protocol. I've used the Perl framework myself to verify correct behaviour in Perl modules and the Apache Web server. It came as a surprise to me that there was apparently no port of the technology to PHP, and so I've done some work toward correcting that. This session will include an introduction to the technology, a description of the implementation, and examples of how it can be used to test PHP applications.

I think Ken's interest highlights the usefulness of these tools. (He's been notified that this work has already been done, so hopefully it can save him some wasted time.) With any luck, Ken will not only talk about Test::More for PHP but also the TAP support that is now available in Simple-Test and PHPUnit.

About this post

Power PHP Testing was posted on Sat, 17 Dec 2005. If you liked it, follow me on Twitter or share:

2 comments

1.Geoffrey Young said:

yeah, it's pretty exciting what has been going on recently through a series of private emails - lots of interest in all the frameworks we covered, both in making themselves better and in creating TAP output formats.

as for Ken's talk, I find it very ironic that he mentions TAP by name but suggests that no work has been done in joining perl and php. especially since it wasn't called TAP until you decided "ok 1" needed a better name for our "Testing PHP with Perl" talk at ApacheCon2004 :)

Mon, 19 Dec 2005 at 18:11:07 GMT Link


2.nate parsons said:

Hey guys, I found this write up incredibly interesting! I've been riding the Ruby on Rails wave for a couple of months now, and have been very impressed with it's built in testing framework. I work at a shop that is primarly PHP based, and I'm interested in bringing functional & unit testing into the shop. Do you think you might expand or annotate your power point presentation a little more? I read it over quickly, but wasn't qutie able to follow all the wizbang moments in there. It sounds like testing is finally getting a little easier in PHP and I'd love to learn more about it. Anyhow thanks for putting all this great information together!

-nate

Fri, 30 Dec 2005 at 03:54:56 GMT Link


Hello! What’s your name?

Want to comment? Please connect with Twitter to join the discussion.