49

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.

Pekka
  • 418,526
  • 129
  • 929
  • 1,058
  • +1 Say Pekka, you're not able to read my mind, are you? – middus Mar 11 '10 at 11:25
  • @middus there are *amazing* coincidences on SO sometimes. :) – Pekka Mar 11 '10 at 11:30
  • You also might want to check out Hudson as an alternative for phpUnderControl. A nice article (with some good online references) on how to set it up can be found at http://luhman.org/blog/2009/12/16/installing-hudson-phing-phpunit-and-git-ubuntu – wimvds May 18 '10 at 13:58
  • @wim very nice, will take a look into it. Thanks! – Pekka May 18 '10 at 14:00

11 Answers11

26

I recently discovered Visual PHPUnit which looks like a very very nice interface for everyone that doesn't want to run PHPUnit from the command line:

Visual PHPUnit

It seems to be the next iteration of @Matt's PHPUnit Test Report

edorian
  • 36,948
  • 13
  • 119
  • 141
21

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
(source: mattmueller.me)

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

Cheers! Matt

Glorfindel
  • 19,729
  • 13
  • 67
  • 91
Matt
  • 19,783
  • 24
  • 71
  • 113
18

After several hours of researching recently, the best PHPUnit web frontend I have come across was https://github.com/NSinopoli/VisualPHPUnit

Motin
  • 4,093
  • 2
  • 38
  • 47
14

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 it is gone for some time now. You might be able to find an old copy with Google somewhere.

Since you mention this is for phpUnderControl: if you are not fixed on that, consider using Jenkins and http://jenkins-php.org.

On a side note: unless we are talking CI servers, most people I know don't use PHPUnit through a web interface. They either just use the command line or their IDE integration.

Gordon
  • 296,205
  • 68
  • 508
  • 534
  • 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 Mar 11 '10 at 11:39
  • @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 Mar 11 '10 at 11:47
  • I wasn't able to use these tools being a newbie with phpunit. Created 2 files for each tool and have no idea what to do with them. – user1 Oct 04 '16 at 14:46
  • @mr_jigsaw tbh, as a newbie get to grips with how to use phpunit from cli. that's what it's for. unless you want to integrate with some sort of CI solution or need custom reports, there is no real benefit in using it any other way. Also, most IDEs come with phpunit integration, e.g. a simple ui interface. That should be really good enough for any use cases you have right now. – Gordon Oct 10 '16 at 08:45
  • @Gordon "that's what it's for" - it's for showing me which tests failed. And I want the output to be a nice webpage, not some text in console. Whenever CLI phpunit is useful I can't imaging GUI phpunit not being useful. And it's everybody's decision what is more clear to read for them. For me it's GUI. – user1 Oct 10 '16 at 11:16
  • @mr_jigsaw I understand that you *think* it would be clearer for you *right now*. But I can assure you that it's a misconception. No one I know who's doing php for a living uses it with a webpage. And I know a lot of people, including the original author of phpunit as well as several contributors. They don't use it with a webpage. Of course, you are free to create your own reports. I am telling you it's a waste of time. Embrace your command line or use your IDE's integration (PHPStorm shows test results visually and generates coverage reports). Or setup a CI server (Travis/Jenkins). – Gordon Oct 10 '16 at 11:35
7

You can use Jenkins to run any kind of tasks including PHPUnit tests. It can automatically checkout your app, run the tests, build a HTML report and even email you if the build fails.

Here's the templates you need to setup Jenkins to build a bunch of interesting reports and stats from your project.

Tom
  • 30,868
  • 31
  • 81
  • 104
2

If you don't care about reformatting the output and just want to run PHPUnit from a web page, you can do so with some PHP code like this:

<pre>
<?php 
$argv[0] = "phpunit.phar";
$argv[1] = '--bootstrap';
$argv[2] = 'src/load.php';
$argv[3] = "tests/MoneyTest";
$_SERVER['argv'] = $argv;
include 'phpunit.phar';
?>
</pre>

The file src/load.php is just a bunch of includes to include the classes. The output then looks like this:

#!/usr/bin/env php
PHPUnit 4.1.2 by Sebastian Bergmann.

........................

Time: 122 ms, Memory: 3.25Mb

OK (24 tests, 43 assertions)

Just ignore that first line and you can see the results.

I'm shocked that PHPUnit does not include a basic way to do this. Some classes may be dependent on the web server. Do we just not test those? Some sites have you upload your files and don't allow command line executions.

Charles
  • 1,005
  • 11
  • 12
1

jframework also has a nice UI for PHPUnit. It breaks the results, and shows test coverage on all files and each file separately. It works on both web and cli, with the cli one having the benefit of dumping every test after its done (the web-based one has to wait until everything is over).

General web output, with code coverage per file

Code coverage report for a single file

AbiusX
  • 2,227
  • 19
  • 25
1

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
  • 374,560
  • 73
  • 631
  • 650
  • 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 Mar 11 '10 at 11:37
  • 1
    Netbeans also has a handy PHPUnit Runner GUI, allows debugging of the test too which is useful when the tests are failing/erroring for unknown reasons. – Jonathan Day Dec 15 '10 at 23:38
1

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)

Community
  • 1
  • 1
Pekka
  • 418,526
  • 129
  • 929
  • 1,058
1

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 Napoli
  • 42,736
  • 37
  • 154
  • 239
0

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
  • 523
  • 7
  • 17