Behat: How to get a custom generator?

Behat: How to get a custom generator?

Urs Hunkler發表於
Number of replies: 4
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.

評比平均分數: -
In reply to Urs Hunkler

Re: Behat: How to get a custom generator?

Itamar Tzadok發表於

 

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

hth 微笑

評比平均分數:Useful (1)
In reply to Itamar Tzadok

Re: Behat: How to get a custom generator?

Urs Hunkler發表於
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?

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). 微笑