The code that creates the HTML is in PHPUnit/Util/TestDox/ResultPrinter/HTML.php and, unfortunately, I don't know how to extend it. You can just change it, but then you have to repeat this for each update, which can be annoying.
Since the output is still small, I would go the other way:
I would use the phpunit output of the .xml file (e.g. phpunit --log-junit foo.xml DemoTest.php ) and use xslt or the dom parser to convert the output to html. It doesn't have to be much work, and you can set it up very quickly.
I wrote a small example using xslt to convert output.
Test
<?php class DemoTest extends PHPUnit_Framework_TestCase { public function testPass() { $this->assertTrue(true); } public function testFail() { $this->assertTrue(false); } }
Create xml output
phpunit --log-junit foo.xml DemoTest.php
Xslt template
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h1>Tests</h1> <xsl:for-each select="testsuites/testsuite"> <h2><xsl:value-of select="@name"/></h2> <ul> <xsl:for-each select="testcase"> <li> <xsl:value-of select="@name"/> <xsl:if test="failure"> <b>Failed !</b> <i><xsl:value-of select="*"/></i> </xsl:if> </li> </xsl:for-each> </ul> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
Output conversion
xsltproc foo.xsl foo.xml > output.html
What does it look like
<html> <body> <h1>Tests</h1> <h2>DemoTest</h2> <ul> <li>testPass</li> <li>testFail<b>Failed !</b> <i>DemoTest::testFail Failed asserting that <boolean:false> is true. /home/edo/DemoTest.php:10 </i> </li> </ul> </body> </html>
and it should be easily adapted, since you can use all the values ββin the xml file, such as the runtime of each test, etc.
Alternatives
You can use DomParser, just change the PHPUnit class or maybe someone has a faster idea :)
edorian
source share