Created
December 29, 2014 08:44
-
-
Save stof/930e968829cd66751a3a to your computer and use it in GitHub Desktop.
Accessing other contexts in Behat 3
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
default: | |
suites: | |
default: | |
contexts: [FeatureContext, SubContext] |
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
<?php | |
use Behat\Behat\Context\Context; | |
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | |
class FeatureContext implements Context { | |
private $subContext; | |
/** @BeforeScenario */ | |
public function gatherContexts(BeforeScenarioScope $scope) | |
{ | |
$environment = $scope->getEnvironment(); | |
$this->subContext = $environment->getContext('SubContext'); | |
} | |
/** @When I set the state :state */ | |
function IGetTheContext($state) { | |
$this->subContext->setState($state); | |
} | |
} |
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
Feature: SubContext | |
Scenario: Access the sub context | |
When I set the state "foo" | |
Then the state should be "foo" |
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
<?php | |
use Behat\Behat\Context\Context; | |
class SubContext implements Context { | |
private $state; | |
function setState($state) { | |
$this->state = $state; | |
} | |
/** @Then the state should be :state */ | |
function theStateShouldBe($state) { | |
PHPUnit_Framework_Assert::assertSame($state, $this->state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!