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?
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 ]
Always use the %paths.base%
variable to be able to run your Behat tests from a different directory.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With