This space is archived
For current information please use the current ExamSys documentation
Writing new data generators
Our behat tests should use data generators to create data that is assumed by tests directly in the database.
All data generators:
- should be located in a sub-directory of testing/datagenerator/generators
- must extend the \testing\datagenerator\generator class
- the file name must be the lowercase classname
- the file must declasre itself part of the testing\datagenerator namespace
Using data generators in behat
The main exists step
Given the following "([^"]*)" exist:
If the data generator can be used by passing a single set of data in an array or object then the it can be used in the main behat exists step.
To make a data generator usable in this step you must add a new entry to the \testing\behat\steps\database\datageneration::$datagenerator_map array. It has the following form:
'myexample' => array('example', 'core', 'create_example'),
The array key is the name that will be used to call the data generator in the step. The values of the sub array have the following meanings
- The first value must be the name of the class that should be used as the data generator
- The second value is the sub-directory that the data generator is located in
- The third value must be the name of the method that should be called
Using the data generator will now look like:
Given the following "myexample" exist:
Details about the required and optional fields for the data generator should be added to Writing automatic functional tests for Rogo
In a custom step
Data generators should be loaded using the \testing\datagenerator\loader::get()
To load the user data generator you would use:
\testing\datagenerator\loader::get('users', 'core')