Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to debug in case of fail. This pause will keep chrome o… #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
13 changes: 11 additions & 2 deletions src/Cjm/Behat/StepThroughExtension/Pauser/CliPauser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}

Expand All @@ -42,4 +46,9 @@ public function activate()
{
$this->isActive = true;
}

public function activateOnFail()
{
$this->isActiveOnFail = true;
}
}
7 changes: 6 additions & 1 deletion src/Cjm/Behat/StepThroughExtension/Pauser/Pauser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}