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
- http://codex.wordpress.org/User:Hakre/WP_Unit-Tests
- http://codex.wordpress.org/Automated_Testing
Once you have the mundane prerequisites out of the way you can get to the more exciting tests.
- Put the stream wrappers plugin in the usual directory. This will probably be something like wp_automated_tests/wordpress/wp-content/plugins/
- 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]
hakre 2:14 pm on August 31, 2010 Permalink |
I love Stream Wrapper. Thanks for taking care. I thought to write something that hooks on file:// just by default … 🙂
Jon Stacey 10:53 pm on October 10, 2012 Permalink |
That’s odd… I just got an email notification of your comment today… Yep, 2 years behind schedule.
Wish I could spend more time on this, [school/life/loans and whatnot]. If you need to make any changes or find bugs in the code be sure to send a pull request on GitHub and I’ll get it incorporated at least. And if you have a plugin which depends on this one update the wiki to mention it.
Cheers!