Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding smoke test running command at CLI
- Loading branch information
1 parent
f65d8ef
commit 34a2808
Showing
5 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
use Behat\Behat\Tester\Exception\PendingException; | ||
use Behat\Behat\Context\Context; | ||
use Behat\Behat\Context\SnippetAcceptingContext; | ||
use Behat\Gherkin\Node\PyStringNode; | ||
use Behat\Gherkin\Node\TableNode; | ||
use PhpSpec\Exception\Example\SkippingException; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* Defines application features from the specific context. | ||
*/ | ||
class IsolatedProcessContext implements Context, SnippetAcceptingContext | ||
{ | ||
private $lastOutput; | ||
|
||
/** | ||
* @Given I have started describing the :class class | ||
*/ | ||
public function iHaveStartedDescribingTheClass($class) | ||
{ | ||
$process = new Process($this->buildPhpSpecCmd() . ' describe '. escapeshellarg($class)); | ||
$process->run(); | ||
|
||
expect($process->getExitCode())->toBe(0); | ||
} | ||
|
||
/** | ||
* @When I run phpspec and answer :answer when asked if I want to generate the code | ||
*/ | ||
public function iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode($answer) | ||
{ | ||
if (!`which expect`) { | ||
throw new SkippingException('Cannot test interactive scripts on this platform'); | ||
} | ||
|
||
$process = new Process( | ||
"exec expect -c '\n" . | ||
"set timeout 10\n" . | ||
"spawn {$this->buildPhpSpecCmd()} run\n" . | ||
"expect \"Y/n\"\n" . | ||
"sleep 0.1\n" . | ||
"send \"$answer\n\"\n" . | ||
"sleep 0.5\n" . | ||
"interact\n" . | ||
"'" | ||
); | ||
|
||
$process->run(); | ||
|
||
$this->lastOutput = $process->getOutput(); | ||
|
||
expect($process->getErrorOutput())->toBe(null); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function buildPhpSpecCmd() | ||
{ | ||
return escapeshellcmd(__DIR__ . '/../../bin/phpspec'); | ||
} | ||
|
||
/** | ||
* @Then the tests should be rerun | ||
*/ | ||
public function theTestsShouldBeRerun() | ||
{ | ||
expect(substr_count($this->lastOutput, 'Y/n'))->toBe(2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters