Skip to content

Commit

Permalink
Merge pull request #3 from elvetemedve/fix/rename-output-filename
Browse files Browse the repository at this point in the history
Rename output filename
  • Loading branch information
Tibor Kotosz committed Nov 17, 2015
2 parents f4437bd + af36001 commit 1d9bccd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
27 changes: 26 additions & 1 deletion spec/Bex/Behat/Context/TestRunnerContextSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace spec\Bex\Behat\Context;

use Behat\Gherkin\Node\PyStringNode;
use Behat\Testwork\Hook\Scope\AfterTestScope;
use Behat\Testwork\Tester\Result\TestResult;
use Bex\Behat\Context\Services\ProcessFactory;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
Expand All @@ -19,14 +21,20 @@
*/
class TestRunnerContextSpec extends ObjectBehavior
{
function let(Filesystem $filesystem, ProcessFactory $processFactory)
function let(Filesystem $filesystem, ProcessFactory $processFactory, Process $behatProcess)
{
$this->beConstructedWith('bin/phantomjs', $filesystem, $processFactory);
$this->initFilesystemDouble($filesystem);
$this->initProcessFactoryDouble($processFactory, $behatProcess);

defined('BEHAT_BIN_PATH') or define('BEHAT_BIN_PATH', 'bin/behat');
}

function letgo()
{
(new Filesystem())->remove(glob(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat-test-runner*'));
}

function it_is_initializable()
{
$this->shouldHaveType('Bex\Behat\Context\TestRunnerContext');
Expand Down Expand Up @@ -156,9 +164,26 @@ function it_does_not_run_browser_when_broser_binary_is_not_set(
$this->iHaveAWebServerRunningOnAddressAndPort(Argument::any(), Argument::any());
}

function it_dumps_the_output_of_secondary_behat_to_file_on_failure(
AfterTestScope $scope, TestResult $testResult, Filesystem $filesystem
) {
$scope->getTestResult()->willReturn($testResult);
$testResult->isPassed()->willReturn(false);

$filesystem->dumpFile(Argument::containingString('behat-test-runner.out'), Argument::any())->shouldBeCalled();

$this->iRunBehat();
$this->shouldThrow('\RuntimeException')->duringPrintTesterOutputOnFailure($scope);
}

private function initFilesystemDouble($filesystem)
{
$filesystem->remove(Argument::type('string'))->willReturn(null);
$filesystem->mkdir(Argument::type('string'), Argument::type('int'))->willReturn(null);
}

private function initProcessFactoryDouble(ProcessFactory $processFactory, Process $behatProcess)
{
$processFactory->createBehatProcess(Argument::any(), Argument::any())->willReturn($behatProcess);
}
}
5 changes: 2 additions & 3 deletions src/TestRunnerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Bex\Behat\Context\Services\ProcessFactory;
use RuntimeException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

/**
Expand Down Expand Up @@ -155,10 +154,10 @@ public function destroyProcesses()
/**
* @param AfterScenarioScope $scope
*/
public function printTesterOutputOnFailure(AfterScenarioScope $scope)
public function printTesterOutputOnFailure($scope)
{
if (!$scope->getTestResult()->isPassed()) {
$outputFile = sys_get_temp_dir() . '/behat-screenshot.out';
$outputFile = sys_get_temp_dir() . '/behat-test-runner.out';
$this->filesystem->dumpFile(
$outputFile,
$this->behatProcess->getOutput() . $this->behatProcess->getErrorOutput()
Expand Down

0 comments on commit 1d9bccd

Please sign in to comment.