예제 #1
0
 /**
  * Tests whether the constructor works as expected.
  *
  * @return void
  */
 public function testConstructorSetsParametersCorrectly()
 {
     $user = new UserEntity('username', 'passwordHash', 'emailAddress', 'firstName', 'lastName');
     $this->assertNull($user->getId());
     $this->assertSame('username', $user->getUsername());
     $this->assertSame('passwordHash', $user->getPasswordHash());
     $this->assertSame('emailAddress', $user->getEmailAddress());
     $this->assertSame('firstName', $user->getFirstName());
     $this->assertSame('lastName', $user->getLastName());
     $this->assertSame('firstName lastName', $user->getDisplayName());
     $this->assertEmpty($user->getRoles()->count());
 }
예제 #2
0
 /**
  * Tests whether findByUsername works as expected.
  *
  * @return void
  */
 public function testFindByUsername()
 {
     // define username
     $username = '******';
     // create user entity
     $user = new UserEntity($username, '', '', '', '');
     // verify user does not exist
     $this->assertNull(Application::getPersistenceManager()->getRepository('UserEntity')->findByUsername($user->getUsername()));
     // create user
     Application::getPersistenceManager()->getEntityManager()->persist($user);
     Application::getPersistenceManager()->getEntityManager()->flush();
     // verify user exist
     $userFromDb = Application::getPersistenceManager()->getRepository('UserEntity')->findByUsername($user->getUsername());
     $this->assertNotNull($userFromDb);
     $this->assertSame($username, $userFromDb->getUsername());
     $this->assertNotNull($username, $userFromDb->getId());
     // remove user
     Application::getPersistenceManager()->getEntityManager()->remove($user);
     Application::getPersistenceManager()->getEntityManager()->flush();
 }