Behat: How to get a custom generator?

Behat: How to get a custom generator?

by Urs Hunkler -
Number of replies: 4
Picture of Core developers

Given the Behat rule file "local/more_rules/tests/behat/behat_local_core_rules.php" and the generator file "local/more_rules/tests/generator/lib.php".

The rules class is build with

class behat_local_more_rules extends behat_base {}

The generator class is build with

class local_more_rules_generator extends testing_data_generator {}

 

To be able to call the generator methods I need the reference to the generator class. In "lib/tests/behat/behat_data_generators.php" I found the line that gets the datagenerator

$this->datagenerator = testing_util::get_data_generator();

 

When I call the same line in my rules script I get an error. My solution for now is to hard code the connection to the generator with

require_once(__DIR__.'/../generator/lib.php');
$this->generator = new local_more_rules_generator();

 

This code works but I hope there might be a more general solution.

Average of ratings: -
In reply to Urs Hunkler

Re: Behat: How to get a custom generator?

by Itamar Tzadok -

 

$this->datagenerator = testing_util::get_data_generator()->get_plugin_generator('local_more_rules');

hth smile

Average of ratings: Useful (1)
In reply to Itamar Tzadok

Re: Behat: How to get a custom generator?

by Urs Hunkler -
Picture of Core developers

Thanks a lot, Itamar. That was the method I was looking for.

Did you find that method in a documentation or did you discover it digging in Moodle code?

In reply to Urs Hunkler

Re: Behat: How to get a custom generator?

by Itamar Tzadok -

Code. It is probably too new to be docs-umented and at any rate API documentation seem to rely more and more on better PHPDoc comments and the use of docs generators (with or without IDEs). smile