Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Behat 3.0 features folder/path

Tags:

php

laravel

behat

I am trying to setup Behat 3.0. I want to change the path of where my features go.

Currently, my behat.yml config looks like this:

default:
    autoload:
        '': app/tests/acceptance

Running behat --init wil create the acceptance/FeatureContext.php in the app/tests directory.

However, it will create the features folder in the root of my project. I would instead want this features folder to be placed in the app/tests/acceptance folder.

How can I do this?

like image 557
FooBar Avatar asked Jan 12 '15 15:01

FooBar


1 Answers

Behat 3 has support for suites and profiles.

Only thing you have to do is to add custom paths to the default profile:

default:
  autoload:
    '': %paths.base%/app/tests/acceptance
  suites:
    default:
      paths: [ %paths.base%/app/tests/acceptance/features ]

Tip 1

Always use the %paths.base% variable to be able to run your Behat tests from a different directory.

Tip 2

Depending on Behat's PSR-0 autoload mechanism can be problematic when you'll have more contexts implemented.

Good practice is to use the composer's PSR-4 autoload mechanism to be able to run namespaced Behat features.

After you have setup Behat as in the example above you need to delete the autoload section in the bahat.yml and add contexts to the default profile:

default:
  suites:
    default:
      paths: [ %paths.base%/app/tests/acceptance/features ]
      contexts: [ MyApp\Tests\Acceptance\FeatureContext ]

Add autoloading configuration to composer.json:

{
    [...]
    "autoload-dev": {
        "psr-4": {
            "MyApp\\Tests\\Acceptance\\": "app/tests/acceptance"
        }
    }
    [...]
}

And then simply dump the autoloader with composer dump-autoload.

like image 131
Sławomir Chrobak Avatar answered Sep 21 '22 17:09

Sławomir Chrobak