Skip to content

Instantly share code, notes, and snippets.

@everzet
Created August 13, 2011 15:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save everzet/1143930 to your computer and use it in GitHub Desktop.
Save everzet/1143930 to your computer and use it in GitHub Desktop.
How to use MinkContext inside BehatBundle as subcontext
<?php
namespace Acme\DemoBundle\Features\Context;
use Behat\BehatBundle\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
/**
* Feature context.
*/
class FeatureContext extends BehatContext
{
/**
* BehatBundle's main context constructor gets
* KernelInterface instance as single parameter
*/
public function __construct($kernel)
{
// Instantiate and use BehatBundle's MinkContext with provided $kernel
$this->useContext('mink', new MinkContext($kernel));
}
/**
* Get Mink session from MinkContext
*/
public function getSession($name = null)
{
reutrn $this->getSubcontext('mink')->getSession($name);
}
}
<?php
namespace Acme\DemoBundle\Features\Context;
use Behat\BehatBundle\Context\MinkContext as BaseMinkContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
/**
* Mink-enabled context.
*/
class MinkContext extends BaseMinkContext
{
}
@arrobeusa
Copy link

How is it that you are able to avoid calling parent constructor within each of those classes? I get a "Call to a member function getContainer() on a non-object" when I don't call parent::__construct($kernel);

@clemherreman
Copy link

You have a typo in

    public function getSession($name = null)
    {
        reutrn $this->getSubcontext('mink')->getSession($name); // Should be 'return'
    }

Also thank you for your work on Behat/Mink

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment