The basic Behat use case recommends using FeatureContext
class. Also, you can specify any other PHP classes in the features/bootstrap
directory and they are loaded, but in the alphabetical order, no matter what the dependencies are.
Given there is a trait and a FeatureContext class:
features/bootstrap/FeatureContext.php
features/bootstrap/MyLovelyTrait.php
What is the best way to load it properly? Obviously, MyLovelyTrait is used within the FeatureContext:
class FeatureContext extends BehatContext {
use MyLovelyTrait;
}
And that fails because M > F
, in the alphabet.
I will be happy to use composer autoloading, but I don't want to require_once
the autoload.php
file in the top of BehatContext.php
file. Is there a way to specify this in behat.yml
configuration? Also, any other best practice answer regarding class-loading of Behat context files will be appreciated.
I'm not 100% sure this is answering your question but I am under the impression that you are trying to use multiple context files? If so you don't need the use statement instead within the FeatureContext.php construct method we use the line:
$this -> useContext('Subcontext', new Subcontext($parameters));
In this case the other context you want to use is called "Subcontext".
A good reason not to useContext('Subcontext') can be found in the Changelog of the upcoming version 3 of Behat:
3.0.0beta1 / 2013-08-13
...
* Subcontexts removed in favor of context pools
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