diff --git a/src/Cjm/Behat/StepThroughExtension/Cli/StepThroughController.php b/src/Cjm/Behat/StepThroughExtension/Cli/StepThroughController.php index e179134..1c796b1 100644 --- a/src/Cjm/Behat/StepThroughExtension/Cli/StepThroughController.php +++ b/src/Cjm/Behat/StepThroughExtension/Cli/StepThroughController.php @@ -32,6 +32,7 @@ public function __construct(Pauser $pauser) public function configure(SymfonyCommand $command) { $command->addOption('--step-through', null, InputOption::VALUE_NONE, 'Pause after every step to aid debugging'); + $command->addOption('--pause-on-fail', null, InputOption::VALUE_NONE, 'Pause after each failed step to aid debugging'); } /** @@ -42,5 +43,9 @@ public function execute(InputInterface $input, OutputInterface $output) if ($input->getOption('step-through') && $input->isInteractive()) { $this->pauser->activate(); } + + if ($input->getOption('pause-on-fail') && $input->isInteractive()) { + $this->pauser->activateOnFail(); + } } } diff --git a/src/Cjm/Behat/StepThroughExtension/Listener/PausingListener.php b/src/Cjm/Behat/StepThroughExtension/Listener/PausingListener.php index 0432f63..bd1cb63 100644 --- a/src/Cjm/Behat/StepThroughExtension/Listener/PausingListener.php +++ b/src/Cjm/Behat/StepThroughExtension/Listener/PausingListener.php @@ -34,6 +34,6 @@ public function pauseAfterStep(AfterStepTested $event) if (in_array($event->getTestResult()->getResultCode(), array(TestResult::PENDING, TestResult::SKIPPED))) { return; } - $this->pauser->pause($event->getStep()->getText()); + $this->pauser->pause($event->getStep()->getText(), $event->getTestResult()->getResultCode()); } } diff --git a/src/Cjm/Behat/StepThroughExtension/Pauser/CliPauser.php b/src/Cjm/Behat/StepThroughExtension/Pauser/CliPauser.php index efe82fa..934729e 100644 --- a/src/Cjm/Behat/StepThroughExtension/Pauser/CliPauser.php +++ b/src/Cjm/Behat/StepThroughExtension/Pauser/CliPauser.php @@ -3,6 +3,7 @@ namespace Cjm\Behat\StepThroughExtension\Pauser; use Symfony\Component\Console\Output\OutputInterface; +use Behat\Testwork\Tester\Result\TestResult; final class CliPauser implements Pauser { @@ -21,15 +22,18 @@ final class CliPauser implements Pauser */ private $isActive = false; + + private $isActiveOnFail = false; + public function __construct(OutputInterface $output, $inputStream = null) { $this->output = $output; $this->inputStream = $inputStream ?: STDIN; } - public function pause($stepText) + public function pause($stepText, $resultCode) { - if (!$this->isActive) { + if (!$this->isActive && (!$this->isActiveOnFail || $resultCode != TestResult::FAILED)) { return; } @@ -42,4 +46,9 @@ public function activate() { $this->isActive = true; } + + public function activateOnFail() + { + $this->isActiveOnFail = true; + } } diff --git a/src/Cjm/Behat/StepThroughExtension/Pauser/Pauser.php b/src/Cjm/Behat/StepThroughExtension/Pauser/Pauser.php index cb21eb4..7747b9e 100644 --- a/src/Cjm/Behat/StepThroughExtension/Pauser/Pauser.php +++ b/src/Cjm/Behat/StepThroughExtension/Pauser/Pauser.php @@ -9,10 +9,15 @@ interface Pauser * * @param string $stepText */ - public function pause($stepText); + public function pause($stepText, $resultCode); /** * Enable the pauser */ public function activate(); + + /** + * Enable the pauser + */ + public function activateOnFail(); } \ No newline at end of file