...
Code Block |
---|
language | php |
---|
title | Template data generator (example.php) |
---|
linenumbers | true |
---|
collapse | true |
---|
|
<?php
// This file is part of Rogō
//
// Rogō is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Rogō is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rogō. If not, see <http://www.gnu.org/licenses/>.
namespace testing\datagenerator;
/**
* Generates Rogo users.
*
* @author Your Name <youremail@example.com>
* @copyright Copyright message
* @package testing
* @subpackage datagenerator
*/
class example extends generator {
/**
* To be usable in the main behat datageneration step the methods
* must accept a single array or stdClass parameter only.
*
* @param array|stdClass $parameters
* @return array Contains the values that were inserted into the database.
* @throws data_error
*/
public function create_example($parameters) {
// Your code goes here
}
} |
Using data generators in behat
The main exists step
Code Block |
---|
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:
Code Block |
---|
|
'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:
Code Block |
---|
Given the following "myexample" exist: |
In a custom step
Data generators should be loaded using the \testing\datagenerator\loader::get()
To load the user data generator you would use:
Code Block |
---|
|
\testing\datagenerator\loader::get('users', 'core') |