示例#1
0
 /**
  * @param \Notes\Domain\Entity\User $user
  * @return mixed
  */
 public function addUser(User $user)
 {
     // TODO: Implement addUser() method
     if (!$user instanceof User) {
         throw new InvalidArgumentException(__METHOD__ . '(): $user has to be a User object');
     }
     $this->role = new AdminRole();
     $this->id = $user->getId();
     $this->name = $user->getUsername();
     $this->role->addUserInRole($user);
     $this->admins[] = $user;
 }
     it('should return the Admin Role\'s list of users', function () {
         $faker = \Faker\Factory::create();
         $user = new User(new Uuid());
         $user->setUsername(new StringLiteral($faker->userName));
         $users = array($user);
         $admin = new AdminRole();
         $admin->addUserInRole($user);
         expect($admin->getRoleUsers())->equal($users);
     });
 });
 describe('->getRoleName', function () {
     it('should get the correct admin role\'s username', function () {
         $user = new User(new Uuid());
         $user->setUsername(new StringLiteral('Joe'));
         $admin = new AdminRole();
         $admin->addUserInRole($user);
         $actual = $admin->getRoleName();
         expect($actual->__toString())->equal('Joe');
     });
 });
 describe('->removeRoleUser()', function () {
     it('should delete a user that is in the admin role', function () {
         $actual = new AdminRole();
         $user = new User(new Uuid());
         $user->setUsername(new StringLiteral('Joe'));
         $before = $actual->getRoleUsers();
         $actual->removeRoleUser();
         $after = $actual->getRoleUsers();
         expect(!in_array($user, $before));
         expect(in_array($user, $after));
     });