BehatBundle, BehatMinkBundle and friends

Published on

Apr 20, 2011

technical

Apr 21, 2011 − News in the Behat (the PHP BDD framework) world: --rerun option in Behat, a BehatMinkBundle to use Mink (and test your JS) in your Symfony projects... and a brand new BehatBundle!

Behat 1.1.1, Mink 0.2, BehatMinkBundle and BehatBundle. Man, that's a lot! But let's start from new Behat version.

Behat 1.1.1

New version brings bunch of cool new features and bugfixes, but most of the changes happened inside of BehatCommand. Just look at this commit. Also, with cleanup and refactoring, I've added some hotness on top of core functionality:

Features --rerun

Try it with:

bin/behat.php --rerun ~/.behat_rerun

In this case, Behat will store all failed scenarios paths in ~/.behat_rerun file OR will use it as source, if it's already has some failing scenarios. So, basic usecase is:

bin/behat.php --rerun ~/.behat_rerun

runs all features in current workdir. If you have failed scenarios and you run:

bin/behat.php --rerun ~/.behat_rerun

again, then Behat will run only failed scenarios from previous call. Then, you fix scenarios and run command once again:

bin/behat.php --rerun ~/.behat_rerun

It shows previously failed scenarios as green. And next time:

bin/behat.php --rerun ~/.behat_rerun

It will again run all scenarios in current workdir.

Configuration paths tuneup

When you want to use mink with Behat, you import it's configuration in your behat.yml like this:

# behat.yml
default:
  environment:
    parameters:
      start_url: http://your_app_host.loc/
imports:
  - mink/behat.yml

But what if you want to use your own custom step definitions instead of bundled ones (Behat doesn't support step definitions overriding)? Then you can tell Behat to exlude mink steps paths from configuration:

# behat.yml
default:
  paths:
    steps:
      - !%%BEHAT_MINK_PATH%%/src/Behat/Mink/Integration/steps
    steps_i18n:
      - !%%BEHAT_MINK_PATH%%/src/Behat/Mink/Integration/steps/i18n
  environment:
    parameters:
      start_url: http://your_app_host.loc/
imports:
  - mink/behat.yml

Notice this ! in front of paths. It simply means: "don't use this path!". Read changelog for all release details.

Mink 0.2

Behat integration in Mink was totally refactored too. Now it's cleaner, simplier and more configurable. For example, now if you need to talk with your server through proxy, then you can tell GoutteDriver about it:

# behat.yml
default:
    environment:
        parameters:
            start_url: http://en.wikipedia.org/
            goutte:
                zend_config:
                    adapter:        ZendHttpClientAdapterProxy
                    proxy_host:  proxy.myhost.com
                    proxy_port:  8080
imports:
    - mink/behat.yml

Also, thanks to Jeremy Bush we now have bunch of cool new web steps, available right from the start. Check all available steps with:

bin/behat.php --steps --lang en

Read changelog for all release details.

BehatMinkBundle

As I said earlier, Mink was created especially for Behat, but that doesn't mean that you can't use it without Behat. BehatMinkBundle is all about using greatest browsing emulation library natively with greatest framework of all time - Symfony2. With BehatMinkBundle, you can enable/configure 3 different type of drivers and start to use them in your PHPUnit functional tests in about 5 minutes. BehatMinkBundle fully support latest Symfony2 SE and flawlessly integrates with it. By default, BehatMinkBundle uses Symfony2 test.client to test your applications, which is statefull and not what you actually need sometimes. But don't worry, you can switch your entire test suite to goutte or sahi in matter of seconds ;-) Read readme for further information, including installation instruction.

BehatBundle

Updated BehatBundle. Or... I think I should say brand new, cuz BehatBundle was changed entirely. Now, it uses BehatMinkBundle to setup browser emulation library and Mink step definitions (and translations) to run your features. Just install BehatBundle, BehatMinkBundle, configure MinkBundle and you're ready to go. All default Mink steps and translations are available in your Symfony2 projects. Read readme for further information, including installation instruction.

sfBehatPlugin

Update is coming...

Written by

KNP Labs
KNP Labs

Comments