I believe I am not clear on BehatContext versus MinkContext and am not sure why I would inherit from one or the other in my app.
BehatContext
is a basic context which would be a default choice for most of your own contexts.
MinkContext
is a specialized context giving you access to the Mink session. It also contains some basic step definitions. That's why you should never extend it ('cause you'd be only able to extend it once, since step definitions cannot be duplicated).
If you need to access the Mink Session extend the RawMinkContext
. It's like the MinkContext
without step definitions.
Basically I am not clear on why I have to instantiate a new Client object in every function. I should be able to use $this since I have goutte loaded in my behat.yml file.
Why are you trying to instantiate the Client yourself? Just use the Mink Session, which will do it for you:
<?php
namespace Main\ReferralCaptureBundle\Features\Context;
// your use statements here...
class FeatureContext extends RawMinkContext
{
/**
* @Given /^I am on homepage$/
*/
public function iAmOnHomepage()
{
$session = $this->getSession();
$session->visit($this->locatePath('/'));
$link = $session->getPage()->findLink('I am a Physician');
if (null === $link) {
throw new Exception("Home Page Not Loaded:\n");
}
}
/**
* @Given /^I follow "([^"]*)"$/
*/
public function iFollow($arg1)
{
$link = $this->getSession()->findLink('Register');
if (null === $link) {
throw new \LogicException('Could not find the "Register" link');
}
$link->click();
}
// ...
}
Look at the step definitions in the MinkContext
for inspiration.
To read (seriously, read the docs first):
- Mink: http://mink.behat.org/
- MinkExtension: http://extensions.behat.org/mink/index.html
- MinkContext class: https://github.com/Behat/MinkExtension/blob/master/src/Behat/MinkExtension/Context/MinkContext.php
- RawMinkContextClass: https://github.com/Behat/MinkExtension/blob/master/src/Behat/MinkExtension/Context/RawMinkContext.php