Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Handle errors in the PHPUnit webreport.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic_chabant committed Mar 1, 2011
1 parent 40ba9fc commit 0be185e
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions tests/libs/phpunit_webreport/PHPUnit/WebReport/Dashboard.php
Expand Up @@ -6,6 +6,7 @@
class PHPUnit_WebReport_Dashboard
{
public $report;
public $errors;

public function __construct($logFile, $format = 'xml')
{
Expand All @@ -26,19 +27,32 @@ public function getReportCss()

public function display($headerLevel = 2)
{
echo '<div class="test-report">';

// Summary of the test run.
echo '<div class="test-report-summary">';
$this->displayStats($this->report);
echo '</div>';

// Details on test suites that failed.
foreach ($this->report->testSuites as $testsuite)
if ($this->errors === null)
{
$this->displayTestSuite($testsuite, true, $headerLevel);
echo '<div class="test-report">';

// Summary of the test run.
echo '<div class="test-report-summary">';
$this->displayStats($this->report);
echo '</div>';

// Details on test suites that failed.
foreach ($this->report->testSuites as $testsuite)
{
$this->displayTestSuite($testsuite, true, $headerLevel);
}
echo '</div>';
}
else
{
echo '<div class="test-report">';
echo '<h' . $headerLevel . '>Error reading PHPUnit log</h' . $headerLevel . '>';
foreach ($this->errors as $error)
{
echo '<p>' . $error . '</p>';
}
echo '</div>';
}
echo '</div>';
}

protected function displayStats($stats)
Expand Down Expand Up @@ -94,7 +108,7 @@ protected function displayTestSuite($testsuite, $skipSuccessful, $headerLevel)
echo '<div class="failures">';
foreach ($testcase->failures as $failure)
{
echo '<pre>' . $failure . '</pre>';
echo '<pre>' . htmlentities($failure) . '</pre>';
}
echo '</div>';
}
Expand All @@ -103,7 +117,7 @@ protected function displayTestSuite($testsuite, $skipSuccessful, $headerLevel)
echo '<div class="errors">';
foreach ($testcase->errors as $error)
{
echo '<pre>' . $error . '</pre>';
echo '<pre>' . htmlentities($error) . '</pre>';
}
echo '</div>';
}
Expand All @@ -123,10 +137,23 @@ protected function parseXmlLog($logFile)
{
$report = new PHPUnit_WebReport_Report();

libxml_use_internal_errors(true);
$results = simplexml_load_file($logFile);
foreach ($results->testsuite as $ts)
if (!$results)
{
$this->errors = array();
foreach (libxml_get_errors() as $error)
{
$this->errors[] = $error->message . " (in '" . $error->file . "', line " . $error->line . ", column " . $error->column . ")";
}
libxml_clear_errors();
}
else
{
$report->testSuites[] = $this->parseXmlTestSuite($ts);
foreach ($results->testsuite as $ts)
{
$report->testSuites[] = $this->parseXmlTestSuite($ts);
}
}

return $report;
Expand Down

0 comments on commit 0be185e

Please sign in to comment.