While tackling with someones question i decided it’s time to play around with XSLT for learning purposes and i found something useful to do.<p />He wanted to extend the –testdox-html output and i proposed to just transform PHPUnits XML output using an XSLT since i didn’t see a easy way to prove a custom implementation for PHPUnit/Util/TestDox/ResultPrinter/HTML.php and i didn’t want to change the file its self.

So let’s play around a bit.

A simple test:

class DemoTest extends PHPUnit_Framework_TestCase {

  public function testPass() {

  public function testFail() {

and generate some XML, for that test i used the jUnit output:

phpunit --log-junit foo.xml DemoTest.php

and write a simple XSLT. It might not be the best way to do that but like i said: I’m just looked for something to learn about XSLT so correct my if I’m wrong.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <xsl:for-each select="testsuites/testsuite">
      <h2><xsl:value-of select="@name"/></h2>
        <xsl:for-each select="testcase">
            <xsl:value-of select="@name"/>
            <xsl:if test="failure">
              <b>Failed !</b>
              <i><xsl:value-of select="*"/></i>
</xsl:stylesheet> > and using that with the XML output using a Linux command line tool:

xsltproc foo.xsl foo.xml > output.html

and that produces a nice litte HTML files:

  <li>testFail<b>Failed !</b></code></div>
  Failed asserting that <boolean:false> is true.


To make at least something a litte more useful out of that blog post:

I’m planing about writing about use cases for phpab and on how to ship your PHP_CodeSniffer coding standard with your project. If you have further suggestions I’d like to hear them.


19 January 2011


blog comments powered by Disqus