示例#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;
 }
            $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));
        });
    });
});
            /** @var int $permission */
            $permission = 5;
            $admin->addPermission($permission);
            expect(count($admin->getPermissions()))->to->be->equal(1);
            expect($admin->getPermissions()[0])->to->be->equal($permission);
        });
    });
    describe('->__removePermission()', function () {
        it('should return the correct permission when added', function () {
            $admin = new AdminRole();
            /** @var int $permission */
            $permission = 6;
            $admin->addPermission($permission);
            expect(count($admin->getPermissions()))->to->be->equal(1);
            expect($admin->getPermissions()[0])->to->be->equal($permission);
            $admin->removePermission($permission);
            expect(count($admin->getPermissions()))->to->be->equal(0);
        });
        it('should return false if the permission does not exist', function () {
            $admin = new AdminRole();
            /** @var int $permission */
            $permission = 5;
            /** @var int $invalidPermission */
            $invalidPermission = 6;
            $admin->addPermission($permission);
            expect(count($admin->getPermissions()))->to->be->equal(1);
            $result = $admin->removePermission($invalidPermission);
            expect($result)->to->be->false;
        });
    });
});
 * User: tylercazier
 * Date: 11/29/15
 * Time: 8:37 PM
 */
use Notes\Domain\Entity\Role\AdminRole;
use Notes\Domain\ValueObject\Uuid;
describe('Notes\\Domain\\Entity\\Role\\AdminRole', function () {
    describe('-->__construct()', function () {
        it('should construct a new AdminRole object', function () {
            $faker = \Faker\Factory::create();
            $adminRole = new AdminRole($faker->uuid);
            expect($adminRole)->to->be->instanceof('Notes\\Domain\\Entity\\Role\\AdminRole');
        });
    });
    describe('-->getId()', function () {
        it('should return the AdminRole roleId', function () {
            $faker = \Faker\Factory::create();
            $roleId = $faker->uuid;
            $adminRole = new AdminRole($roleId);
            expect($adminRole->getId())->equal($roleId);
        });
    });
    describe('-->getPermissions()', function () {
        it('should return the AdminRole permissions list', function () {
            $adminRole = new AdminRole(new Uuid());
            for ($i = 0; $i < 4; $i++) {
                expect($adminRole->getPermissions()[$i])->equal($i + 4);
            }
        });
    });
});