[pLog-svn] r3704 - in plog/trunk: . class/test class/test/helpers

oscar at devel.lifetype.net oscar at devel.lifetype.net
Thu Jul 6 13:27:25 GMT 2006


Author: oscar
Date: 2006-07-06 13:27:24 +0000 (Thu, 06 Jul 2006)
New Revision: 3704

Added:
   plog/trunk/class/test/helpers/
   plog/trunk/class/test/helpers/htmlreporter.class.php
Modified:
   plog/trunk/runtests.php
Log:
added a nicer html reporter


Added: plog/trunk/class/test/helpers/htmlreporter.class.php
===================================================================
--- plog/trunk/class/test/helpers/htmlreporter.class.php	2006-07-06 13:21:50 UTC (rev 3703)
+++ plog/trunk/class/test/helpers/htmlreporter.class.php	2006-07-06 13:27:24 UTC (rev 3704)
@@ -0,0 +1,119 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/test/PHPUnit/TestResult.php" );
+
+	/**
+	 * \ingroup Tests
+	 *
+	 * A nicer test reporter that generates readable HTML output
+	 */
+	class HTMLReporter
+	{
+		var $_result;
+		
+		function HTMLReporter( $result )
+		{
+			$this->_result = $result;
+		}
+		
+		function _getHeader()
+		{
+			return('<html>
+			        <head><title>LifeType Test Suite</title></head>
+			        <body>
+			        <h1>Test Report</h1>
+			        <table cols="4" border="1" width="100%">
+			        <thead style="text-align:left">
+			         <th>Group</th>
+			         <th>Test</th>
+			         <th>Status</th>
+			         <th>Message</th>
+			        </thead>
+			        <tbody>
+			      ');
+		}
+		
+		function _getFooter()
+		{
+			return( '</tbody>
+			         </table>
+			        '.$this->_getStats().'
+			         </body>
+			         </html>
+			      ');
+		}
+		
+		function _cleanGroupName( $group )
+		{
+			$group = strtolower( $group );
+			$group = str_replace( "_test", "", $group );
+			return( $group );
+		}
+		
+		function _getPassed( $test, $group = "" )
+		{
+			return( '<tr>
+			          <td><b>'.$this->_cleanGroupName($group).'</b></td>			
+			          <td>'.$test->getName().'</td>
+			          <td style="background-color:green">PASSED</td>
+			          <td></td>
+			         ');
+		}
+		
+		function _getFailed( $test, $group = "" )
+		{
+			return( '<tr>
+			          <td><b>'.$this->_cleanGroupName($group).'</b></td>
+			          <td>'.$test->_failedTest->getName().'</td>
+			          <td style="background-color:red">FAILED</td>
+			          <td>'.$test->_thrownException.'</td>
+			         ');			
+		}
+		
+		function _getStats()
+		{
+			return( '<h1>Test Stats</h1>
+			         <b>Number of tests: </b>'.$this->_result->runCount().'<br/>
+			         <b>Number of tests passed: </b>'.($this->_result->runCount() - $this->_result->failureCount()).'<br/>
+			         <b>Number of tests failed: </b>'.$this->_result->failureCount().'<br/>
+			       ');
+		}
+		
+		function generate()
+		{
+			$groups = $this->_prepare();
+			
+	        $result = $this->_getHeader();
+	
+			foreach( $groups as $group => $tests ) {
+				$i=0;
+				foreach( $tests as $test ) {
+					$i++;
+					$i == 1 ? $groupName = $group : $groupName = "";
+					if( isset( $test->_failedTest )) {
+						$result .= $this->_getFailed( $test, $groupName );
+					}
+					else {
+						$result .= $this->_getPassed( $test, $groupName );
+					}
+				}
+			}
+
+	        $result .= $this->_getFooter();
+			return( $result );
+		}
+		
+		function _prepare()
+		{
+			$groups = Array();
+	        foreach ($this->_result->_passedTests as $passedTest) {
+				$groups[get_class($passedTest)][] = $passedTest;
+	        }				
+	        foreach ($this->_result->_failures as $failedTest) {
+				$groups[get_class($failedTest->_failedTest)][] = $failedTest;
+	        }
+	
+			return( $groups );
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/trunk/runtests.php
===================================================================
--- plog/trunk/runtests.php	2006-07-06 13:21:50 UTC (rev 3703)
+++ plog/trunk/runtests.php	2006-07-06 13:27:24 UTC (rev 3704)
@@ -5,6 +5,7 @@
 	}
 
 	include_once( PLOG_CLASS_PATH."class/test/testrunner.class.php" );
+	include_once( PLOG_CLASS_PATH."class/test/helpers/htmlreporter.class.php" );	
 
 	// create a new TestRunner class, which will take care of loading all our
 	// tests cases, instantiate them and tell PHPUnit to run the tests
@@ -12,5 +13,6 @@
 	$result = $r->run();
 	
 	// check the results when ready
-	print( $result->toHTML());
+	$reporter = new HTMLReporter( $result );
+	print($reporter->generate());
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list