/** * Prepare for the test, creating a user and entry to work with during the test. */ protected function setUp() { parent::setUp(); // Ensure that the entry was deleted in the case of a failed test. $this->beforeApplicationDestroyed(function () { $this->entry->delete(); $this->user->delete(); }); $this->user = factory(App\User::class)->create(['username' => 'test_user', 'email' => '*****@*****.**', 'password' => 'password']); $this->entry = \App\Project::create(['author' => $this->user->username, 'user_id' => $this->user->id, 'title' => 'Test Project', 'description' => 'For testing', 'body' => 'This is a simple test body']); $this->member = \App\ProjectMember::create(['user_id' => $this->user->id, 'project_id' => $this->entry->id, 'admin' => true]); $this->entry->members()->save($this->member); }
/** * Adds a member to the project * * @param boolean $admin * @param Int user_id * @return new member */ public function addMember($admin = false, $user_id = null) { if ($user_id == null) { $user_id = Auth::user()->id; } $member = ProjectMember::create(['user_id' => $user_id, 'project_id' => $this->id, 'admin' => $admin]); return $this->members()->save($member); }