/** * @covers Kunstmaan\AdminBundle\Entity\User::getGroups */ public function testGetGroups() { /* @var $group1 GroupInterface */ $group1 = $this->getMock('FOS\\UserBundle\\Model\\GroupInterface'); /* @var $group2 GroupInterface */ $group2 = $this->getMock('FOS\\UserBundle\\Model\\GroupInterface'); $this->object->addGroup($group1); $this->object->addGroup($group2); $collection = new ArrayCollection(); $collection->add($group1); $collection->add($group2); $this->assertEquals($collection, $this->object->getGroups()); }
/** * Create a user * * @param ObjectManager $manager The object manager * @param string $username The username * @param string $password The plain password * @param string $email The email of the user * @param string $locale The locale (language) of the user * @param array $roles The roles the user has * @param array $groups The groups the user belongs to * @param bool $enabled Enable login for the user * @param bool $changed Disable password changed for the user * * @return User */ private function createUser(ObjectManager $manager, $username, $password, $email, $locale, array $roles = array(), array $groups = array(), $enabled = false, $changed = false) { $user = new User(); $user->setUsername($username); $user->setPlainPassword($password); $user->setRoles($roles); $user->setEmail($email); $user->setEnabled($enabled); $user->setAdminLocale($locale); $user->setPasswordChanged($changed); foreach ($groups as $group) { $user->addGroup($group); } $manager->persist($user); return $user; }