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_generate_valid_username_if_already_exists() { $first = FirstName::fromNative('Evey'); $last = LastName::fromNative('Edward'); $this->repository->shouldReceive('userOfUsername')->andReturn(true, true, null); $username = $this->registrar->generateUsername($first, $last); $this->assertEquals('eveyedward3', $username->toString()); }
public static function create() { // return 'here'; $faker = Factory::create(); $identifier = UserId::generate(); $email = Email::fromNative($faker->email); $first = FirstName::fromNative($faker->word); $last = LastName::fromNative($faker->word); $username = Username::fromNative($faker->word); $password = HashedPassword::fromNative(str_random(10)); return User::create($identifier, $email, $first, $last, $username, $password); }
/** @test */ public function should_create_from_native() { $last_name = LastName::fromNative('Edward'); $this->assertInstanceOf('Cffs\\Domain\\Model\\Identity\\LastName', $last_name); }
/** * Set the User's last name * * @param LastName $lastName * @return void */ private function setLastName(LastName $lastName) { $this->lastName = $lastName->toString(); }