/** * @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 OwnerRole(); $this->id = $user->getId(); $this->name = $user->getUsername(); $this->role->addUserInRole($user); $this->owners[] = $user; }
* User: tylercazier * Date: 11/29/15 * Time: 8:38 PM */ use Notes\Domain\Entity\Role\OwnerRole; use Notes\Domain\ValueObject\Uuid; describe('Notes\\Domain\\Entity\\Role\\OwnerRole', function () { describe('-->__construct()', function () { it('should construct a new OwnerRole object', function () { $faker = \Faker\Factory::create(); $ownerRole = new OwnerRole($faker->uuid); expect($ownerRole)->to->be->instanceof('Notes\\Domain\\Entity\\Role\\OwnerRole'); }); }); describe('-->getId()', function () { it('should return the OwnerRole roleId', function () { $faker = \Faker\Factory::create(); $roleId = $faker->uuid; $ownerRole = new OwnerRole($roleId); expect($ownerRole->getId())->equal($roleId); }); }); describe('-->getPermissions()', function () { it('should return the OwnerRole roleId', function () { $ownerRole = new OwnerRole(new Uuid()); for ($i = 0; $i < 4; $i++) { expect($ownerRole->getPermissions()[$i])->equal($i); } }); }); });
$user = new User(new Uuid()); $user->setUsername(new StringLiteral($faker->userName)); $users = array($user); $owner = new OwnerRole(); $owner->addUserInRole($user); expect($owner->getRoleUsers())->equal($users); }); }); describe('->getRoleName', function () { it('should get the correct Owner role\'s username', function () { $user = new User(new Uuid()); $user->setUsername(new StringLiteral('Joe')); $owner = new OwnerRole(); $owner->addUserInRole($user); $actual = $owner->getRoleName(); expect($actual->__toString())->equal('Joe'); }); }); describe('->removeRoleUser()', function () { it('should delete a user that is in the owner role', function () { $actual = new OwnerRole(); $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)); }); }); });
$permission = 5; $owner->addPermission($permission); expect(count($owner->getPermissions()))->to->be->equal(1); expect($owner->getPermissions()[0])->to->be->equal($permission); }); }); describe('->__removePermission()', function () { it('should return the correct permission when added', function () { $owner = new OwnerRole(); /** @var int $permission */ $permission = 5; $owner->addPermission($permission); expect(count($owner->getPermissions()))->to->be->equal(1); expect($owner->getPermissions()[0])->to->be->equal($permission); $owner->removePermission($permission); expect(count($owner->getPermissions()))->to->be->equal(0); }); it('should return false if the permission does not exist', function () { $owner = new OwnerRole(); /** @var int $permission */ $permission = 5; /** @var int $permission */ $invalidPermission = 6; $owner->addPermission($permission); expect(count($owner->getPermissions()))->to->be->equal(1); expect($owner->getPermissions()[0])->to->be->equal($permission); $result = $owner->removePermission($invalidPermission); expect($result)->to->be->false; }); }); });