Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from elvetemedve/feature/add-parameter-support-…
Browse files Browse the repository at this point in the history
…for-secondary-behat

Amend the process factory to be able to set parameters for the secondary behat
  • Loading branch information
Geza Buza committed Nov 16, 2015
2 parents 3874c6c + c8003fb commit 27367ea
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
/vendor

# Composer installed package cache
/.composer.lock
/composer.lock
55 changes: 55 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
checks:
php: true

tools:
external_code_coverage: false
php_code_coverage: false
php_code_sniffer:
config: { standard: 'Zend' }
php_changetracking: false
php_sim: false
php_cs_fixer: true
php_mess_detector: true
php_pdepend: true
php_analyzer: true
sensiolabs_security_checker: true

filter:
paths:
- 'src/*'
excluded_paths:
- 'features/bootstrap/*'
- 'dev/*'
- 'var/*'
- 'lib/*'
- 'bin/*'
- 'vendor/*'

build:
environment:
php:
version: 5.4
ini:
'always_populate_raw_post_data': '-1'

tests:
override:
- bin/phpspec run --no-interaction --format=pretty
after:
- SCRUTINIZER_START_TIME=$(cat /tmp/build-start-time.txt) sh -c 'curl -sS https://gist.githubusercontent.com/tonypiper/fd3cf9a67b71d4e3928c/raw/152f1d873f98ff4256ca8bc3041443eae7c890b4/keenio-logger.php | php'

dependencies:
before:
- date -u +"%Y-%m-%dT%H:%M:%SZ" > /tmp/build-start-time.txt

override:
- { command: 'composer update --no-interaction --prefer-source', idle_timeout: 600 }

cache:
directories: [ vendor/, bin/ ]

build_failure_conditions:
- 'elements.rating(<= B).new.exists'
- 'issues.label("coding-style").new.exists'
- 'issues.new.exists'
- 'project.metric("scrutinizer.quality", < 9.00)'
9 changes: 5 additions & 4 deletions spec/Bex/Behat/Context/TestRunnerContextSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ function it_saves_files_in_document_root_directory(PyStringNode $content, Filesy
function it_runs_behat_in_working_directory(ProcessFactory $processFactory, Process $process)
{
$processFactory->createBehatProcess(
Argument::containingString(sys_get_temp_dir() .'/behat-test-runner')
Argument::containingString(sys_get_temp_dir() .'/behat-test-runner'),
Argument::any()
)->shouldBeCalled()->willReturn($process);
$process->run()->shouldBeCalled();

Expand Down Expand Up @@ -116,16 +117,16 @@ function it_can_detect_when_there_was_no_failing_tests_but_expected(
ProcessFactory $processFactory,
Process $process
) {
$processFactory->createBehatProcess(Argument::any())->willReturn($process);
$processFactory->createBehatProcess(Argument::any(), Argument::any())->willReturn($process);
$this->createWorkingDirectory();
$this->iRunBehat();

$process->getExitCode()->willReturn(0);
$process->isSuccessful()->willReturn(true);
$this->shouldThrow(
new \RuntimeException('Behat did not find any failing scenario.')
)->duringIShouldSeeAFailingTest();

$process->getExitCode()->willReturn(255);
$process->isSuccessful()->willReturn(false);
$this->shouldNotThrow('\RuntimeException')->duringIShouldSeeAFailingTest();
}

Expand Down
5 changes: 3 additions & 2 deletions src/Services/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ public function __construct(PhpExecutableFinder $phpFinder = null)

/**
* @param string $workingDirectory
* @param string $parameters
*
* @return Process
*/
public function createBehatProcess($workingDirectory)
public function createBehatProcess($workingDirectory, $parameters = '')
{
return new Process(
sprintf('%s %s --no-colors', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH)),
sprintf('%s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $parameters),
$workingDirectory
);
}
Expand Down
41 changes: 35 additions & 6 deletions src/TestRunnerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public function afterRunTests(AfterScenarioScope $scope)
$this->destroyProcesses();
}

/**
* @return void
*/
public function createWorkingDirectory()
{
$this->workingDirectory = tempnam(sys_get_temp_dir(), 'behat-test-runner');
Expand All @@ -126,11 +129,17 @@ public function createWorkingDirectory()
$this->filesystem->mkdir($this->documentRoot, 0770);
}

/**
* @return void
*/
public function clearWorkingDirectory()
{
$this->filesystem->remove($this->workingDirectory);
}

/**
* @return void
*/
public function destroyProcesses()
{
/** @var Process $process */
Expand All @@ -144,6 +153,9 @@ public function destroyProcesses()
$this->behatProcess = null;
}

/**
* @param AfterScenarioScope $scope
*/
public function printTesterOutputOnFailure(AfterScenarioScope $scope)
{
if (!$scope->getTestResult()->isPassed()) {
Expand Down Expand Up @@ -177,6 +189,7 @@ public function iHaveTheFeature(PyStringNode $content)
$content->getRaw()
);
}

/**
* @Given I have the context:
*/
Expand All @@ -190,10 +203,12 @@ public function iHaveTheContext(PyStringNode $definition)

/**
* @When I run Behat
* @When I run Behat with :paramters parameter
* @When I run Behat with :paramters parameters
*/
public function iRunBehat()
public function iRunBehat($parameters = '')
{
$this->runBehat();
$this->runBehat($parameters);
}

/**
Expand All @@ -218,7 +233,7 @@ public function iHaveAWebServerRunningOnAddressAndPort($hostname, $port)
*/
public function iShouldSeeAFailingTest()
{
if ($this->behatProcess->getExitCode() == 0) {
if ($this->behatProcess->isSuccessful()) {
throw new RuntimeException('Behat did not find any failing scenario.');
}
}
Expand All @@ -228,7 +243,7 @@ public function iShouldSeeAFailingTest()
*/
public function iShouldNotSeeAFailingTest()
{
if ($this->behatProcess->getExitCode() != 0) {
if (!$this->behatProcess->isSuccessful()) {
throw new RuntimeException('Behat found a failing scenario.');
}
}
Expand All @@ -253,21 +268,35 @@ public function getStandardErrorMessage()
return $this->behatProcess->getErrorOutput();
}

private function runBehat()
/**
* @param string $parameters
*
* @return void
*/
private function runBehat($parameters = '')
{
$behatProcess = $this->processFactory->createBehatProcess($this->workingDirectory);
$behatProcess = $this->processFactory->createBehatProcess($this->workingDirectory, $parameters);
$this->behatProcess = $behatProcess;
$this->processes[] = $this->behatProcess;
$behatProcess->run();
}

/**
* @param string $hostname
* @param string $port
*
* @return void
*/
private function runWebServer($hostname, $port)
{
$webServerProcess = $this->processFactory->createWebServerProcess($this->documentRoot, $hostname, $port);
$this->processes[] = $webServerProcess;
$webServerProcess->start();
}

/**
* @return void
*/
private function runBrowser()
{
if (is_null($this->browserCommand)) {
Expand Down

0 comments on commit 27367ea

Please sign in to comment.