/** * Logs a subject in * * @param array $subject */ public function login(array $subject) { /** @var HasLoginToken */ $caller = $this->identifier->identify($subject); if ($this->authenticator->authenticate($subject, $caller)) { $this->session->setLoginToken($caller->getLoginToken()); $this->currentCaller = $caller; return true; } return false; }
function it_fails_to_log_a_caller_in(LoginTokenIdentifier $identifier, HasLoginToken $caller, Authenticator $authenticator, Session $session) { $subject = ['username' => 'john.doe', 'password' => 'secret']; $caller->getLoginToken()->willReturn(1); $identifier->identify($subject)->willReturn($caller); $authenticator->authenticate($subject, $caller)->willReturn(false); $session->setLoginToken(1)->shouldNotBeCalled(); $this->login($subject)->shouldReturn(false); }