From e8618183e615a8db831f048168d5035312c6d26f Mon Sep 17 00:00:00 2001 From: Rafael Miranda Date: Tue, 5 May 2015 19:07:49 -0300 Subject: [PATCH] Added option to print the step arguments (Table Node) on the report. Signed-off-by: Rafael Miranda --- README.md | 12 +++++++----- src/BehatHTMLFormatterExtension.php | 2 ++ src/Formatter/BehatHTMLFormatter.php | 19 +++++++++++++++++-- src/Renderer/TwigRenderer.php | 1 + templates/index.html.twig | 7 ++++++- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 764c376..5400548 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ formatters: name: html renderer: Twig,Behat2 file_name: Index + print_table: true The *output* parameter is relative to %paths.base% and, when omitted, will default to that same path. @@ -24,6 +25,8 @@ 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** @@ -39,11 +42,10 @@ File names have this format : *"renderer name"*_*"date hour"* To be done: ======================== -1. Store previous runs --> Done -2. Add parameters for behat.yml file -3. Add bootstrap as dependency -4. clean up html report -5. Add out parameter +1. Add parameters for behat.yml file +2. Add bootstrap as dependency +3. clean up html report +4. Add out parameter ========================= diff --git a/src/BehatHTMLFormatterExtension.php b/src/BehatHTMLFormatterExtension.php index 7e044d3..0b58538 100644 --- a/src/BehatHTMLFormatterExtension.php +++ b/src/BehatHTMLFormatterExtension.php @@ -54,6 +54,7 @@ public function configure(ArrayNodeDefinition $builder) { $builder->children()->scalarNode("name")->defaultValue("emusehtml"); $builder->children()->scalarNode("renderer")->defaultValue("behat2"); $builder->children()->scalarNode("file_name")->defaultValue("generated"); + $builder->children()->scalarNode("print_args")->defaultValue("false"); $builder->children()->scalarNode('output')->defaultValue('.'); } @@ -68,6 +69,7 @@ public function load(ContainerBuilder $container, array $config) { $definition->addArgument($config['name']); $definition->addArgument($config['renderer']); $definition->addArgument($config['file_name']); + $definition->addArgument($config['print_args']); $definition->addArgument('%paths.base%'); $container->setDefinition("html.formatter", $definition) diff --git a/src/Formatter/BehatHTMLFormatter.php b/src/Formatter/BehatHTMLFormatter.php index 629e080..84c0c84 100644 --- a/src/Formatter/BehatHTMLFormatter.php +++ b/src/Formatter/BehatHTMLFormatter.php @@ -77,6 +77,12 @@ class BehatHTMLFormatter implements Formatter { */ private $renderer; + /** + * Flag used by this Formatter + * @param $print_args boolean + */ + private $print_args; + /** * @var Array */ @@ -147,13 +153,13 @@ class BehatHTMLFormatter implements Formatter { * @param $name * @param $base_path */ - function __construct($name, $renderer, $filename, $base_path) { + function __construct($name, $renderer, $filename, $print_args, $base_path) { $this->name = $name; + $this->print_args = $print_args; $this->renderer = new BaseRenderer($renderer, $base_path); $this->printer = new FileOutputPrinter($this->renderer->getNameList(), $filename, $base_path); $this->timer = new Timer(); $this->memory = new Memory(); - } /** @@ -267,6 +273,15 @@ public function getOutputPath() { return $this->outputPath; } + /** + * Returns if it should print the step arguments + * + * @return boolean + */ + public function getPrintArguments() { + return $this->print_args; + } + public function getTimer() { return $this->timer; } diff --git a/src/Renderer/TwigRenderer.php b/src/Renderer/TwigRenderer.php index c9c8c75..5bd358d 100644 --- a/src/Renderer/TwigRenderer.php +++ b/src/Renderer/TwigRenderer.php @@ -46,6 +46,7 @@ public function renderAfterExercise($obj) { 'passedSteps' => $obj->getPassedSteps(), 'failedFeatures' => $obj->getFailedFeatures(), 'passedFeatures' => $obj->getPassedFeatures(), + 'printStepArgs' => $obj->getPrintArguments(), ) ); diff --git a/templates/index.html.twig b/templates/index.html.twig index 3dd2a12..9e9abe6 100644 --- a/templates/index.html.twig +++ b/templates/index.html.twig @@ -184,10 +184,15 @@ {% for step in scenario.steps %}
  • {{ step.keyword }} {{ step.text }} + {% if printStepArgs is not null %} + {% for argument in step.arguments %} +

    {{ argument | nl2br }}

    + {% endfor %} + {% endif %} {% if step.exception is not null %}

    ({{ step.exception }})

    - {% endif %} + {% endif %}
  • {#
    #} {#{{ step.keyword }} {{ step.text }}#}