Skip to content

Commit

Permalink
Merge pull request #18 from lmrafael/master
Browse files Browse the repository at this point in the history
Fixes and funcionalities
  • Loading branch information
dutchiexl committed May 27, 2015
2 parents 0597412 + 6099a17 commit c7a51a1
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 6 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ formatters:
name: html
renderer: Twig,Behat2
file_name: Index
print_table: true
print_args: true
loop_break: true
</pre>

The *output* parameter is relative to %paths.base% and, when omitted, will default to that same path.
Expand All @@ -25,8 +26,6 @@ The *renderer* is the renderer engine and the report format that you want to be

The *file_name* is optional. When it is added, the report name will be fixed instead fo generated, and this file will be overwritten with every build.

The *print_args* is optional. When it is added, the report will contain the arguments for each step if exists. (e.g. Tables)

Actually, there is 3 formats :

- **Twig** : new report format based on Twig, **requires Twig installed**
Expand All @@ -39,6 +38,14 @@ You can combine formats to generate multiple reports with multiple formats at on

File names have this format : *"renderer name"*_*"date hour"*

**Twig renderer only parameters:**

The *print_args* is optional. When it is added, the report will contain the arguments for each step if exists. (e.g. Tables)

The *print_outp* is optional. When it is added, the report will contain the output of each step if exists. (e.g. Exceptions)

The *loop_break* is optional. When it is added, Scenario Outlines printed to the report will have a break line separating the executions.

To be done:
========================

Expand All @@ -47,12 +54,15 @@ To be done:
3. clean up html report
4. Add out parameter

Screenshots
=========================

Twig :

<img src="http://i.imgur.com/o0zCqiB.png"></img>

Behat2 :

<img src="http://i57.tinypic.com/287g942.jpg"></img>


4 changes: 4 additions & 0 deletions assets/Twig/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ body {
background-color: #f56956;
background-image: none;
}
.list-group-item.break {
padding: 1px;
background-color: #808080;
}
4 changes: 4 additions & 0 deletions src/BehatHTMLFormatterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function configure(ArrayNodeDefinition $builder) {
$builder->children()->scalarNode("renderer")->defaultValue("behat2");
$builder->children()->scalarNode("file_name")->defaultValue("generated");
$builder->children()->scalarNode("print_args")->defaultValue("false");
$builder->children()->scalarNode("print_outp")->defaultValue("false");
$builder->children()->scalarNode("loop_break")->defaultValue("false");
$builder->children()->scalarNode('output')->defaultValue('.');
}

Expand All @@ -70,6 +72,8 @@ public function load(ContainerBuilder $container, array $config) {
$definition->addArgument($config['renderer']);
$definition->addArgument($config['file_name']);
$definition->addArgument($config['print_args']);
$definition->addArgument($config['print_outp']);
$definition->addArgument($config['loop_break']);

$definition->addArgument('%paths.base%');
$container->setDefinition("html.formatter", $definition)
Expand Down
22 changes: 22 additions & 0 deletions src/Classes/Scenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Scenario
private $name;
private $line;
private $tags;
private $loopCount;

/**
* @var bool
Expand Down Expand Up @@ -45,6 +46,21 @@ public function setName($name)
$this->name = $name;
}

/**
* @return int
*/
public function getLoopCount()
{
return $this->loopCount;
}

/**
* @param int $loopCount
*/
public function setLoopCount($loopCount)
{
$this->loopCount = $loopCount;
}
/**
* @return mixed
*/
Expand Down Expand Up @@ -132,4 +148,10 @@ public function setId($id)
{
$this->id = $id;
}

public function getLoopSize()
{
//behat
return $this->loopCount > 0 ? sizeof($this->steps)/$this->loopCount : sizeof($this->steps);
}
}
17 changes: 17 additions & 0 deletions src/Classes/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Step
private $result;
private $resultCode;
private $exception;
private $output;
private $definition;

/**
Expand Down Expand Up @@ -133,6 +134,22 @@ public function setDefinition($definition)
$this->definition = $definition;
}

/**
* @return mixed
*/
public function getOutput()
{
return $this->output;
}

/**
* @param mixed $output
*/
public function setOutput($output)
{
$this->output = $output;
}

/**
* @return mixed
*/
Expand Down
50 changes: 48 additions & 2 deletions src/Formatter/BehatHTMLFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ class BehatHTMLFormatter implements Formatter {
*/
private $print_args;

/**
* Flag used by this Formatter
* @param $print_outp boolean
*/
private $print_outp;

/**
* Flag used by this Formatter
* @param $loop_break boolean
*/
private $loop_break;

/**
* @var Array
*/
Expand Down Expand Up @@ -153,9 +165,11 @@ class BehatHTMLFormatter implements Formatter {
* @param $name
* @param $base_path
*/
function __construct($name, $renderer, $filename, $print_args, $base_path) {
function __construct($name, $renderer, $filename, $print_args, $print_outp, $loop_break, $base_path) {
$this->name = $name;
$this->print_args = $print_args;
$this->print_outp = $print_outp;
$this->loop_break = $loop_break;
$this->renderer = new BaseRenderer($renderer, $base_path);
$this->printer = new FileOutputPrinter($this->renderer->getNameList(), $filename, $base_path);
$this->timer = new Timer();
Expand Down Expand Up @@ -282,6 +296,24 @@ public function getPrintArguments() {
return $this->print_args;
}

/**
* Returns if it should print the step outputs
*
* @return boolean
*/
public function getPrintOutputs() {
return $this->print_outp;
}

/**
* Returns if it should print scenario loop break
*
* @return boolean
*/
public function getPrintLoopBreak() {
return $this->loop_break;
}

public function getTimer() {
return $this->timer;
}
Expand Down Expand Up @@ -450,6 +482,7 @@ public function onAfterScenarioTested(AfterScenarioTested $event) {
$this->currentFeature->addFailedScenario();
}

$this->currentScenario->setLoopCount(1);
$this->currentScenario->setPassed($event->getTestResult()->isPassed());
$this->currentFeature->addScenario($this->currentScenario);

Expand Down Expand Up @@ -487,6 +520,7 @@ public function onAfterOutlineTested(AfterOutlineTested $event) {
$this->currentFeature->addFailedScenario();
}

$this->currentScenario->setLoopCount(sizeof($event->getTestResult()));
$this->currentScenario->setPassed($event->getTestResult()->isPassed());
$this->currentFeature->addScenario($this->currentScenario);

Expand All @@ -509,6 +543,7 @@ public function onBeforeStepTested(BeforeStepTested $event) {
public function onAfterStepTested(AfterStepTested $event) {
$result = $event->getTestResult();

//$this->dumpObj($event->getStep()->getArguments());
/** @var Step $step */
$step = new Step();
$step->setKeyword($event->getStep()->getKeyword());
Expand All @@ -522,11 +557,11 @@ public function onAfterStepTested(AfterStepTested $event) {
if (is_a($result, 'Behat\Behat\Tester\Result\UndefinedStepResult')) {
//pending step -> no definition to load
$this->pendingSteps[] = $step;

}
else {
if (is_a($result, 'Behat\Behat\Tester\Result\SkippedStepResult')) {
//skipped step
/** @var ExecutedStepResult $result */
$step->setDefinition($result->getStepDefinition());
$this->skippedSteps[] = $step;
}
Expand All @@ -540,6 +575,7 @@ public function onAfterStepTested(AfterStepTested $event) {
$this->failedSteps[] = $step;
}
else {
$step->setOutput($result->getCallResult()->getStdOut());
$this->passedSteps[] = $step;
}
}
Expand All @@ -559,4 +595,14 @@ public function printText($text) {
file_put_contents('php://stdout', $text);
}

/**
* @param $obj
*/
public function dumpObj($obj) {
ob_start();
var_dump($obj);
$result = ob_get_clean();
$this->printText($result);
}

}
2 changes: 2 additions & 0 deletions src/Renderer/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function renderAfterExercise($obj) {
'failedFeatures' => $obj->getFailedFeatures(),
'passedFeatures' => $obj->getPassedFeatures(),
'printStepArgs' => $obj->getPrintArguments(),
'printStepOuts' => $obj->getPrintOutputs(),
'printLoopBreak' => $obj->getPrintLoopBreak(),
)
);

Expand Down
9 changes: 8 additions & 1 deletion templates/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,14 @@
{% endif %}
{% if step.exception is not null %}
<br>
<p style="padding-left:2em ; color:gray">({{ step.exception }})</p>
<p style="padding-left:2em ; color:gray">({{ step.exception }})</p>
{% endif %}
{% if step.output is not null %}
<br>
<p style="padding-left:2em ; color:black">| {{ step.output }}</p>
{% endif %}
{% if printLoopBreak is not null and ( loop.index % scenario.getLoopSize ) == 0 and loop.last != true %}
</li><li class="list-group-item break">
{% endif %}
</li>
{#<div class="bs-callout bs-callout-{% if step.passed %}success{% else %}danger{% endif %}" id="callout-collapse-accessibility">#}
Expand Down

0 comments on commit c7a51a1

Please sign in to comment.