/** * Test for postRequests */ public function testPostRequests() { $user1 = factory(App\Models\User::class)->create(); $user2 = factory(App\Models\User::class)->create(); $this->actingAs($user1)->post('/request', ['user_id' => $user2->id]); //getting the entry from the battle_request table to verify $br = BattleRequest::where('challenger_id', $user1->id)->first(); //comparing it with the new entry created in the battle_request table $this->assertNotNull($br); $this->assertEquals($user1->id, $br->challenger_id); }
/** * Checks whether a user has a battle request agains $user */ public function hasBattleRequestAgainst(User $user) { // possibly naive solution, other one had really ugly bugs $cnt1 = BattleRequest::where('challenger_id', $this->id)->where('challenged_id', $user->id)->count(); $cnt2 = BattleRequest::where('challenged_id', $this->id)->where('challenger_id', $user->id)->count(); return $cnt1 > 0 || $cnt2 > 0; }