public function testAverageFillupConsumptionCalculation()
 {
     $averageUser = $this->getTestUser();
     $vehicle = Vehicle::firstOrCreate(['user_id' => $averageUser->id, 'registration' => 'ASD-567']);
     $fillupsData = $this->getFillupData($vehicle->id);
     $fillups = [];
     foreach ($fillupsData as $fillupData) {
         array_push($fillups, Fillup::firstOrCreate($fillupData));
     }
     $this->assertEquals(0, AverageConsumptionService::getFillupConsumption($fillups[0]->id));
     $this->assertEquals(60 / ((1500 - 1000) / 100), AverageConsumptionService::getFillupConsumption($fillups[1]->id));
     $this->assertEquals(70 / ((2000 - 1500) / 100), AverageConsumptionService::getFillupConsumption($fillups[2]->id));
 }
Esempio n. 2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $vehicleId
  * @param  int $fillupId
  * @return Response
  */
 public function destroy($vehicleId, $fillupId)
 {
     try {
         $fillup = Fillup::findOrFail($fillupId);
         $fillup->delete();
         return response("", 204);
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
 }