/**
  * @test
  */
 public function TestAddHelpIsOnlyAddedOnce()
 {
     /**
      * test to make sure addHelp text is only added once to a message
      */
     $message = new Messages();
     $message->addHelp();
     // add once
     $countAfterFirst = count($message->get());
     $message->addHelp();
     // add twice
     $countAfterSecond = count($message->get());
     // first and second count should be exactly the same
     $this->assertEquals($countAfterFirst, $countAfterSecond);
 }
示例#2
0
                    $recipes->setScore($key, $score);
                }
                // we now have a score value for each recipe based on ingredients expiry
                // order the recipes by order
                $recipes->sort();
                // filter out all invalid recipes
                $results = $recipes->filter();
                // check to make sure there is a recipe
                //the top result is the best recipe based on the ingredients expiry
                if (count($results)) {
                    $result = array_shift($results);
                    $message->add("The best recipe for you to make is : " . $result["name"])->add("You need the following ingredients:");
                    foreach ($result["ingredients"] as $ingredient) {
                        $message->add(" - " . $ingredient["amount"] . " " . $ingredient["unit"] . " of " . $ingredient["item"]);
                    }
                    // add a blank line
                    $message->add("");
                } else {
                    // order takeout
                    $message->add("All ingredients are past their used by date, Order Takeout!");
                }
            }
        }
    } else {
        // invalid number of arguments passed
        $message->add("Invalid number of arguments", true);
    }
} else {
    $message->addHelp();
}
echo $message->__toString();