예제 #1
0
파일: FinderTest.php 프로젝트: y2khjh/test1
 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
파일: FridgeTest.php 프로젝트: y2khjh/test1
 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
파일: Main.php 프로젝트: y2khjh/test1
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";
}