Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/DrevOps/BehatFormatProgressFail/FormatExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Behat\Behat\Output\Node\EventListener\Statistics\ScenarioStatsListener;
use Behat\Behat\Output\Node\EventListener\Statistics\StepStatsListener;
use Behat\Behat\Output\Node\EventListener\Statistics\HookStatsListener;
use Behat\Behat\Output\Statistics\TotalStatistics;
use Behat\Testwork\Output\Printer\StreamOutputPrinter;
use Behat\Behat\Output\Printer\ConsoleOutputFactory;
use Behat\Testwork\Exception\ServiceContainer\ExceptionExtension;
Expand Down Expand Up @@ -82,6 +83,10 @@ public function configure(ArrayNodeDefinition $builder): void {
public function load(ContainerBuilder $container, array $config): void {
$name = isset($config['name']) && is_string($config['name']) ? $config['name'] : self::MOD_ID;

// Create our own statistics object instead of using the shared one.
$definition = new Definition(TotalStatistics::class);
$container->setDefinition('output.progress_fail.statistics', $definition);

$definition = new Definition(StepListener::class, [
new Reference('output.printer.' . $name),
]);
Expand All @@ -105,18 +110,18 @@ public function load(ContainerBuilder $container, array $config): void {
[
new Reference(self::ROOT_LISTENER_ID),
new Definition(StatisticsListener::class, [
new Reference('output.progress.statistics'),
new Reference('output.progress_fail.statistics'),
new Reference('output.node.printer.progress.statistics'),
]),
new Definition(ScenarioStatsListener::class, [
new Reference('output.progress.statistics'),
new Reference('output.progress_fail.statistics'),
]),
new Definition(StepStatsListener::class, [
new Reference('output.progress.statistics'),
new Reference('output.progress_fail.statistics'),
new Reference(ExceptionExtension::PRESENTER_ID),
]),
new Definition(HookStatsListener::class, [
new Reference('output.progress.statistics'),
new Reference('output.progress_fail.statistics'),
new Reference(ExceptionExtension::PRESENTER_ID),
]),
],
Expand Down
56 changes: 56 additions & 0 deletions tests/behat/features/format.feature
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,59 @@ Feature: Format
3 steps (2 passed, 1 failed)
"""

Scenario: Metrics should not double when used with multiple formatters
Given a file named "behat.yml" with:
"""
default:
suites:
default:
contexts:
- FeatureContextTest
extensions:
DrevOps\BehatFormatProgressFail\FormatExtension: ~
"""
And a file named "features/apples.feature" with:
"""
Feature: Apples story
In order to eat apple
As a little kid
I need to have an apple in my pocket

Background:
Given I have 3 apples

Scenario: I'm little hungry
When I ate 1 apple
Then I should have 2 apples
And I should have 2 apples

Scenario: I eat wrong amount
When I ate 1 apple
Then I should have 3 apples
And I should have 2 apples

Scenario: I found apples
When I found 2 apples
Then I should have 5 apples
And I should have 5 apples
"""
When I run "behat --no-colors --strict -f progress -o progress.txt -f progress_fail -o std"
Then it should fail with:
"""
......
--- FAIL ---
Then I should have 3 apples # (features/apples.feature):16
Failed asserting that 2 matches expected 3.
------------
-....

--- Failed steps:

001 Scenario: I eat wrong amount # features/apples.feature:14
Then I should have 3 apples # features/apples.feature:16
Failed asserting that 2 matches expected 3.

3 scenarios (2 passed, 1 failed)
12 steps (10 passed, 1 failed, 1 skipped)
"""