PHP, Drupal, and testing
I’m trying to work out the best way to automate testing of a Drupal module I’m developing for work. Rails, of course, comes with this capability built-in, and moving from writing a Rails app back to Drupal development has been painful (for this and several other reasons).
I’m constantly impressed at how PHP takes precisely the wrong approach in so many cases. For example, every source file is processed as if it were HTML (or some other plain-text file) with embedded code, even if that source file should produce no output.
There’s also a lack of free, usable debuggers. Oh sure, there’s XDebug… but try using that without Komodo for a real debugging session. It’s painful. Plus it requires you to install a Zend extension.
<span id="more-56"></span>
<p>There are test frameworks, though, including 2 frameworks called PHPUnit (<a href="http://phpunit.sourceforge.net/">1</a>, <a href="http://www.phpunit.de/">2</a> and <a href="http://www.lastcraft.com/simple_test.php">SimpleTest</a>, SimpleTest is actually relatively clever, but in particular, it doesn’t have anything on the order of Rails’ <a href="http://api.rubyonrails.org/classes/Test/Unit/Assertions.html#M000970"><code>assert_tag</code></a>. (I haven’t used either PHPUnit.) But it exists, and I’m already using it a bit.</p>
There’s also a simpletest.module for Drupal, which is usable, but it unfortunately conflates unit testing with functional testing (a.k.a. integration testing) by subclassing both the UnitTestCase and WebTestCase from SimpleTest.
So I’ve just spent some time trying to catalog the differences in PHP’s environment when run as an Apache module, a CGI application, or a command-line (CLI) script. My hope is to be able to write a reliable test framework runnable from the command-line, probably using a shell script to wrap the CGI version of PHP.
Of course, there’s no guarantee that Drupal will behave the same in CGI mode as it does under mod_php. This complicates matters. Nonetheless, it looks possible.
No comments
Jump to comment form | comments rss [?] | trackback uri [?]