Search code examples
phpbehatmink

Can't enable Behat Mink extension


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?


Solution

  • 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