Exemplo n.º 1
0
 public function testSetGetIngredient()
 {
     $ingredient = new Ingredient();
     $ingredient->setName('water')->setQty('100')->setUnit('litres')->setUsedByDate(NULL);
     $this->assertEquals($ingredient->getName(), 'water');
     $this->assertEquals($ingredient->getUnit(), 'litres');
     $this->assertEquals($ingredient->getUsedByDate(), NULL);
 }
 /**
  * Check if an ingredient is in the fridge or not.
  *
  * @param  Ingredient $contestant [description]
  * @return boolean                return TRUE if in the fridge or FALSE if not
  */
 public function isSatisfiedBy($contestant)
 {
     if ($this->ingredient_repository->findByName($contestant->getName())) {
         return TRUE;
     }
     $this->addMessage('INGREDIENTS', 'Ingredient required for the recipe is not in the fridge.');
     return FALSE;
 }
 /**
  * Check if the recipe ingredient qty is available in the
  * ridge or not.
  *
  * @param  Ingredient $contestant [description]
  * @return boolean                return TRUE if qty can be met, FALSE if not
  */
 public function isSatisfiedBy($contestant)
 {
     $qty_available = 0;
     if ($this->usable_ingredients->count()) {
         if ($this->usable_ingredients->get($contestant->getName())) {
             $qty_available = $this->usable_ingredients->get($contestant->getName())->getQty();
         }
     }
     if ($contestant->getQty() <= $qty_available) {
         return TRUE;
     }
     $this->addMessage('INGREDIENTS', 'Required amount of ingredients is not available in the fridge.');
     return FALSE;
 }
 /**
  * Return an array of ingredients based on CSV dataset passed in
  * @param  Array $csv_rows array of CSV row data
  * @return Collection      array of ingredient objects
  */
 private static function getIngredientCollection($csv_rows)
 {
     $ingredients = new Collection();
     foreach ($csv_rows as $row) {
         // Ignore whitespace/eof chars
         if (empty(trim($row[0]))) {
             continue;
         }
         $ingredient = new Ingredient();
         $ingredient->setName($row[0])->setQty($row[1])->setUnit($row[2])->setUsedByDate(self::parseCSVDateFormat($row[3]));
         $ingredients->put($ingredient->getName(), $ingredient);
     }
     return $ingredients;
 }