views:

702

answers:

6

Is there a simple "Web interface" to running PHPUnit test suites? i.e. a PHP script that runs the test on the command line, and outputs a nicely formatted HTML result.

I develop web applications, and the day-to-day workflow usually switches between the IDE and the browser. I would like to have the unit testing in the same environment.

I'm looking for something really simple and PHP based - I am planning to get into phpUnderControl (which has the functionality I'm looking for) but not yet.

+3  A: 

You can use phing to run a PHPUnitTask and then convert the output with:

  • PHPUnitReport - This task transforms PHPUnit xml reports to HTML using XSLT.

Example:

<phpunitreport infile="reports/testsuites.xml" 
    format="frames" 
    todir="reports/tests" 
    styledir="/home/phing/etc"/>

See phpunit --help for the various output formats.

The 2.3 version of PHPUnit had a chapter on this, but since it is no longer in the current docs of PHPUnit, I'd refer to the Phing docs directly. Just linking it for reference:

Gordon
Cheers @Gordon this looks interesting. I would like to get around the additional dependency, though, so I'll try the blog post I found first (see below). If that doesn't work, I will come back to this.
Pekka
@Pekka the approach in the blog post seems similar. It also uses the XML and then reformats it to HTML. If you don't want to use phing, you could just get the XML from PHPUnit and use the XSLT of Phing to transform programmatically with PHP instead. I think the XSL files are here: http://phing.info/trac/browser/trunk/etc
Gordon
+1  A: 

I've never seen such a web-interface... But, as you say you are always using your IDE and your webbrowser, why not think the other way ?

i.e. a possible solution would be to launch the unittests from your IDE ;-)
Which means you should be able to click on the failing tests to "jump" to either the test method, or the reason that caused the test to fail, for instance.


In the PHP + PHPUnit world, I know that Zend Studio does that -- yes, it's not free, unfortunatly ;-(


Using Eclipse PDT, a solution would be to register PHPUnit as an external tool (see or instance this blogpost : Using PHPUnit with Eclipse PDT) -- but it's quite not sexy, and you cannot click on the results to jump the the methods/tests...

Another solution would be to develop a plugin to integrate PHPUnit into Eclipse PDT (like it's been done for Zend Studio, I suppose) -- A phpunit4eclipse was created some time ago, but it's just a start, and didn't get much succes, so the author didn't work on it after releasing that...

Pascal MARTIN
Cheers @Pascal, good hints but I use neither Zend nor Eclipse (I use phpEd). It's been a while since I've bought the last update so it could be that this is supported there as well by now - I will defintely check, good idea. I would still really prefer a IDE-independent solution for this, though.
Pekka
You're welcome :-) ;; Oh, ok about another IDE ^^
Pascal MARTIN
A: 

I found this:

I stumbeld upon a post from Parth Patil, whose solution was to create an xml-report from PHPUnit and then use this xml to create your own report.

I used his solution, made it PHPUnit 3.4 compatible and also added some Reflection to see my testcase doc-comments in the report. (Note: For the refelection i use the Zend_Framework reflection class)

Pekka
+1  A: 

Ok you said you'd prefer an independent IDE solution, but just so you know there is a recent plugin that enables executing PHPUnit simply into Eclipse, and having a nice representation (like in Zend Studio, but for free).

Here is the link, the main developper replies fast to emails too if you have a problem :

http://www.phpsrc.org/wiki/

I personnaly tested some web interface, but I have always been deceived (not really practital and stable). But this is your choice.

Matthieu
Cheers Matthieu, I don't use eclipse but this is still good to know. +1
Pekka
A: 

You can always use the Maven for PHP from which you can use the surefire reports (mvn site). More info here: http://www.php-maven.org

Softy
+3  A: 

I feel your frustration - I'm a UI guy myself. Looking at the terminal too long makes my head spin. I wrote a quick little application that you might find helpful.

PHPUnit test application

You can find it here: http://mattmueller.me/blog/introducing-phpunit-test-report

Cheers! Matt

Matt