/** * 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([]); }
/** * 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(); }
/** * @return User */ private function fetchLatestUser() : User { $latestUserResource = User::with('roles')->orderBy('updated_at', 'desc')->first(); return $latestUserResource ? $latestUserResource : new User(); }
/** * Should use roles to determine if user is staff. */ public function testIsStaff() { $this->user->setAttribute('roles', []); $this->assertFalse($this->user->isStaff()); }
/** * @return Collection|User[] */ private function staffUsers() : Collection { return $this->userResource->whereHas('roles', function (Builder $roles) { $roles->where('name', '=', Role::STAFF); })->get() ?? new Collection(); }
/** * Create a new user instance after a valid registration. * * @param array $data * * @return User */ protected function create(array $data) { return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); }