I suffered a lot with it, so here is my (simple) solution, in the hope it will save time to someone oneday. Using behat 3.8.1.
My files layout:
behat.yml
test/acceptance/bootstrap/FeatureContext.php
test/acceptance/features/myAcceptanceTest.feature
My behat.yml file:
default:
autoload: [ '%paths.base%/test/acceptance/bootstrap' ]
suites:
default:
paths: [ '%paths.base%/test/acceptance/features' ]
contexts: [ test\acceptance\bootstrap\FeatureContext ]
Unlike everything I read, including the documentation, I had to add quotes to be able to use the %paths.base%
variable.
The autoload
parameter tells Behat where to find your context php file(s).
The paths
parameter tells Behat where to find your features file(s).
The tricky part is the contexts
parameter: it gives the namespace path of your FeatureContext class. You need to make sure that it matches what you have at the top of your FeatureContext.php
file:
<?php
namespace test\acceptance\bootstrap;
...
class FeatureContext implements Context
{
...
}
With all these planets properly aligned, it works beautifully. From the project folder:
$ vendor/bin/behat
HTH