public function testActivate() { $this->user->activate(); $this->assertEquals('*****@*****.**', $this->user->getEmail()); $this->assertEquals('john', $this->user->getUsername()); $this->assertEquals('John', $this->user->getName()); $this->assertEquals('Smith', $this->user->getSurname()); $this->assertNotEmpty($this->user->getPassword()); $this->assertEmpty($this->user->getCode()); $this->assertFalse($this->user->isFrozen()); $this->assertInstanceOf(DateTime::class, $this->user->getCreatedAt()); $this->assertInstanceOf(ReadOnlyCollectionWrapper::class, $this->user->getRoles()); }
public function createUser(User $user) { $now = new DateTime(); $rawPass = null; $userPass = $user->getPassword(); if (empty($userPass)) { $rawPass = Strings::random(self::RANDOM_PASS_LENGTH); } else { $rawPass = $user->getPassword(); } $this->entityManager->beginTransaction(); $user->setPassword($this->generateNewPassword($rawPass)); $user->setCreated($now); $user->setUpdated($now); $user->setWebProfile(new WebProfile()); $user->contact->setUpdated($now); $user->getWebProfile()->setUpdated($now); $user->getWebProfile()->setStatus(WebProfileStatus::BAD); try { $this->contactDao->save($user->getContact()); } catch (DuplicateEntryException $e) { $this->entityManager->rollback(); throw new Exceptions\DuplicateEntryException($e->getMessage(), Exceptions\DuplicateEntryException::EMAIL_EXISTS, $e->getPrevious()); } try { $this->userDao->save($user); $this->entityManager->commit(); } catch (DuplicateEntryException $e) { $this->entityManager->rollback(); throw new Exceptions\DuplicateEntryException($e->getMessage(), Exceptions\DuplicateEntryException::BIRTH_NUM_EXISTS, $e->getPrevious()); } catch (\Exception $e) { $this->entityManager->rollback(); $this->logError($e->getMessage()); throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious()); } $this->logInfo("User %user was successfully created", ["user" => $user]); $user->insertRawPassword($rawPass); $this->onCreate(clone $user); }