DataFixtures/ORM/InitialUserData.php
public function load(ObjectManager $manager)
    {
        $userGroup = $this->getReference('user-group');
        $adminGroup = $this->getReference('admin-group');

        $user = new User();
        $user->setFirstName('Administrative');
        $user->setLastName('User');
        $user->setUsername('admin');
        $user->setPassword('password');
        $user->addGroup($userGroup);
        $user->addGroup($adminGroup);

        $factory = $this->container->get('security.encoder_factory');
        $encoder = $factory->getEncoder($user);
        $user->setPassword($encoder->encodePassword($user->getPassword(), $user->getSalt()));

        $this->setReference('admin-user', $user);

        $manager->persist($user);

        $manager->flush();
    }
public function load(ObjectManager $manager)
    {
        $userGroup = $this->getReference('user-group');
        $adminGroup = $this->getReference('admin-group');

        $user = new User();
        $user->setFirstName('Administrative');
        $user->setLastName('User');
        $user->setUsername('admin');
        $user->setPassword('password');
        $user->addGroup($userGroup);
        $user->addGroup($adminGroup);

        $factory = $this->container->get('security.encoder_factory');
        $encoder = $factory->getEncoder($user);
        $user->setPassword($encoder->encodePassword($user->getPassword(), $user->getSalt()));

        $this->setReference('admin-user', $user);

        $manager->persist($user);

        $manager->flush();
    }
Load data fixtures with the passed EntityManager

@param \Doctrine\Common\Persistence\ObjectManager $manager