From d9b6060830bf0c087b95f9be19b953e706c3d61d Mon Sep 17 00:00:00 2001 From: Jonathan Hedstrom Date: Mon, 4 Dec 2017 15:46:57 -0800 Subject: [PATCH] Merge pull request #434 from jhedstrom/nlisgo-hotfix/assert_logged_in_with_pemissions reroll: Undesirable PHP Notice displayed when Exception thrown Signed-off-by: Jonathan Hedstrom --- .../DrupalExtension/Context/DrupalContext.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Drupal/DrupalExtension/Context/DrupalContext.php b/src/Drupal/DrupalExtension/Context/DrupalContext.php index 6311231e..672da254 100644 --- a/src/Drupal/DrupalExtension/Context/DrupalContext.php +++ b/src/Drupal/DrupalExtension/Context/DrupalContext.php @@ -123,19 +123,22 @@ public function assertLoggedInByName($name) { * @Given I am logged in as a user with the :permissions permission(s) */ public function assertLoggedInWithPermissions($permissions) { + // Create a temporary role with given permissions. + $permissions = array_map('trim', explode(',', $permissions)); + $role = $this->getDriver()->roleCreate($permissions); + // Create user. $user = (object) array( 'name' => $this->getRandom()->name(8), 'pass' => $this->getRandom()->name(16), + 'role' => $role, ); $user->mail = "{$user->name}@example.com"; $this->userCreate($user); - // Create and assign a temporary role with given permissions. - $permissions = array_map('trim', explode(',', $permissions)); - $rid = $this->getDriver()->roleCreate($permissions); - $this->getDriver()->userAddRole($user, $rid); - $this->roles[] = $rid; + // Assign the temporary role with given permissions. + $this->getDriver()->userAddRole($user, $role); + $this->roles[] = $role; // Login. $this->login($user);