/** * Handles the given command. * * @param RequestRememberPasswordCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(RequestRememberPasswordCommand $aCommand) { $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); if (null === $user) { throw new UserDoesNotExistException(); } $user->rememberPassword(); $this->repository->persist($user); }
function it_does_not_request_remember_password_because_user_does_not_exist(RequestRememberPasswordCommand $command, UserRepository $repository) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }