1
votes

I am trying to use behat with mink extension to create a simplistic case scenario. I am stuck in the beginning though, and hours of googling do not seem to help.

My composer require

  "require": {
    "behat/behat": "3.0.6",
    "behat/mink": "1.6.*",
    "behat/mink-extension": "*",
    "behat/mink-goutte-driver": "*"
  }

My behat.yml

default:
  autoload:
    '': %paths.base%/features/bootstrap
  suites:
    default:
      paths:
        - %paths.base%/features
      extensions:
        Behat\MinkExtension:
          base_url:  'http://example.com'
          goutte: ~

My FeatureContext.php

<?php

use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\MinkExtension\Context\MinkContext;

/**
 * Behat context class.
 */
class FeatureContext extends MinkContext implements SnippetAcceptingContext
{
    /**
     * Initializes context.
     *
     * Every scenario gets it's own context object.
     * You can also pass arbitrary arguments to the context constructor through behat.yml.
     */
    public function __construct()
    {
    }

    /**
     * @Given /^I am on home page$/
     */
    public function iGoToHomePage()
    {
        $session = $this->getSession();
        $session->visit($this->locatePath('/'));
    }
}

Whenever I run behat with my feature I get

  Mink instance has not been set on Mink context class. Have you enabled the Mink Extension? (RuntimeException)

I double-checked indentation dozens of times, checked the namespace is present in vendors directory, swapped things around. Nothing seems to be of help - what's wrong here?

1
Your feature context extends RawMinkContext (or one of its relatives)? - bishop
@bishop Yes, it does. I updated my question with the contents of featureContext.php - Vladimir Hraban
Have you moved extensions out of suites, so that autoload, extensions, and suites are on the same YAML level? - bishop
@bishop Unbelievable, shame on me. Of course the answer was that simple. Thanks a lot, could you please post it as n answer so I can accept it? - Vladimir Hraban
Of course, happy to help! - bishop

1 Answers

2
votes

extensions do not apply per suite, so move that directive up a level, like:

default:
  autoload:
    '': %paths.base%/features/bootstrap
  extensions:
    Behat\MinkExtension:
      base_url:  'http://example.com'
      goutte: ~
  suites:
    default:
      paths:
        - %paths.base%/features