Skip to content

Instantly share code, notes, and snippets.

@bfodeke
Created May 23, 2019 15:26
Show Gist options
  • Save bfodeke/4fc790b6ea27e7a500bf6b37e6872933 to your computer and use it in GitHub Desktop.
Save bfodeke/4fc790b6ea27e7a500bf6b37e6872933 to your computer and use it in GitHub Desktop.
Behat: Logging in to accounts via email or username using drush
/**
* @Given I log in as :name
*/
public function iLogInAs($name) {
$domain = $this->getMinkParameter('base_url');
// Pass base url to drush command.
$uli = $this->getDriver('drush')->drush('uli', array(
"'" . $name . "'",
"--browser=0",
"--uri=$domain",
));
// Trim EOL characters.
$uli = trim($uli);
$this->getSession()->visit($uli);
}
/**
* @Given I log in as user with :name email
*/
public function iLogInAsUserWithEmail($email) {
$domain = $this->getMinkParameter('base_url');
// Pass base url to drush command.
$uli = $this->getDriver('drush')->drush('uli', array(
"--mail='$email'",
"--browser=0",
"--uri=$domain",
));
// Trim EOL characters.
$uli = trim($uli);
$this->getSession()->visit($uli);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment