예제 #1
0
 public function testSetGetRecipeIngredients()
 {
     $ingredient = new Ingredient();
     $ingredient->setName('water')->setQty('100')->setUnit('litres');
     $recipe = new Recipe();
     $recipe->addIngredient($ingredient);
     $this->assertEquals($recipe->getIngredients()->first()->getName(), 'water');
     $this->assertEquals($recipe->getIngredients()->first()->getUnit(), 'litres');
     $this->assertEquals($recipe->getIngredients()->first()->getQty(), '100');
 }
예제 #2
0
 /**
  * Return all recipes found in the datasource
  * @return Collection collection of recipe objects
  */
 public function getAll()
 {
     $recipes = new Collection();
     foreach ($this->json_recipes as $name => $recipe_ingredients) {
         // Not interested in just names
         if (!is_array($recipe_ingredients)) {
             continue;
         }
         $recipe = new Recipe();
         $ingredients_json = $recipe_ingredients['ingredients'];
         $recipe->setName($recipe_ingredients['name']);
         foreach ($ingredients_json as $ingredient_json) {
             $ingredient = new Ingredient();
             $ingredient->setName($ingredient_json['item'])->setQty($ingredient_json['amount'])->setUnit($ingredient_json['unit']);
             $recipe->addIngredient($ingredient);
         }
         $recipes->push($recipe);
     }
     return $recipes;
 }