Last active
December 24, 2015 07:40
-
-
Save clemherreman/6765747 to your computer and use it in GitHub Desktop.
FeatureContext
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\Step\Given; | |
use Behat\Behat\Context\Step\When; | |
use Behat\Mink\Element\Element; | |
use Behat\Mink\Exception\ExpectationException; | |
use Behat\MinkExtension\Context\RawMinkContext; | |
use FooInterface; | |
class BusinessContext extends RawMinkContext | |
{ | |
/** @var FooInterface */ | |
private $foo; | |
// Dependency injection of FooInterface (Fake object used for testing) | |
public function __construct(FooInterface $foo) | |
{ | |
$this->foo = $foo; | |
} | |
/** @BeforeScenario */ | |
public function before($event) | |
{ | |
$this->setMink($this->getMainContext()->getMink()); | |
} | |
/** | |
* @Given /^I am on the job listing page$/ | |
*/ | |
public function iAmOnTheJobListingPage() | |
{ | |
return array( | |
new Given('I am on the homepage'), | |
new When('I follow "Positions List"'), | |
); | |
} | |
//Only step definitions, no hooks, acts like a step dictionnary | |
} |
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\MinkExtension\Context\MinkContext; | |
use Behat\Behat\Event\ScenarioEvent; | |
use \Mockery; | |
use \Pimple; | |
/** | |
* Features context. | |
*/ | |
class FeatureContext extends MinkContext | |
{ | |
/** @var Pimple */ | |
private $container; | |
/** @var array Behat parameters from the behat.yml file */ | |
private $params; | |
/** | |
* Initializes context. | |
* Every scenario gets its own context object. | |
* | |
* @param array $parameters context parameters (set them up through behat.yml) | |
*/ | |
public function __construct(array $parameters) | |
{ | |
$this->params = $parameters; | |
$this->buildContainer($parameters); | |
$this->useContext('behatch', new BehatchContext($parameters)); | |
$this->useContext('business', new BusinessContext($this->container['foo'])); | |
$this->useContext('login', new LoginContext()); | |
$this->useContext('domain_part', new SomeDomainPartContext()); | |
} | |
/** | |
* @param array $parameters Parameters from the behat.yml file | |
*/ | |
private function buildContainer($parameters) | |
{ | |
// Some Fake objects, that keeps the need of mock low. | |
$this->container = new Pimple(); | |
$this->container['foo'] = $this->container->share(function($c) { | |
return new Foo(); | |
}); | |
$this->container['bar'] = $this->container->share(function($c) { | |
return new Bar(); | |
}); | |
} | |
/** @BeforeScenario */ | |
public function beforeScenario(ScenarioEvent $event) | |
{ | |
$this->loadFixtures($this->container['db']); | |
$this->setupWsMock(); | |
} | |
/** | |
* Replace the webservice url in the config with the url of a mock application. | |
* | |
* @throws InvalidArgumentException In the mock | |
*/ | |
private function setupWsMock() | |
{ | |
// here be dragons | |
} | |
private function setupFizzleTwizzle() | |
{ | |
set_include_path(get_include_path().':'.realpath(__DIR__.'/../../web')); | |
some_bootstrap_dark_magic(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment