Пример #1
0
 public function __construct(User $user, DTOBuilderFactoryInterface $dtoBuilderFactory)
 {
     $this->entity = $user;
     $this->dtoBuilderFactory = $dtoBuilderFactory;
     $this->entityDTO = $this->getEntityDTO();
     $this->setId();
     $this->setTime();
     $this->entityDTO->externalId = $this->entity->getExternalId();
     $this->entityDTO->email = $this->entity->getEmail();
     $this->entityDTO->firstName = $this->entity->getFirstName();
     $this->entityDTO->lastName = $this->entity->getLastName();
     $this->entityDTO->totalLogins = $this->entity->getTotalLogins();
     $this->entityDTO->lastLogin = $this->entity->getLastLogin();
     $this->entityDTO->status = $this->dtoBuilderFactory->getUserStatusTypeDTOBuilder($this->entity->getStatus())->build();
 }
 /**
  * @param User $user
  * @param string $password
  * @throws UserPasswordValidationException
  */
 public function assertPasswordValid(User $user, $password)
 {
     if (strlen($password) < 8) {
         throw new UserPasswordValidationException('Password must be at least 8 characters');
     }
     if ($user->verifyPassword($password)) {
         throw new UserPasswordValidationException('Invalid password');
     }
     $tooSimilarValues = [$user->getFirstName(), $user->getLastName(), $user->getFullName(), $user->getEmail()];
     foreach ($tooSimilarValues as $text) {
         if ($this->isTooSimilar($password, $text)) {
             throw new UserPasswordValidationException('Password is too similar to your name or email');
         }
     }
 }
Пример #3
0
 public function testCreateDefaults()
 {
     $user = new User();
     $this->assertTrue($user->getId() instanceof UuidInterface);
     $this->assertTrue($user->getCreated() instanceof DateTime);
     $this->assertTrue($user->getStatus()->isActive());
     $this->assertSame(null, $user->getExternalId());
     $this->assertSame(null, $user->getEmail());
     $this->assertSame(null, $user->getFirstName());
     $this->assertSame(null, $user->getLastName());
     $this->assertSame(null, $user->getCart());
     $this->assertSame(null, $user->getLastLogin());
     $this->assertSame(0, $user->getTotalLogins());
     $this->assertSame(0, count($user->getUserRoles()));
     $this->assertSame(0, count($user->getUserTokens()));
     $this->assertSame(0, count($user->getUserLogins()));
     $this->assertSame(0, count($user->getOrders()));
 }