PHPUnit Testing in the Browser
Over the last couple weeks, I’ve been learning PHPUnit. PHPUnit is a unit testing framework for PHP, based on the JUnit framework for JAVA. It was created by Sebastian Bergmann. I’ll be the first to say that it is a wonderful library and it greatly simplifies Unit Testing in PHP. That being said, PHPUnit is not pretty. You mainly interact with it through the terminal. Now, I like pretty things. The web is pretty. Web development is pretty (with Textmate at least). Why can’t unit testing be pretty? A few days ago, I set out to resolve this issue.
PHPUnit Test Report
PHPUnit Test Report is designed to make unit testing fun. It discovers all files in your test folder that have the suffix “TestCase.php”. From there it loads and runs any classes within those files that have the suffix “TestCase”. Following standard PHPUnit procedures, it will run all methods that has the prefix “test”. For the case above, it is loading the class “TagTestCase” (from file TagTestCase.php). It will then proceed to run through all its methods that have “test” in front of them – so it runs testStylesheet, testScript, testRemoveScript, etc.
The result colors represent the following:
- Red – Failed (or error)
- Green – Pass
- Yellow – Skipped
- Grey – Incomplete
Let’s learn about some of PHPUnit Test Report’s features.
Sandbox that PHP
PHPUnit Test Report sandboxes your PHP. If you have an error in your code, the report will give you information about the error.
Talk to me PHPUnit
One of the most frustrating aspects of Unit Testing with PHPUnit was that I was unable to print variables within the tests to help me debug my application. PHPUnit Test Report handles this nicely:
Link PHPUnit Test Report to your Tests
I made it really easy to start using PHPUnit Test Report immediately. You can either go to PHPUnit Test Report’s index in the browser and add the path to your tests:
Or you can add an index in your tests directory (tests/index.php) and include PHPUnit Test Report’s index:
Start using PHPUnit Test Report today
Excited yet? I’m releasing PHPUnit Test Report today. PHPUnit 3.4.13 comes with the report. It should be self-contained, but let me know if you have any issues. As far as the continual development of this project, I started learning PHPUnit about a week ago, so I have a lot to learn about it. As I learn more and continue to test my applications, I’ll add more stuff. I’ll try to help as best I can with issues you run into but, I can’t guarantee that I’ll be able to help. Feel free to get under the hood and hack something up. It’s pretty basic code.
Download PHPUnit Test Report
Click the link below to go to PHPUnit Test Report’s project page on GitHub.
The project is now hosted on GitHub. I’d love to see any contributions on your part – someone with some real PHPUnit experience could really do some damage with this application! Happy testing!