/** * Handles the given command. * * @param EnableUserCommand $aCommand The command * * @throws UserTokenNotFoundException when the user token does not exist */ public function __invoke(EnableUserCommand $aCommand) { $confirmationToken = $aCommand->confirmationToken(); $user = $this->repository->userOfConfirmationToken(new UserToken($confirmationToken)); if (null === $user) { throw new UserTokenNotFoundException(); } $user->enableAccount(); $this->repository->persist($user); }
function it_doesnt_activate_user_with_wrong_token(UserRepository $repository, User $user, EnableUserCommand $command) { $command->confirmationToken()->shouldBeCalled()->willReturn('confirmation-token'); $user->enableAccount()->shouldNotBeCalled(); $repository->userOfConfirmationToken(new UserToken('confirmation-token'))->shouldBeCalled()->willReturn(null); $repository->persist($user)->shouldNotBeCalled(); $this->shouldThrow(UserTokenNotFoundException::class)->during__invoke($command); }