From b3abba05b8a90c6a395f78214b48fb96d9007bc3 Mon Sep 17 00:00:00 2001 From: Rajab Natshah <rajabn@gmail.com> Date: Mon, 1 Jun 2020 11:52:57 +0300 Subject: [PATCH] Issue #3138611: Fix Notice: Undefined index: NOT_EXISTED_USER in VarbaseContext by replacing the captured notice with an exception lookup message for better automated testing reports --- tests/features/bootstrap/VarbaseContext.php | 33 +++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/features/bootstrap/VarbaseContext.php b/tests/features/bootstrap/VarbaseContext.php index 7f7ad387..7d05ddb3 100644 --- a/tests/features/bootstrap/VarbaseContext.php +++ b/tests/features/bootstrap/VarbaseContext.php @@ -72,21 +72,28 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext */ public function iAmloggedInUserWithTheUser($username) { - try { - $password = $this->users[$username]; - } - catch (Exception $e) { - throw new \Exception("Password not found for '$username'."); + if (isset($this->users[$username])) { + try { + $password = $this->users[$username]; + } + catch (Exception $e) { + throw new \Exception("Password not found for '$username'."); + } + + if ($this->loggedIn()) { + $this->logout(); + } + + $element = $this->getSession()->getPage(); + $this->getSession()->visit($this->locatePath('/user')); + $element->fillField('edit-name', $username); + $element->fillField('edit-pass', $password); + $submit = $element->findButton('op'); + $submit->click(); } - if ($this->loggedIn()) { - $this->logout(); + else { + throw new \Exception("The '$username' user name is wrong or it was not listed in the list of default testing users."); } - $element = $this->getSession()->getPage(); - $this->getSession()->visit($this->locatePath('/user')); - $element->fillField('edit-name', $username); - $element->fillField('edit-pass', $password); - $submit = $element->findButton('op'); - $submit->click(); } /** -- GitLab