Behat has several options for splitting your FeatureContext into multiple classes. Firstly, you can use php5 inheritance from the old school. If inheritance is not what you want, Behat also supports subcontexts: " Using subcontexts ."
Further, if you want to name your class differently from FeatureContext , you can override this in the Context Configuration section of your behat.yml config.
Thus, you can divide common definitions and bindings into separate classes and use them in other sets of functions, as well as with subcontext or inheritance.
But your question also asks:
I would like to have one definition file for each function file.
This request is absolutely incorrect. Behat and the BDD script is a description of the behavior of your application in business terms and the creation of a test dictionary for the described behavior. With this in mind, you could logically have several different dictionaries for one set of functions. By writing the definitions for the step, you say that it means Given I am on "/news" . And when you want this step to mean different things from function to function, you are doing it wrong.
Behat consists of 2 basic and fairly separate concepts:
*.feature files written in Gerkinโs language. These files should be self-describing. So they must provide all the information for the reader to understand them. Gherkin is not a new programming language for your functional tests, it is just a markdown for your user stories!FeatureContext.php , describes how Behat should test your functions. It defines the application dictionary for use with the entire set of application functions. This is a programming modem between your markdown-like user stories and actual function tests.
And you should not ruin it. A separate set of functions should have a dictionary with one step (definitions). But you can use one dictionary in several sets of functions thanks to inheritance and subcontexts. And yes, you can split the dictionary of one set into several php classes ,-)
everzet
source share