覆盖/扩展 behat ProgressStepPrinter

Override / Extend behat ProgressStepPrinter

我正在尝试创建一个扩展来 progress output step formatter

目标只是将每个已通过的场景步骤的 . 更改为 *

The behat documentation does not even mention the ability to create a custom formatter, however I found a GitHub repository that does this behat-format-progress-fail

但是没有关于如何实现这一点的清晰/简单的概述,我已经尝试复制和修改它们。有没有简单的例子或清晰的文档?

通过创建一个非常简化的 ProgressStepPrinter.php 版本,然后将其包含在 autoload-dev 中,在 composer.json 中优先使用它而不是 Behat 中的版本。

ProgressStepPrinter.php

namespace Behat\Behat\Output\Node\Printer\Progress;

use Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter;
use Behat\Behat\Output\Node\Printer\StepPrinter;
use Behat\Behat\Tester\Result\StepResult;
use Behat\Gherkin\Node\ScenarioLikeInterface as Scenario;
use Behat\Gherkin\Node\StepNode;
use Behat\Testwork\Output\Formatter;

final class ProgressStepPrinter implements StepPrinter {

    private $resultConverter;

    public function __construct(ResultToStringConverter $resultConverter) {
        $this->resultConverter = $resultConverter;
    }

    public function printStep(Formatter $formatter, Scenario $scenario, StepNode $step, StepResult $result) {
        //custom logic to print per step here
    }
}

composer.json

"autoload-dev": {
    "files": [
        "features/bootstrap/ProgressStepPrinter.php",
    ]
},