Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit e4d14d1

Browse files
committed
[Behat] Add null guard clause for User in auth test
In case FOS User manage can't load a user, trying to access it's password would raise an exception.
1 parent bb78b36 commit e4d14d1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

features/bootstrap/FOSWebContext.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ public function iAmAuthorizedWith($accessRole)
100100

101101
$user = $fosUserManager->findUserByUsername('admin');
102102

103-
$token = new UsernamePasswordToken($user, $user->getPassword(), $providerKey, [$accessRole]);
103+
if (null !== $user) {
104+
$token = new UsernamePasswordToken($user, $user->getPassword(), $providerKey, [$accessRole]);
104105

105-
$session->set('_security_'.$providerKey, serialize($token));
106-
$session->save();
106+
$session->set('_security_'.$providerKey, serialize($token));
107+
$session->save();
107108

108-
$cookie = new Cookie($session->getName(), $session->getId());
109-
$client->getCookieJar()->set($cookie);
109+
$cookie = new Cookie($session->getName(), $session->getId());
110+
$client->getCookieJar()->set($cookie);
111+
}
110112
}
111113
}

0 commit comments

Comments
 (0)