protected function addNewUser($username, $email, $password, $persist = true, $andFlush = true)
 {
     $user = new User();
     $user->setUsername($username);
     $user->setEmail($email);
     $user->setPlainPassword($password);
     if ($persist) {
         $this->em->persist($user);
         if ($andFlush) {
             $this->em->flush();
             $this->em->refresh($user);
         }
     }
     return $user;
 }
 public function thereIsUser($username, $email, $password, $role = 'ROLE_USER', $enabled = true)
 {
     $user = new User();
     $user->setUsername($username);
     $user->setEmail($email);
     $user->setEnabled($enabled);
     $user->setPlainPassword($password);
     if (null !== $role) {
         $user->addRole($role);
     }
     $this->getEntityManager()->persist($user);
     return $user;
 }