示例#1
0
 /**
  * @param string $email
  * @param string $password
  * @param bool   $isStaff
  *
  * @throws \DomainException
  * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
  *
  * @return User
  */
 public function make(string $email, string $password, bool $isStaff) : User
 {
     if (!$this->validate($email, $password)) {
         throw new DomainException();
     }
     $user = new User();
     $user->email = $email;
     $user->password = $this->hasher->make($password);
     if ($isStaff) {
         $staffRole = $this->roleResource->mustFindByName(Role::STAFF);
         $staffRole->users()->save($user);
     }
     return $user;
 }
 /**
  * Should create a non-staff user if the --staff option is not given.
  */
 public function testDoesNotCreateStaffUserWithoutFlag()
 {
     $this->roleResource->expects($this->never())->method('mustFindByName');
     $this->userResource->expects($this->never())->method('roles');
     $tester = $this->commandTester($this->makeUser);
     $tester->execute([]);
 }
示例#3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $staff = Role::create(['name' => Role::STAFF]);
     $developer = User::create(['name' => 'Developer', 'email' => '*****@*****.**', 'password' => bcrypt('developer')]);
     $developer->roles()->sync([$staff->id]);
     $developer->save();
 }
示例#4
0
 /**
  * Expect a user to be added to the staff role.
  */
 private function expectStaffRoleAssociation()
 {
     $this->role->expects($this->atLeastOnce())->method('mustFindByName')->with(Role::STAFF)->willReturn($this->role);
     $usersRelationship = $this->makeMock(BelongsToMany::class);
     $this->role->expects($this->atLeastOnce())->method('users')->willReturn($usersRelationship);
     $usersRelationship->expects($this->atLeastOnce())->method('save')->with($this->isInstanceOf(User::class));
 }