First, what I tried to do is to add profile2 informations to a user created with the step:
Given users

Here my step definition:

  /**
   * @Given /^profiles:$/
   */
 public function createProfiles(TableNode $profilesTable) {
   foreach ($profilesTable->getHash() as $profileHash) {
     $profileHash['user'] = $this->users[$profileHash['drupal_username']];
     $profile = profile2_create($profileHash);
     profile2_save($profile);
   }
 }

Problem is, I couldn't manage to find how to to call the profile2_create method, it is not found. I searched how and where the Drupal bootstrap is loaded, but no success so far.

Anybody can help me to achieve this?

Comments

jhedstrom’s picture

Hmm, since profile2_create() is in the profile2.module file, it should always be available once Drupal is bootstrapped. Can you post a stack trace for the fatal error?

b2f’s picture

Before I do that, can you confirm that Drupal is bootstrapped when a subcontext class of the form *behat.inc is constructed ? Because when I place a debugging string in drush driver's bootstrap function, it is not showing before the error stack trace (@api tag is set on the Feature).

---

PHP Fatal error:  Call to undefined function {any Drupal function } in sites/all/modules/dbdd/dbdd.behat.inc on line 19
PHP Stack trace:
PHP   1. {main}() sites/all/vendor/behat/behat/bin/behat:0
PHP   2. Symfony\Component\Console\Application->run() sites/all/vendor/behat/behat/bin/behat:32
PHP   3. Behat\Behat\Console\BehatApplication->doRun() sites/all/vendor/symfony/console/Symfony/Component/Console/Application.php:124
PHP   4. Symfony\Component\Console\Application->doRun() sites/all/vendor/behat/behat/src/Behat/Behat/Console/BehatApplication.php:68
PHP   5. Symfony\Component\Console\Application->doRunCommand() sites/all/vendor/symfony/console/Symfony/Component/Console/Application.php:194
PHP   6. Symfony\Component\Console\Command\Command->run() sites/all/vendor/symfony/console/Symfony/Component/Console/Application.php:880
PHP   7. Behat\Behat\Console\Command\BehatCommand->execute() sites/all/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:245
PHP   8. Behat\Behat\Console\Command\BehatCommand->runFeatures() sites/all/vendor/behat/behat/src/Behat/Behat/Console/Command/BehatCommand.php:128
PHP   9. Behat\Gherkin\Node\AbstractNode->accept() sites/all/vendor/behat/behat/src/Behat/Behat/Console/Command/BehatCommand.php:150
PHP  10. Behat\Behat\Tester\FeatureTester->visit() sites/all/vendor/behat/gherkin/src/Behat/Gherkin/Node/AbstractNode.php:42
PHP  11. Behat\Gherkin\Node\AbstractNode->accept() sites/all/vendor/behat/behat/src/Behat/Behat/Tester/FeatureTester.php:88
PHP  12. Behat\Behat\Tester\ScenarioTester->visit() sites/all/vendor/behat/gherkin/src/Behat/Gherkin/Node/AbstractNode.php:42
PHP  13. Behat\Behat\Tester\ScenarioTester->visitStep() sites/all/vendor/behat/behat/src/Behat/Behat/Tester/ScenarioTester.php:87
PHP  14. Behat\Gherkin\Node\AbstractNode->accept() sites/all/vendor/behat/behat/src/Behat/Behat/Tester/ScenarioTester.php:148
PHP  15. Behat\Behat\Tester\StepTester->visit() sites/all/vendor/behat/gherkin/src/Behat/Gherkin/Node/AbstractNode.php:42
PHP  16. Behat\Behat\Tester\StepTester->executeStep() sites/all/vendor/behat/behat/src/Behat/Behat/Tester/StepTester.php:95
PHP  17. Behat\Behat\Tester\StepTester->executeStepDefinition() sites/all/vendor/behat/behat/src/Behat/Behat/Tester/StepTester.php:126
PHP  18. Behat\Behat\Definition\Annotation\Definition->run() sites/all/vendor/behat/behat/src/Behat/Behat/Tester/StepTester.php:157
PHP  19. call_user_func_array() sites/all/vendor/behat/behat/src/Behat/Behat/Definition/Annotation/Definition.php:155
PHP  20. CustomBehatContext->theCustomStep() sites/all/vendor/behat/behat/src/Behat/Behat/Definition/Annotation/Definition.php:155
b2f’s picture

I went further in my investigations, it seems that the Drupal bootstrap only occurs when getDriver() is called inside the DrupalContext class. It doesn't seem to be possible to bootstrap from a module.behat.inc context as is. Am I correct or am I missing something ?

b2f’s picture

The answer to this may be getMainContext. I am going to try that.

b2f’s picture

Status: Active » Closed (works as designed)

EDIT: a quick note to explain how I fixed it, I added drupal_root in behat.yml next to the drupal driver section. Drush driver alone was unable to bootstrap, but by adding drupal driver support in beyat.yml, Drupal Extension managed to bootstrap even without explicitly adding @drupal to the scenario.

b2f’s picture

Issue summary: View changes

format