/** @test */ public function should_return_true_when_user_email_is_unique() { $this->repository->shouldReceive('userOfEmail')->andReturn(null); $user = UserStub::create(); $userRepo = $this->repository; $this->assertTrue($this->guard->handle(compact('user', 'userRepo'))); }
/** @test */ public function should_return_user() { $this->userRepository->shouldReceive('userOfEmail')->andReturn($this->user); $this->hashingService->shouldReceive('check')->andReturn(true); $credentials = ['email' => '*****@*****.**', 'password' => 'password']; $user = $this->authService->loginWithCredentials($credentials); $this->assertEquals($user, $this->user); }
private function findUserByEmail(Email $email) { $user = $this->userRepository->userOfEmail($email); if (!$user) { throw new NotFoundException('user_email_not_found', $email); } return $user; }
/** @test */ public function should_register_new_user() { $this->repository->shouldReceive('userOfEmail')->andReturn(null); $this->repository->shouldReceive('userOfUsername')->andReturn(null); $this->repository->shouldReceive('nextIdentity')->andReturn(UserId::generate()); $this->hashing->shouldReceive('hash')->andReturn(new HashedPassword('password')); $this->repository->shouldReceive('add'); $user = $this->registrar->register('*****@*****.**', 'First', 'Last', 'username', 'password'); $this->assertInstanceOf(User::class, $user); }
public function generateUsername(FirstName $firstName, LastName $lastName, $offset = 1) { $fullNameStr = $firstName->toString() . $lastName->toString(); $modifier = $offset > 1 ? $offset : ''; $username = Username::fromNative(str_slug($fullNameStr . $modifier)); if ($this->userRepository->userOfUsername($username)) { return $this->generateUsername($firstName, $lastName, $offset + 1); } return $username; }
/** @test */ public function should_add_new_user() { $userStub = UserStub::create(); $user = $this->repository->add($userStub); $this->em->clear(); $user = $this->repository->userOfEmail($userStub->email()); $this->assertEquals($userStub->id(), $user->id()); $this->assertEquals($userStub->email(), $user->email()); $this->assertEquals($userStub->username(), $user->username()); $this->assertEquals($userStub->firstName(), $user->firstName()); $this->assertEquals($userStub->lastName(), $user->lastName()); }
/** * Attempt to find a user by their email address * * @param Email $email * @return User * @throws ValueNotFoundException */ private function findUserByEmail(Email $email) { $user = $this->users->userOfEmail($email); if ($user) { return $user; } throw new ValueNotFoundException("{$email} is not a registered email address"); }