Пример #1
0
 private function getFridge()
 {
     $fridgeItems = array(0 => array(0 => 'bread', 1 => '10', 2 => 'slices', 3 => date_format(new DateTime('+365 days'), 'd/m/Y')), 1 => array(0 => 'cheese', 1 => '10', 2 => 'slices', 3 => date_format(new DateTime('+365 days'), 'd/m/Y')), 2 => array(0 => 'butter', 1 => '250', 2 => 'grams', 3 => date_format(new DateTime('+365 days'), 'd/m/Y')), 3 => array(0 => 'peanut butter', 1 => '250', 2 => 'grams', 3 => date_format(new DateTime('+180 days'), 'd/m/Y')), 4 => array(0 => 'mixed salad', 1 => '500', 2 => 'grams', 3 => date_format(new DateTime('-10 days'), 'd/m/Y')));
     $fridge = new Fridge();
     foreach ($fridgeItems as $item) {
         $fridge->put(new Ingredient($item[0], $item[1], $item[2], date_create_from_format('d/m/Y', $item[3])));
     }
     return $fridge;
 }
Пример #2
0
 public function testFillFromArrayFunction()
 {
     $testData = array(0 => array(0 => 'bread', 1 => '10', 2 => 'slices', 3 => date_format(new DateTime('+365 days'), 'd/m/Y')), 1 => array(0 => 'cheese', 1 => '10', 2 => 'slices', 3 => date_format(new DateTime('+365 days'), 'd/m/Y')));
     $fridge = new Fridge();
     $fridge->fillFromArray($testData);
     $items = $fridge->getItems();
     $this->assertEquals($items[0]->getItem(), $testData[0][0]);
     $this->assertEquals($items[1]->getItem(), $testData[1][0]);
     $this->assertEquals(sizeof($items), 2);
 }
Пример #3
0
function main()
{
    $fridge_csv_path = isset($argv[1]) ? $argv[1] : 'fridge.csv';
    $recipe_json_path = isset($argv[2]) ? $argv[2] : 'recipes.js';
    $ingredients = array_map('str_getcsv', file($fridge_csv_path));
    $recipes = json_decode(file_get_contents($recipe_json_path), 1);
    $fridge = new Fridge();
    $fridge->fillFromArray($ingredients);
    $finder = new Finder($fridge);
    $recipeToday = $finder->findRecipe($recipes);
    echo $recipeToday . "\n";
}