Skip to content

Commit

Permalink
Merge pull request #26 from heiglandreas/showMoreDetails
Browse files Browse the repository at this point in the history
Show more details on passing verbosity flags
  • Loading branch information
heiglandreas committed Jan 27, 2017
2 parents 2698b20 + 2779d8e commit 437e5e2
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Command/CompareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if ($output->getVerbosity() >= Output::VERBOSITY_NORMAL) {
$writer = new Standard($style);
$writer = new Standard($style, $output->getVerbosity());
$writer->write($mergeResult);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
continue;
}

if ($value['base'] != $value['current']) {
if ($value['base']['result'] != $value['current']['result']) {
$output->writeln(sprintf(
'<bg=blue;fg=yellow>o</> %s changed from <fg=cyan>%s</> to <fg=magenta>%s</>',
$key,
$array1[$key],
$array2[$key]
$array1[$key]['result'],
$array2[$key]['result']
));
continue;
}
Expand Down
30 changes: 29 additions & 1 deletion src/JUnitParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,42 @@ public function parseFile($filename)

$type = 'success';

$element = new \DOMNode();

foreach ($item->childNodes as $child) {
if ($child->nodeType != XML_ELEMENT_NODE) {
continue;
}
$type = $child->nodeName;
$element = clone($child);
}

$message = $ftype = $addInfo = '';

switch ($type) {
case 'error':
case 'failure':
if (! $element->hasAttributes()) {
break;
}
$message = $element->attributes->getNamedItem('message');
if ($message instanceof \DOMAttr) {
$message = $message->value;
}
$ftype = $element->attributes->getNamedItem('type');
if ($ftype instanceof \DOMAttr) {
$ftype = $ftype->value;
}
$addInfo = $element->textContent;
break;
}

$result[$class . '::' . $item->getAttribute('name')] = $type;
$result[$class . '::' . $item->getAttribute('name')] = [
'result' => $type,
'message' => $message,
'type' => $ftype,
'info' => $addInfo,
];

}

Expand Down
95 changes: 85 additions & 10 deletions src/Writer/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@
namespace Org_Heigl\JUnitDiff\Writer;

use Org_Heigl\JUnitDiff\MergeResult;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Style\StyleInterface;

class Standard implements WriterInterface
{
protected $style;

public function __construct(StyleInterface $style)
private $verbosity;

public function __construct(StyleInterface $style, $verbosity = Output::VERBOSITY_NORMAL)
{
$this->style = $style;
$this->verbosity = $verbosity;
}

public function write(MergeResult $mergeResult)
Expand All @@ -48,23 +52,94 @@ public function write(MergeResult $mergeResult)

foreach ($mergeResult as $key => $value) {
if (! isset($value['base'])) {
$this->style->text('<bg=green;fg=black>+</> ' . $key);
$this->writeAddedTest($key);
continue;
}
if (! isset($value['current'])) {
$this->style->text('<bg=red;fg=yellow>-</> ' . $key);
$this->writeRemovedTest($key);
continue;
}

if ($value['base'] != $value['current']) {
$this->style->text(sprintf(
'<bg=blue;fg=yellow>o</> %s changed from <fg=cyan>%s</> to <fg=magenta>%s</>',
$key,
$value['base'],
$value['current']
));
if ($value['base']['result'] != $value['current']['result']) {
$this->writeChangedTest($value['base'], $value['current'], $key);
continue;
}
}
}

/**
* @param string $key
*
* @return void;
*/
private function writeAddedTest($key)
{
$this->style->text('<bg=green;fg=black>+</> ' . $key);
}

/**
* @param string $key
*
* @return void
*/
private function writeRemovedTest($key)
{
$this->style->text('<bg=red;fg=yellow>-</> ' . $key);
}

/**
* @param array $base
* @param array $current
* @param string $key
*
* @return void
*/
private function writeChangedTest($base, $current, $key)
{
$this->style->text(sprintf(
'<bg=blue;fg=yellow>o</> %s changed from <fg=cyan>%s</> to <fg=magenta>%s</>',
$key,
$base['result'],
$current['result']
));

if ($base['result'] === 'success') {
$this->addVerboseInformationToChangedTest($current);
$this->addVeryVerboseInformationToChangedTest($current);
}

}

private function addVerboseInformationToChangedTest($current)
{
if (! $current['message']) {
return;
}

if ($this->verbosity < Output::VERBOSITY_VERBOSE) {
return;
}

$this->style->text(sprintf(
"\t<fg=yellow>%s</>: <fg=green>%s</>",
$current['type'],
$current['message']
));
}

private function addVeryVerboseInformationToChangedTest($current)
{
if (! $current['info']) {
return;
}

if ($this->verbosity < Output::VERBOSITY_VERY_VERBOSE) {
return;
}

$this->style->text(sprintf(
"\t<fg=cyan>%s</>",
$current['info']
));
}
}
101 changes: 97 additions & 4 deletions tests/JUnitParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,103 @@ public function testThatParsingAJunitFileResultsInAnArray()
$result = $parser->parseFile(__DIR__ . '/_assets/exampleJUnit.xml');

$expectedResult = [
'JUnitXmlReporter.constructor::should default path to an empty string' => 'failure',
'JUnitXmlReporter.constructor::should default consolidate to true' => 'skipped',
'JUnitXmlReporter.constructor::should default useDotNotation to true' => 'success',
];
'JUnitXmlReporter.constructor::Errored and will stay errored' => [
'result' => 'error',
'message' => 'value of getMessage',
'type' => 'Exception',
'info' => 'This might be a stack-trace',
],
'JUnitXmlReporter.constructor::Errored and will fail' => [
'result' => 'error',
'message' => 'value of getMessage',
'type' => 'Exception',
'info' => 'This might be a stack-trace',
],
'JUnitXmlReporter.constructor::Errored and will be skipped' => [
'result' => 'error',
'message' => 'value of getMessage',
'type' => 'Exception',
'info' => 'This might be a stack-trace',
],
'JUnitXmlReporter.constructor::Errored and will be restored' => [
'result' => 'error',
'message' => 'value of getMessage',
'type' => 'Exception',
'info' => 'This might be a stack-trace',
],
'JUnitXmlReporter.constructor::Failed and will error' => [
'result' => 'failure',
'message' => 'value of getMessage',
'type' => 'assertEquals',
'info' => 'This might be a stack-trace',
],
'JUnitXmlReporter.constructor::Failed and will stay failed' => [
'result' => 'failure',
'message' => 'value of getMessage',
'type' => 'assertEquals',
'info' => 'This might be a stack-trace',
],
'JUnitXmlReporter.constructor::Failed and will be skipped' => [
'result' => 'failure',
'message' => 'value of getMessage',
'type' => 'assertEquals',
'info' => 'This might be a stack-trace',
],
'JUnitXmlReporter.constructor::Failed and will be restored' => [
'result' => 'failure',
'message' => 'value of getMessage',
'type' => 'assertEquals',
'info' => 'This might be a stack-trace',
],
'JUnitXmlReporter.constructor::Skipped and will error' => [
'result' => 'skipped',
'message' => '',
'type' => '',
'info' => ''
],
'JUnitXmlReporter.constructor::Skipped and will fail' => [
'result' => 'skipped',
'message' => '',
'type' => '',
'info' => ''
],
'JUnitXmlReporter.constructor::Skipped and will stay skipped' => [
'result' => 'skipped',
'message' => '',
'type' => '',
'info' => ''
],
'JUnitXmlReporter.constructor::Skipped and will be restored' => [
'result' => 'skipped',
'message' => '',
'type' => '',
'info' => ''
],
'JUnitXmlReporter.constructor::Success and will error' => [
'result' => 'success',
'message' => '',
'type' => '',
'info' => ''
],
'JUnitXmlReporter.constructor::Success and will fail' => [
'result' => 'success',
'message' => '',
'type' => '',
'info' => ''
],
'JUnitXmlReporter.constructor::Success and will be skipped' => [
'result' => 'success',
'message' => '',
'type' => '',
'info' => ''
],
'JUnitXmlReporter.constructor::Success and will stay success' => [
'result' => 'success',
'message' => '',
'type' => '',
'info' => ''
],
];

$this->assertEquals($expectedResult, $result);

Expand Down
10 changes: 5 additions & 5 deletions tests/Writer/StandardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public function testThatSummaryWorks()
$mergeresult->shouldReceive('valid')->andReturnValues([true, true, true, true, true, false]);
$mergeresult->shouldReceive('key')->andReturnValues(['a', 'b', 'c', 'd', 'e']);
$mergeresult->shouldReceive('current')->andReturnValues([
['base'=>'Success'],
['base' => 'success', 'current' => 'success'],
['current' => 'success'],
['base' => 'success', 'current' => 'failure'],
['base' => 'failure', 'current' => 'success'],
['base'=>['result'=>'Success', 'message' => '', 'info' => '']],
['base' => ['result'=>'success', 'message' => '', 'info' => ''], 'current' => ['result' => 'success', 'message' => '', 'info' => '']],
['current' => ['result' => 'success', 'message' => '', 'info' => '']],
['base' => ['result' => 'success', 'message' => '', 'info' => ''], 'current' => ['result' => 'failure', 'message' => '', 'info' => '']],
['base' => ['result' => 'failure', 'message' => '', 'info' => ''], 'current' => ['result' => 'success', 'message' => '', 'info' => '']],
]);

$fileSummary = new Standard($styleInterface, 'a', 'b');
Expand Down
43 changes: 38 additions & 5 deletions tests/_assets/exampleJUnit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,51 @@
-->
<testsuites>
<testsuite name="JUnitXmlReporter" errors="0" tests="0" failures="0" time="0" timestamp="2013-05-24T10:23:58" />
<testsuite name="JUnitXmlReporter.constructor" errors="0" skipped="1" tests="3" failures="1" time="0.006" timestamp="2013-05-24T10:23:58">
<testsuite name="JUnitXmlReporter.constructor" errors="4" skipped="4" tests="16" failures="4" time="0.006" timestamp="2013-05-24T10:23:58">
<properties>
<property name="java.vendor" value="Sun Microsystems Inc." />
<property name="compiler.debug" value="on" />
<property name="project.jdk.classpath" value="jdk.classpath.1.6" />
</properties>
<testcase classname="JUnitXmlReporter.constructor" name="should default path to an empty string" time="0.006">
<failure message="test failure">Assertion failed</failure>
<testcase classname="JUnitXmlReporter" name="Errored and will stay errored" time="0.006">
<error message="value of getMessage" type="Exception">This might be a stack-trace</error>
</testcase>
<testcase classname="JUnitXmlReporter.constructor" name="should default consolidate to true" time="0">
<testcase classname="JUnitXmlReporter" name="Errored and will fail" time="0.006">
<error message="value of getMessage" type="Exception">This might be a stack-trace</error>
</testcase>
<testcase classname="JUnitXmlReporter" name="Errored and will be skipped" time="0.006">
<error message="value of getMessage" type="Exception">This might be a stack-trace</error>
</testcase>
<testcase classname="JUnitXmlReporter" name="Errored and will be restored" time="0.006">
<error message="value of getMessage" type="Exception">This might be a stack-trace</error>
</testcase>
<testcase classname="JUnitXmlReporter" name="Failed and will error" time="0.006">
<failure message="value of getMessage" type="assertEquals">This might be a stack-trace</failure>
</testcase>
<testcase classname="JUnitXmlReporter" name="Failed and will stay failed" time="0.006">
<failure message="value of getMessage" type="assertEquals">This might be a stack-trace</failure>
</testcase>
<testcase classname="JUnitXmlReporter" name="Failed and will be skipped" time="0.006">
<failure message="value of getMessage" type="assertEquals">This might be a stack-trace</failure>
</testcase>
<testcase classname="JUnitXmlReporter" name="Failed and will be restored" time="0.006">
<failure message="value of getMessage" type="assertEquals">This might be a stack-trace</failure>
</testcase>
<testcase classname="JUnitXmlReporter" name="Skipped and will error" time="0.006">
<skipped />
</testcase>
<testcase classname="JUnitXmlReporter" name="Skipped and will fail" time="0.006">
<skipped />
</testcase>
<testcase classname="JUnitXmlReporter" name="Skipped and will stay skipped" time="0.006">
<skipped />
</testcase>
<testcase classname="JUnitXmlReporter" name="Skipped and will be restored" time="0.006">
<skipped />
</testcase>
<testcase classname="JUnitXmlReporter.constructor" name="should default useDotNotation to true" time="0" />
<testcase classname="JUnitXmlReporter" name="Success and will error" time="0.006" />
<testcase classname="JUnitXmlReporter" name="Success and will fail" time="0.006"/>
<testcase classname="JUnitXmlReporter" name="Success and will be skipped" time="0.006" />
<testcase classname="JUnitXmlReporter" name="Success and will stay success" time="0.006" />
</testsuite>
</testsuites>

0 comments on commit 437e5e2

Please sign in to comment.