Skip to content

Commit

Permalink
Fixed some code documentation missing/too long lines in junit formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelloDuarte committed Nov 22, 2011
1 parent 90b4cf9 commit 6ea4162
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/PHPSpec/Runner/Formatter/FormatterAbstract.php
Expand Up @@ -39,7 +39,7 @@ abstract class FormatterAbstract implements Formatter
* update the output
*
* @param SplSubject $method
* @param unknown $reporterEvent
* @param PHPSpec\Runnner\ReporterEvent $reporterEvent
*/
public function update(\SplSubject $method, $reporterEvent = null)
{
Expand Down
104 changes: 69 additions & 35 deletions src/PHPSpec/Runner/Formatter/Junit.php
Expand Up @@ -16,24 +16,23 @@
* @package PHPSpec
* @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
* @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
* Marcello Duarte
* Marcello Duarte
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*
*
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite
name="TestDummy"
file="/home/mmueller/Development/Checkouts/trivago-php/tests/unit/TestDummy.php"
tests="1" assertions="1" failures="0" errors="0" time="0.005316">
<testcase name="testNothing" class="TestDummy"
file="/home/mmueller/Development/Checkouts/trivago-php/tests/unit/TestDummy.php"
line="12" assertions="1" time="0.005316"/>
</testsuite>
</testsuites>
*/
*/
namespace PHPSpec\Runner\Formatter;
use PHPSpec\Util\Backtrace, PHPSpec\Specification\Result\DeliberateFailure, PHPSpec\Runner\Reporter;

use PHPSpec\Util\Backtrace,
PHPSpec\Specification\Result\DeliberateFailure,
PHPSpec\Runner\Reporter;

/**
* @category PHPSpec
* @package PHPSpec
* @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
* @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
* Marcello Duarte
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
class Junit extends Progress
{

Expand All @@ -51,12 +50,16 @@ class Junit extends Progress
private $_total = 0;
private $_complete = 0;
private $_errorOnExit = false;


/**
* Creates the formatter adding a testsuites root to the xml
*/
public function __construct (Reporter $reporter)
{
parent::__construct($reporter);
$this->_xml = new \SimpleXMLElement("<testsuites></testsuites>");
}

/**
* Prints the report in a specific format
*/
Expand All @@ -70,7 +73,9 @@ public function output ()

/**
* Opens the testsuite tag
* @see PHPSpec\Runner\Formatter\FormatterAbstract::_startRenderingExampleGroup()
* @see FormatterAbstract::_startRenderingExampleGroup()
*
* @param PHPSpec\Runnner\ReporterEvent $reporterEvent
*/
protected function _startRenderingExampleGroup($reporterEvent)
{
Expand All @@ -79,6 +84,9 @@ protected function _startRenderingExampleGroup($reporterEvent)
$this->_currentGroup = $reporterEvent->example;
}

/**
* Finishes rendering an example group
*/
protected function _finishRenderingExampleGroup()
{
$output = ' <testsuite name="'.$this->_currentGroup.'" ';
Expand All @@ -104,6 +112,11 @@ protected function _finishRenderingExampleGroup()
$this->_complete = 0;
}

/**
* Render examples
*
* @param PHPSpec\Runnner\ReporterEvent $reporterEvent
*/
protected function _renderExamples($reporterEvent)
{
$this->_total++;
Expand All @@ -125,7 +138,9 @@ protected function _renderExamples($reporterEvent)
$this->_complete++;
break;
case '*':
$error = ' <error type="'.get_class($reporterEvent->exception).'">' . PHP_EOL;
$error = ' <error type="';
$error .= get_class($reporterEvent->exception) . '">';
$error .= PHP_EOL;
$error .= ' Skipped Test: ' . $reporterEvent->example;
$error .= ' ' . $reporterEvent->message;
$error .= ' </error>';
Expand All @@ -138,8 +153,10 @@ protected function _renderExamples($reporterEvent)
$this->_errors++;
break;
case 'E':
$error = ' <error type="'.get_class($reporterEvent->exception).'">' . PHP_EOL;
$error .= ' ' . $reporterEvent->example . '(FAILED)' . PHP_EOL;
$error = ' <error type="';
$error .= get_class($reporterEvent->exception).'">' . PHP_EOL;
$error .= ' ' . $reporterEvent->example . '(FAILED)';
$error .= PHP_EOL;
$error .= ' ' . $reporterEvent->message . PHP_EOL;
$error .= ' ' . $reporterEvent->backtrace . PHP_EOL;
$error .= $this->getCode($reporterEvent->exception) . PHP_EOL;
Expand All @@ -154,9 +171,11 @@ protected function _renderExamples($reporterEvent)
$this->_errors++;
break;
case 'F':
$error = ' <failure type="'.get_class($reporterEvent->exception).'">' . PHP_EOL;
$error = ' <failure type="';
$error .= get_class($reporterEvent->exception).'">' . PHP_EOL;

$error .= ' ' . $reporterEvent->example . '(FAILED)' . PHP_EOL;
$error .= ' ' . $reporterEvent->example . '(FAILED)';
$error .= PHP_EOL;
$error .= ' ' . $reporterEvent->message . PHP_EOL;
$error .= ' ' . $reporterEvent->backtrace . PHP_EOL;
$error .= $this->getCode($reporterEvent->exception) . PHP_EOL;
Expand Down Expand Up @@ -202,15 +221,16 @@ protected function getCode($e)
}

/**
* Cleans and returns a line. Removes php tag added to make highlight-string
* work
* Cleans and returns a line. Removes php tag added to make
* highlight-string work
*
* @param unknown_type $traceline
* @param unknown_type $relativePosition
* @param unknown_type $style
* @return Ambigous <string, mixed>
* @param array $traceline
* @param integer $relativePosition
* @param string $style
* @return string
*/
protected function getLine($traceline, $relativePosition, $style = 'normal')
protected function getLine($traceline, $relativePosition,
$style = 'normal')
{
$code = Backtrace::readLine(
$traceline['file'],
Expand All @@ -228,13 +248,23 @@ protected function _onExit()
}

/**
* Creates a testcase
*
* @param \SimpleXMLElement $suite
* @param string $name
* @param string $class
* @param string $file
* @param integer $line
* @param string $assertions
* @param integer $executionTime
*
* @return SimpleXMLElement
* <testcase name="testNothing" class="TestDummy"
* file="/home/mmueller/Development/Checkouts/trivago-php/tests/unit/TestDummy.php"
* file="/home/mmueller/dev/trivago-php/tests/unit/TestDummy.php"
* line="12" assertions="1" time="0.005316"/>
*/
private function createCase (\SimpleXMLElement $suite, $name, $class, $file,
$line, $assertions, $executionTime)
private function createCase (\SimpleXMLElement $suite, $name, $class,
$file, $line, $assertions, $executionTime)
{
$child = $suite->addChild('testcase');
$child->addAttribute('name', $name);
Expand All @@ -245,21 +275,25 @@ private function createCase (\SimpleXMLElement $suite, $name, $class, $file,
$child->addAttribute('executionTime', $executionTime);
return $child;
}

/**
* Creates suite
*
* @param $name
* @param $file
* @param $testcount
* @param $assertions
* @param $failures
* @param $errors
* @param $executionTime
*
* @return SimpleXMLElement
* <testsuite name="TestDummy"
* file="/home/mmueller/Development/Checkouts/trivago-php/tests/unit/TestDummy.php"
* file="/home/mmueller/dev/trivago-php/tests/unit/TestDummy.php"
* tests="1" assertions="1" failures="0" errors="0" time="0.005316">
*/
private function createSuite ($name, $file, $testcount, $assertions,
$failures, $errors, $executionTime)
$failures, $errors, $executionTime)
{
$testSuite = $this->_xml->addChild("testsuite");
$testSuite->addAttribute("name", $name);
Expand Down
2 changes: 1 addition & 1 deletion src/PHPSpec/Specification/Interceptor/ArrayVal.php
Expand Up @@ -32,7 +32,7 @@
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
class ArrayVal extends Interceptor implements \ArrayAccess
{
{
/**
* Checks whether actual value has a key
*
Expand Down

0 comments on commit 6ea4162

Please sign in to comment.