Пример #1
0
 public function test_recipe_with_filling_steps()
 {
     $serializer = new JsonSerializer();
     $recipe = new Recipe(new Name("Screwdriver"));
     $recipe->prepareTheGlass(new Name("Highball"), new Capacity(350));
     $recipe->prepareTheShaker(new Capacity(350));
     $recipe->fillGlassWith(new Name("Ice"));
     $recipe->fillShakerWith(new Name("Ice"));
     $json = json_encode(["name" => "Screwdriver", "publicationDate" => null, "steps" => [["type" => Actions::PREPARE_GLASS, "name" => "Highball", "capacity" => 350, "amount" => 1], ["type" => Actions::PREPARE_SHAKER, "capacity" => 350], ["type" => Actions::FILL_GLASS, "name" => "Ice"], ["type" => Actions::FILL_SHAKER, "name" => "Ice"]], "glass" => "Highball", "description" => ["text" => null, "IBAOfficial" => false, "alcoholContent" => null, "taste" => []]]);
     $this->assertJsonStringEqualsJsonString($json, $serializer->serialize($recipe));
     $this->assertEquals($recipe, $serializer->deserialize($json, Recipe::class));
 }
Пример #2
0
 /**
  * @param DomainRecipe $recipe
  * @param array $data
  * @throws RuntimeException
  * @throws \MyDrinks\Domain\Exception\Recipe\GlassCapacityOverflowException
  * @throws \MyDrinks\Domain\Exception\Recipe\MissingGlassException
  */
 private function deserializeSteps(DomainRecipe $recipe, array $data)
 {
     foreach ($data['steps'] as $step) {
         switch ($step['type']) {
             case Actions::PREPARE_GLASS:
                 $recipe->prepareTheGlass(new Name($step['name']), new Capacity($step['capacity']), new Amount($step['amount']));
                 break;
             case Actions::POUR_INTO_GLASS:
                 $recipe->pourIntoGlass(new Name($step['name']), new Capacity($step['capacity']));
                 break;
             case Actions::STRAIN_INTO_GLASS_FROM_SHAKER:
                 $recipe->strainIntoGlassFromShaker();
                 break;
             case Actions::ADD_INGREDIENT_INTO_GLASS:
                 $recipe->addIngredientIntoGlass(new Name($step['name']), new Amount($step['amount']));
                 break;
             case Actions::STIR_GLASS_CONTENT:
                 $recipe->stirGlassContent();
                 break;
             case Actions::FILL_GLASS:
                 $recipe->fillGlassWith(new Name($step['name']));
                 break;
             case Actions::IGNITE_GLASS_CONTENT:
                 $recipe->igniteGlassContent();
                 break;
             case Actions::GARNISH_GLASS:
                 $recipe->garnishGlass(new Name($step['name']));
                 break;
             case Actions::EMPTY_GLASS_CONTENT:
                 $recipe->emptyTheGlass();
                 break;
             case Actions::MUDDLE_GLASS_CONTENT:
                 $recipe->muddleContent();
                 break;
             case Actions::TOP_UP_GLASS:
                 $recipe->topUpGlass(new Name($step['name']));
                 break;
             case Actions::PREPARE_SHAKER:
                 $recipe->prepareTheShaker(new Capacity($step['capacity']));
                 break;
             case Actions::POUR_INTO_SHAKER:
                 $recipe->pourIntoShaker(new Name($step['name']), new Capacity($step['capacity']));
                 break;
             case Actions::SHAKE_SHAKER_CONTENT:
                 $recipe->shakeShakerContent();
                 break;
             case Actions::FILL_SHAKER:
                 $recipe->fillShakerWith(new Name($step['name']));
                 break;
             case Actions::ADD_INGREDIENT_INTO_SHAKER:
                 $recipe->addIngredientIntoShaker(new Name($step['name']), new Amount($step['amount']));
                 break;
             default:
                 throw new RuntimeException(sprintf("Unknown step type \"%s\"", $step['type']));
         }
     }
 }
Пример #3
0
 function it_add_fill_glass_with_step_to_recipe(Recipe $recipe)
 {
     $command = new AddRecipeStepCommand();
     $command->slug = 'screwdriver';
     $command->type = Actions::FILL_GLASS;
     $command->name = "ice";
     $recipe->fillGlassWith(Argument::type(Name::class))->shouldBeCalled();
     $this->handle($command);
 }