PHP Unit Testing Framework 1
A Unit testing framework for PHP.

xml_test_runner.php

Go to the documentation of this file.
00001 <?php
00035 
00036 require_once 'php_unit_test.php';
00037 
00051 class XMLTestRunner extends TestRunner
00052 {
00056   public function Report()
00057   {
00058     $report = '<?xml version="1.0" standalone="yes"?' . '>';
00059     $report .= "\n<testresults>\n";
00060     $end = $this->GetNumberOfTestCaseResults();
00061     for ($loop = 0; $loop < $end; ++$loop)
00062     {
00063       $testCaseResult = $this->GetTestCaseResult($loop);
00064       $report .= $this->ReportTestCase($testCaseResult);
00065     }
00066     $report .= "</testresults>\n";
00067     return $report;
00068   }
00069   
00070   private function ReportEvent(Event &$event)
00071   {
00072     $report = '        <type>' .
00073               htmlentities($event->GetTypeAsString()) .
00074               "</type>\n";
00075     $report .= '        <time>' .
00076                htmlentities($event->GetTime()) .
00077                "</time>\n";
00078     $type = $event->GetType();
00079     if (EventType::START_SETUP() == $type ||
00080         EventType::END_SETUP() == $type ||
00081         EventType::START_RUN() == $type ||
00082         EventType::END_RUN() == $type ||
00083         EventType::START_TEAR_DOWN() == $type ||
00084         EventType::END_TEAR_DOWN() == $type)
00085     {
00086       return $report;
00087     }
00088     if (EventType::USER_MSG() != $type ||
00089         EventType::PASS_MSG() != $type ||
00090         EventType::FAIL_MSG() != $type)
00091     {
00092       $report .= '        <reason>' .
00093                  htmlentities($event->GetReason()) .
00094                  "</reason>\n";
00095     }
00096     if (EventType::SYS_MSG() != $type)
00097     {
00098       $report .= '        <message>' .
00099               htmlentities($event->GetMessage()) .
00100               "</message>\n";
00101     }
00102     if (EventType::SYS_MSG() != $type &&
00103         EventType::USER_MSG() != $type &&
00104         EventType::FAIL_MSG() != $type &&
00105         EventType::PASS_MSG() != $type &&
00106         EventType::EXCEPTION_THROWN() != $type)
00107     {
00108       $report .= "        <actual>\n" .
00109                  '          <type>' . htmlentities($event->GetActualType()) . "</type>\n" .
00110                  '          <value>'.
00111                  htmlentities($event->GetActualValue()) .
00112                  "</value></actual>\n";
00113       $report .= "        <comparison>\n" .
00114                  '          <type>' . htmlentities($event->GetComparisonType()) . "</type>\n" .
00115                  '          <value>'.
00116                  htmlentities($event->GetComparisonValue()) .
00117                  "</value></comparison>\n";
00118     }
00119     if (EventType::SYS_MSG() != $type)
00120     {
00121       $report .= '        <file>' .
00122                  htmlentities($event->GetFile()) .
00123                  "</file>\n";
00124       $report .= '        <line>' .
00125                  htmlentities($event->GetLine()) .
00126                  "</line>\n";
00127     }
00128     return $report;
00129   }
00130   
00131   private function ReportTestCase(&$testCaseResult)
00132   {
00133     $report = "  <testcase>\n";
00134     $report .= '    <name>' .
00135                htmlentities($testCaseResult->GetName()) .
00136                "</name>\n";
00137     $report .= '    <id>' .
00138                htmlentities($testCaseResult->GetID()) .
00139                "</id>\n";
00140     $report .= '    <description>' .
00141                htmlentities($testCaseResult->GetDescription()) .
00142                "</description>\n";
00143     $report .= '    <passed>' .
00144                ($testCaseResult->TestPassed() ? 'Yes' : 'No') .
00145                "</passed>\n";
00146     $report .= "    <listOfEvents>\n";
00147     $end = $testCaseResult->GetNumberOfEvents();
00148     for ($loop = 0; $loop < $end; ++$loop)
00149     {
00150       $report .= "      <event>\n";
00151       $event = $testCaseResult->GetEvent($loop);
00152       $report .= $this->ReportEvent($event);
00153       $report .= "      </event>\n";
00154     }
00155     $report .= "    </listOfEvents>\n";
00156     $report .= "  </testcase>\n";
00157 
00158     return $report;
00159   }
00160   
00177   public function Run(TestSuite &$suite,
00178                       $filename = null,
00179                       $extension = 'xml')
00180   {
00181     return parent::Run($suite, $filename, $extension);
00182   }
00183 }
00184 ?>
 All Data Structures Files Functions Variables

© 2011, Ed Heal