PHPUnit Testing in the Browser
Introduction
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:
http://localhost/PHPUnit-Test-Report/?path=PATH_TO_TEST_FILES
Or you can add an index in your tests directory (tests/index.php) and include PHPUnit Test Report’s index:
include '../../PHPUnit-Test-Report/index.php';
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.
Your Turn.
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!


Comments
Ryan McCue • http://ryanmccue.info/
Tuesday, June 29th, 2010
Matt Mueller
Wednesday, June 30th, 2010
KRavEN
Saturday, July 31st, 2010
ncorpse • http://moshcode.info
Monday, August 23rd, 2010
Asher Snyder • http://www.noloh.com
Saturday, September 18th, 2010
dave
Friday, September 24th, 2010
Jean-Philippe
Tuesday, November 9th, 2010
meze
Friday, November 12th, 2010
Shaked
Thursday, January 13th, 2011
Shaked
Thursday, January 13th, 2011
Matt Mueller
Thursday, January 13th, 2011
Theodore R. Smith • http://www.phpexperts.pro/
Sunday, January 23rd, 2011
NSinopoli • https://github.com/NSinopoli/VisualPHPUnit
Monday, March 21st, 2011
Matt Mueller
Tuesday, March 22nd, 2011
NSinopoli
Monday, April 4th, 2011
JKrems • http://hybrissimo.com
Tuesday, June 14th, 2011
Nick Turner • http://www.nickturner.co.uk/libs/PHPUnit_Html/demo
Monday, July 18th, 2011
Greenbar: Browser-Based TDD for Python | Yet Another Programming Blog • http://www.davehking.com/wordpress/?p=355
Sunday, August 21st, 2011
Sebastian Bergmann • http://sebastian-bergmann.de/
Thursday, August 25th, 2011
Matt Mueller
Thursday, August 25th, 2011