/** * @test */ public function TestResultsValid() { /** * we want to make sure an array is returned */ $json = new Json('./resources/recipes.json'); $this->assertEquals(is_array($json->get()), true); }
} } else { // import recipes $recipes = new Json($arguments->get(1)); if (!$recipes->count()) { $error = $recipes->hasError(); if ($error["error"]) { $message->add($error["message"]); } else { $message->add("No recipes found in file or JSON file is invalid"); } } else { // valid files now it is time to search // sort ingredients by usedby date $ingredients->sort(); foreach ($recipes->get() as $key => $recipe) { $score = 0; foreach ($recipe["ingredients"] as $recipeIngredient) { $ingredientData = $ingredients->find($recipeIngredient["item"]); if (is_array($ingredientData)) { if ($ingredientData["amount"] >= $recipeIngredient["amount"]) { $score = $score + $ingredientData["score"]; } else { // not enough ingredients for recipe, set score to -1 // mark as invalid $score = -1; break; } } else { $score = -1; }