I have a custom method in my FeatureContext.php file, and would like it to be able to use a drush command. But whenever I try to run my behat script, I get the error

Fatal error: Call to undefined method Drupal\DrupalExtension\Context\DrushContext::drush() (Behat\Testwork\Call\Exception\FatalThrowableError)

My code is faily simple I believe, so imagine I have just misunderstood. But I had thought I would have been able to use the DrushContext in the same way I use the DrupalContext

<?php
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends RawDrupalContext
{

    /** @var \Behat\MinkExtension\Context\MinkContext */
    private $drupalContext;

    /**
     * @var \Drupal\DrupalExtension\Context\MinkContext
     */
    protected $minkContext;

    /**
     * @var \Drupal\DrupalExtension\Context\DrushContext
     */
    private $drushContext;

    /** @BeforeScenario */
    public function gatherContexts(Behat\Behat\Hook\Scope\BeforeScenarioScope $scope)
    {
        $environment = $scope->getEnvironment();

        $this->drupalContext = $environment->getContext('Drupal\DrupalExtension\Context\DrupalContext');
        $this->drushContext = $environment->getContext('Drupal\DrupalExtension\Context\DrushContext');
        $this->minkContext = $environment->getContext('Drupal\DrupalExtension\Context\MinkContext');
    }

    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct()
    {
    }

    /**
     * @When my currency is set to :currency
     */
    public function assertUserCurrency($currency) {

        // Assert my user is logged in
        if (empty($this->drupalContext->user->name)) {
            throw new \Exception(sprintf('Test user is not logged in', $user));
        }

        if (!in_array($currency, array('GBP', 'USD', 'EUR'))) {
            throw new \Exception(sprintf('The currency passed in is invalid', $currency));
        }

        $userInfo = $this->drushContext->drush('uinf', $this->drupalContext->user->name . ' --fields=uid');
        var_dump($userInfo);

    }

}

If anyone is able to advise on this, it would be much appreciated.

Comments

retrodans created an issue.