/** @test */ public function it_gets_all_statuses_for_user() { // Given I have two users $users = Factory::times(2)->create(User::class); // And statuses fro both of them Factory::times(2)->create(Status::class, ['user_id' => $users[0]->id, 'body' => 'First user\'s status']); Factory::times(2)->create(Status::class, ['user_id' => $users[1]->id, 'body' => 'Second user\'s status']); // When I fetch statuses for one user $statusesForUser = $this->repo->getAllForUser($users[0]); // Then I should receive the relevant ones $this->assertCount(2, $statusesForUser); $this->assertEquals('First user\'s status', $statusesForUser[0]->body); $this->assertEquals('First user\'s status', $statusesForUser[1]->body); }
/** * Display a listing of the resource. * * @return Response */ public function index(StatusRepository $repository) { $statuses = $repository->getAllForUser(Auth::user()); return view('statuses.index', compact('statuses')); }