Skip to content

Commit

Permalink
Finally got Jenkins to accept the Junit.xml. Need to take out unnecce…
Browse files Browse the repository at this point in the history
…sary attributes now
  • Loading branch information
Amjad Mohamed committed Nov 3, 2011
1 parent 259476a commit 2ccfd0c
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/PHPSpec/Runner/Formatter/Junit.php
Expand Up @@ -62,7 +62,7 @@ public function __construct (Reporter $reporter)
*/
public function output ()
{
$output = '<xml version="1.0">' . PHP_EOL;
$output = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
$output .= '<testsuites>' . PHP_EOL . $this->_result;
$output .= '</testsuites>' . PHP_EOL;
echo $output;
Expand All @@ -81,9 +81,12 @@ protected function _startRenderingExampleGroup($reporterEvent)

protected function _finishRenderingExampleGroup()
{
$output = ' <testsuite tests="' . $this->_total . '" ';
$output = ' <testsuite name="'.$this->_currentGroup.'" tests="' . $this->_total . '" ';
$output .= 'assertions="' . $this->_total . '" ';
$output .= 'failures="' . $this->_failures . '" ';
$output .= 'errors="' . $this->_errors . '">' . PHP_EOL;
$output .= 'errors="' . $this->_errors . '" ';
$output .= 'time="0.01" ';
$output .= '>' . PHP_EOL;
$output .= $this->_examples;
$output .= ' </testsuite>' . PHP_EOL;
$this->_result .= $output;
Expand All @@ -105,11 +108,17 @@ protected function _renderExamples($reporterEvent)
$this->_total++;

$status = $reporterEvent->status;

$output = ' <testcase class="' . $this->_currentGroup . '"';
$output .= ' name="' . $reporterEvent->example . '"';
$output .= ' file="filename.php"';
$output .= ' assertions="1"';
$output .= ' time="0.01"';
$output .= ' line="30"';

switch ($status) {
case '.':
$output = ' <testcase classname="'
. $this->_currentGroup . '" name="' . $reporterEvent->example
. '" />' . PHP_EOL;
$output .= ' />' . PHP_EOL;
$this->_examples .= $output;

$this->_complete++;
Expand All @@ -120,10 +129,9 @@ protected function _renderExamples($reporterEvent)
$error .= ' ' . $reporterEvent->message;
$error .= ' </error>';

$output = ' <testcase classname="';
$output .= $this->_currentGroup . '" name="' . $reporterEvent->example;
$output .= '">' . PHP_EOL;
$output .= '>' . PHP_EOL;
$output .= $error . PHP_EOL;
$output .= ' </testcase>' . PHP_EOL;
$this->_examples .= $output;

$this->_errors++;
Expand All @@ -137,16 +145,15 @@ protected function _renderExamples($reporterEvent)

$error .= ' </error>';

$output = ' <testcase classname="';
$output .= $this->_currentGroup . '" name="' . $reporterEvent->example;
$output .= '">' . PHP_EOL;
$output .= '>' . PHP_EOL;
$output .= $error . PHP_EOL;
$output .= ' </testcase>' . PHP_EOL;
$this->_examples .= $output;

$this->_errors++;
break;
case 'F':
$error = ' <failure type"'.get_class($reporterEvent->exception).'">' . PHP_EOL;
$error = ' <failure type="'.get_class($reporterEvent->exception).'">' . PHP_EOL;

$error .= ' ' . $reporterEvent->example . '(FAILED)' . PHP_EOL;
$error .= ' ' . $reporterEvent->message . PHP_EOL;
Expand All @@ -155,10 +162,9 @@ protected function _renderExamples($reporterEvent)

$error .= ' </failure>';

$output = ' <testcase classname="';
$output .= $this->_currentGroup . '" name="' . $reporterEvent->example;
$output .= '">' . PHP_EOL;
$output .= '>' . PHP_EOL;
$output .= $error . PHP_EOL;
$output .= ' </testcase>' . PHP_EOL;
$this->_examples .= $output;

$this->_failures++;
Expand Down

0 comments on commit 2ccfd0c

Please sign in to comment.