Skip to content

Commit

Permalink
Added a parameter to enable the step output (var_dump or echo) to be …
Browse files Browse the repository at this point in the history
…printed on the Twig rendered report.

Signed-off-by: Rafael Miranda <[email protected]>
  • Loading branch information
lmrafael committed May 26, 2015
1 parent cdf9a50 commit a11a9cd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ File names have this format : *"renderer name"*_*"date hour"*

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

The *loop_break* is optional. When it is added, Scenario Outlines printed to the report will have a break line separating the executions
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 Down
2 changes: 2 additions & 0 deletions src/BehatHTMLFormatterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ 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 @@ -71,6 +72,7 @@ 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%');
Expand Down
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
21 changes: 19 additions & 2 deletions src/Formatter/BehatHTMLFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ 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
Expand Down Expand Up @@ -159,9 +165,10 @@ class BehatHTMLFormatter implements Formatter {
* @param $name
* @param $base_path
*/
function __construct($name, $renderer, $filename, $print_args, $loop_break, $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);
Expand Down Expand Up @@ -289,6 +296,15 @@ 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
*
Expand Down Expand Up @@ -541,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 @@ -559,6 +575,7 @@ public function onAfterStepTested(AfterStepTested $event) {
$this->failedSteps[] = $step;
}
else {
$step->setOutput($result->getCallResult()->getStdOut());
$this->passedSteps[] = $step;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function renderAfterExercise($obj) {
'failedFeatures' => $obj->getFailedFeatures(),
'passedFeatures' => $obj->getPassedFeatures(),
'printStepArgs' => $obj->getPrintArguments(),
'printStepOuts' => $obj->getPrintOutputs(),
'printLoopBreak' => $obj->getPrintLoopBreak(),
)
);
Expand Down
6 changes: 5 additions & 1 deletion templates/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@
{% 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">
Expand Down

0 comments on commit a11a9cd

Please sign in to comment.