private function ReportEvent(Event &$event) { $report = ' <type>' . htmlentities($event->GetTypeAsString()) . "</type>\n"; $report .= ' <time>' . htmlentities($event->GetTime()) . "</time>\n"; $type = $event->GetType(); if (EventType::START_SETUP() == $type || EventType::END_SETUP() == $type || EventType::START_RUN() == $type || EventType::END_RUN() == $type || EventType::START_TEAR_DOWN() == $type || EventType::END_TEAR_DOWN() == $type) { return $report; } if (EventType::USER_MSG() != $type || EventType::PASS_MSG() != $type || EventType::FAIL_MSG() != $type) { $report .= ' <reason>' . htmlentities($event->GetReason()) . "</reason>\n"; } if (EventType::SYS_MSG() != $type) { $report .= ' <message>' . htmlentities($event->GetMessage()) . "</message>\n"; } if (EventType::SYS_MSG() != $type && EventType::USER_MSG() != $type && EventType::FAIL_MSG() != $type && EventType::PASS_MSG() != $type && EventType::EXCEPTION_THROWN() != $type) { $report .= " <actual>\n" . ' <type>' . htmlentities($event->GetActualType()) . "</type>\n" . ' <value>' . htmlentities($event->GetActualValue()) . "</value></actual>\n"; $report .= " <comparison>\n" . ' <type>' . htmlentities($event->GetComparisonType()) . "</type>\n" . ' <value>' . htmlentities($event->GetComparisonValue()) . "</value></comparison>\n"; } if (EventType::SYS_MSG() != $type) { $report .= ' <file>' . htmlentities($event->GetFile()) . "</file>\n"; $report .= ' <line>' . htmlentities($event->GetLine()) . "</line>\n"; } return $report; }
public function Run(TestSuiteResult &$results) { $this->allPassed = true; foreach ($this->testCases as $className) { // Loop through test cases $testCase = new $className(); $testCaseResult = new TestCaseResultConstructor($className, $testCase->GetID()); if (!$testCase instanceof TestCase) { throw new Exception('The class "' . $className . '" is not an instance of TestCase!'); } // Initialise the test case $testCase->Init($testCaseResult); // Perform set up $testCaseResult->AddTimeStamp(EventType::START_SETUP()); try { $testCase->SetUp(); $okToRun = $testCaseResult->TestPassed(); } catch (Exception $e) { $testCaseResult->SetDetails($testCase->GetName(), $testCase->GetID(), $testCase->GetDescription()); $testCaseResult->AddException('Uncaught exception thrown in \'SetUp\'.', $e); $testCaseResult->AddTimeStamp(EventType::END_SETUP()); $okToRun = false; } $testCaseResult->SetDetails($testCase->GetName(), $testCase->GetID(), $testCase->GetDescription()); if ($okToRun) { // As SetUp ran successfully, run the test $testCaseResult->AddMessage('Setup completed.', EventType::SYS_MSG()); $testCaseResult->AddTimeStamp(EventType::END_SETUP()); try { $testCaseResult->AddTimeStamp(EventType::START_RUN()); $testCase->Run(); $testCaseResult->AddMessage('Test case completed.', EventType::SYS_MSG()); $testCaseResult->AddTimeStamp(EventType::END_RUN()); } catch (Exception $e) { $testCaseResult->AddException('Uncaught exception thrown in \'Run\'.', $e); $testCaseResult->AddTimeStamp(EventType::END_RUN()); // Try to tear down so potentially other tests can run! } } else { $testCaseResult->AddMessage('Setup failed - Not running test case.', EventType::SYS_MSG()); } // Tidy up try { $testCaseResult->AddTimeStamp(EventType::START_TEAR_DOWN()); $testCase->TearDown(); $testCaseResult->AddMessage('TearDown completed.', EventType::SYS_MSG()); $testCaseResult->AddTimeStamp(EventType::END_TEAR_DOWN()); } catch (Exception $e) { $testCaseResult->AddException('Uncaught exception thrown in \'TearDown\'.', $e); $testCaseResult->AddTimeStamp(EventType::END_TEAR_DOWN()); } $results->AddTestCaseResult($testCaseResult); $this->allPassed = $this->allPassed && $testCaseResult->TestPassed(); $testCase = null; // Should call the garbage collector } }