It's released... finally! Shinpuru (Japanese for "simple") is a small PHP testing tool to write easy and maintainable
test suites. Download one file, require()
it and write your test code, that's it:
<?php
require('shinpuru.php');
test('My website should have 10 articles on the front page', function(){
get('http://arkanis.de/');
assert_select('article', 10);
});
?>
The test file can then be run from the command line and reports the test results:
$ php basic_usage_test.php
Running: basic_usage_test.php
.
1 test successful
No tests failed, good job!
Additionally Shinpuru can run in autotest mode, that is it will automatically run the test suite as soon as a file
in the current directory changes (you can also monitor other directories and files as well). The result of each
run is then reported in the console and if you run Ubuntu Linux also with a nice confirmation bubble. That way
you only have to look at your console when a test failed.
Here's a short run down on what Shinpuru has to offer:
- Basic assertions: Assertions to verify the result of "usual" PHP code.
- HTTP request functions: Functions for common HTTP methods (
get()
, post()
, put()
, delete()
) and ability to
build customize requests in any way.
- HTTP/HTML/XML assertions: Assertions to verify the HTTP response using simple CSS selectors and XPath.
- Flow control assertions using checkpoints and exceptions.
- Contexts: You can structure your tests into several contexts (e.g. test for the front page, the archive, the backend,
etc.) and you can nest contexts if you want.
- Setup and teardown functions: Every context can contain setup and teardown functions that are run before and
after each test of the context.
- Autotest: You can run every Shinpuru test in the background. Every time a file is changed the test will be run
automatically and a nice confirmation bubble will notify you if all went well or if a test failed.
- Environments: Run or skip tests according to a command line option, e.g. skip database reset when the test is run
on the server in the production environment.
- No external dependencies (besides PHP 5.3 itself of course).
If you want to give Shinpuru a try, just take a look at the Shinpuru project page. It contains a nice tutorial
and will help you getting started. More experience users can also take a look at the reference to see the
details.
Development and Feedback
All this isn't new of course. Shinpuru is heavily inspired by testing frameworks of the Ruby world, mainly
Shoulda. It all started as a small idea to use the anonymous functions of PHP 5.3 and I got hooked
up in the process somehow. Shinpuru itself took about 3 weeks of my spare time but the work on the documentation
and refining the details continued for about 7 more weeks. Now I'm just happy the project is in a state where it
can be useful for other programmers.
If there is some interest in Shinpuru it's no problem to setup a public repository and a forum or something like that.
For now please feel free to post comments on this blog post or send me mails (see profile page). I'm very interested
in what people think about Shinpuru. :)