public function testNutrients()
 {
     $protein = Nutrient::Protein();
     $carbohydrates = Nutrient::Carbohydrates();
     $fat = Nutrient::Fat();
     // Test units, ID, and all foods with protein
     $this->assertEquals("g", $protein->getUnits());
     $this->assertEquals("203", $protein->getID());
     $this->assertEquals("6607", count($protein->getFoods()));
     // Test units, ID, and all foods with carbs
     $this->assertEquals("g", $carbohydrates->getUnits());
     $this->assertEquals("205", $carbohydrates->getID());
     $this->assertEquals("5940", count($carbohydrates->getFoods()));
     // Test units, ID, and all foods with fat
     $this->assertEquals("g", $fat->getUnits());
     $this->assertEquals("204", $fat->getID());
     $this->assertEquals("6595", count($fat->getFoods()));
 }
예제 #2
0
 public function getFat()
 {
     $nutrient = $this->nutrients()->whereNutrientId(Nutrient::Fat()->getID())->first();
     return $nutrient != null ? $nutrient->pivot->amount_in_food : 0;
 }