/** * {@inheritdoc} */ public function execute($request = null) { if (!$request instanceof SignInUserRequest) { throw new \InvalidArgumentException('The request must be SignInUserRequest instance'); } $email = $request->email(); $password = $request->password(); $user = $this->userRepository->userOfEmail($email); if ($user instanceof User) { throw new UserAlreadyExistsException(); } $user = $this->userFactory->register($this->userRepository->nextIdentity(), $email, $password); $this->userRepository->save($user); return $user; }
function it_registers_the_user(SignInUserRequest $request, UserEmail $email, PersistentUserRepository $repository, User $user, UserFactory $factory, UserId $userId) { $request->email()->shouldBeCalled()->willReturn($email); $request->password()->shouldBeCalled()->willReturn('password'); $repository->userOfEmail($email)->shouldBeCalled()->willReturn(null); $repository->nextIdentity()->shouldBeCalled()->willReturn($userId); $factory->register($userId, $email, 'password')->shouldBeCalled()->willReturn($user); $repository->save($user)->shouldBeCalled(); $this->execute($request)->shouldReturn($user); }