function it_changes_password(WithoutOldPasswordChangeUserPasswordCommand $command, UserRepository $repository, User $user) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn($user); $command->newPlainPassword()->shouldBeCalled()->willReturn('new-plain-pass'); $user->changePassword(Argument::type(UserPassword::class))->shouldBeCalled(); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
/** * Handles the given command. * * @param WithoutOldPasswordChangeUserPasswordCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(WithoutOldPasswordChangeUserPasswordCommand $aCommand) { $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); if (null === $user) { throw new UserDoesNotExistException(); } $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder)); $this->repository->persist($user); }