Php – Behat with Mink

bddbehatPHP

Does anyone know how to successfully configure Mink to work with Behat? In case if anyone doesn't know, Behat is a BDD(Behaviour-Driven Development) framework for PHP and Mink provides a browser emulators abstraction layer to test with.

You can find out more about Behat at http://behat.org/ and Mink at https://github.com/Behat/Mink or http://www.knplabs.com/fr/blog/one-mink-to-rule-them-all

Basically i followed the instructions at http://www.knplabs.com/fr/blog/one-mink-to-rule-them-all to configure my Mink to work with my Behat. My behat.yml, the one located inside the Behat folder, not the Mink folder, is as follows:

default:
  paths:
    features:               %%BEHAT_CONFIG_PATH%%/features
    formatter:
    name:                   progress
pretty:
  formatter:
    name:                   pretty
    parameters:
      multiline_arguments:  false
default:
    environment:
        parameters:
            start_url: http://localhost/
imports:
    - mink/behat.yml

I also have the following code in my features/support/boostrap.php

require_once 'mink/autoload.php';

However, having the following code in my features/support/env.php

$world->client = new \Goutte\Client;

would give me a PHP Fatal error: Class 'Goutte\Client' not found in terminal(OSX) when i use the behat command. This happens even if i have the goutte.phar inside my behat/Mink/Vendor/Goutte folder.

Hope anyone can enlighten me on where i went wrong and if there was any part in the question where I wasn't being clear about it, do let me know. Thanks a lot.

Best Answer

Here it is: https://github.com/knplabs/mink-demo ;-)

Basically, with Mink, you don't need to create or require Goutte client it's done by Mink automatically. Your $world was also enhanced and now you're able to get mink session inside step definitions:

$downloadsLink = $world->getSession()->getPage()->findLink('downloads');

Also, you've forgot to include PHPUnit!

See mink-demo for getting great example ;-)

Related Topic