API Stream Wrappers – Week 8

This week I started doing some serious work with unit testing. I initially wanted to be able to run the tests directly with PHPUnit but discovered that it would be considerably more convenient to have WordPress setup and installed and torn down for each test. So at the moment I’m piggybacking on WordPress Automated Tests. It gets the job done as far as simple testing goes, but several notable features that PHPUnit provides are currently inaccessible such as coverage reports. I’m going to finish up writing the most critical tests for stream wrappers and then briefly look into improving the testing suite to see if coverage reports can be coaxed out without a major overhaul.

Tip: Automated Testing improvements would make a great project for GSoC next year 😉

At the moment the tests demonstrate that the system works top-to-bottom 😀 The registry is fully operational and a preliminary test was written for the new test stream wrapper (test://) that leverages the generic local stream wrapper class that’s included with the plugin. For example, the test proves that mkdir(‘test://dir1’) actually gets rerouted properly to create ‘wp-content/streams_test/dir1’. There’s still a lot remaining to test, especially edge cases [*cough*Windows*cough*], but things are coming together very nicely indeed.

Unit testing stream wrappers plugin mini-guide

Here’s a quick guide if you’re interested in running some of the tests, or even helping out by writing more!

First check out the following

  1. http://codex.wordpress.org/User:Hakre/WP_Unit-Tests
  2. http://codex.wordpress.org/Automated_Testing

Once you have the mundane prerequisites out of the way you can get to the more exciting tests.

  1. Put the stream wrappers plugin in the usual directory. This will probably be something like wp_automated_tests/wordpress/wp-content/plugins/
  2. Configure the wp-config.php file in the top-level directory as indicated in the Automated Testing Guide. Define DIR_TESTPLUGINS as follows:
    define('DIR_TESTPLUGINS', './wordpress/wp-content/plugins/wp-stream-wrappers/tests');

To run tests, use a variation of the following command: php wp-test.php -t [Test]

The following Stream wrapper specific tests are currently available:

  • WP_Stream_Wrapper_Registry_Test [completed]
  • WP_Stream_Test [completed]
  • WP_Local_Stream_Wrapper_Base_Test [in progress]
  • WP_File_Helpers_Test [in progress]