/**
  * Create a few entries for each of a few different exercises (no duplicates).
  * Ideally, a random number of different exercises.
  * @param $date
  */
 private function createEntriesForOneDay()
 {
     $random_exercise_ids = $this->faker->randomElements($this->exercise_ids, $count = 3);
     //Insert a few sets for each $random_exercise_id
     foreach ($random_exercise_ids as $exercise_id) {
         $this->insertExerciseSet(Exercise::find($exercise_id), $this->date);
     }
 }
 /**
  * Insert an exercise entry.
  * It can be an exercise set.
  * @param Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $exercise = Exercise::find($request->get('exercise_id'));
     if ($request->get('exerciseSet')) {
         // We are inserting an exercise set
         $quantity = $exercise->default_quantity;
         $unit = Unit::find($exercise->default_unit_id);
     } else {
         $quantity = $request->get('quantity');
         $unit = Unit::find($request->get('unit_id'));
     }
     $entry = new Entry(['date' => $request->get('date'), 'quantity' => $quantity]);
     $entry->user()->associate(Auth::user());
     $entry->exercise()->associate($exercise);
     $entry->unit()->associate($unit);
     $entry->save();
     //Return the entries for the day
     $entries = transform(createCollection($this->exerciseEntriesRepository->getEntriesForTheDay($request->get('date')), new ExerciseEntryTransformer()))['data'];
     return response($entries, Response::HTTP_CREATED);
 }
 /**
  * @test
  * @return void
  */
 public function it_can_delete_an_exercise_entry()
 {
     $this->logInUser();
     $date = Carbon::today()->format('Y-m-d');
     $entry = new Entry(['date' => $date, 'quantity' => 501]);
     $entry->user()->associate($this->user);
     $entry->exercise()->associate(Exercise::find(1));
     $entry->unit()->associate(Unit::find(1));
     $entry->save();
     $this->seeInDatabase('exercise_entries', ['date' => $date, 'exercise_id' => 1, 'quantity' => 501, 'exercise_unit_id' => 1]);
     $response = $this->call('DELETE', '/api/exerciseEntries/' . $entry->id);
     $this->assertEquals(204, $response->getStatusCode());
     $this->missingFromDatabase('exercise_entries', ['date' => $date, 'exercise_id' => 1, 'quantity' => 501, 'exercise_unit_id' => 1]);
     $response = $this->call('DELETE', '/api/exerciseEntries/' . $entry->id);
     $this->assertEquals(404, $response->getStatusCode());
 }