Example #1
0
 public function test_recipe_with_adding_ingredients_steps()
 {
     $serializer = new JsonSerializer();
     $recipe = new Recipe(new Name("Screwdriver"));
     $recipe->prepareTheGlass(new Name("Highball"), new Capacity(350));
     $recipe->prepareTheShaker(new Capacity(350));
     $recipe->addIngredientIntoGlass(new Name("Ice"), new Amount(5));
     $recipe->muddleContent();
     $recipe->addIngredientIntoShaker(new Name("Ice"), new Amount(5));
     $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::ADD_INGREDIENT_INTO_GLASS, "name" => "Ice", "amount" => 5], ["type" => Actions::MUDDLE_GLASS_CONTENT], ["type" => Actions::ADD_INGREDIENT_INTO_SHAKER, "name" => "Ice", "amount" => 5]], "glass" => "Highball", "description" => ["text" => null, "IBAOfficial" => false, "alcoholContent" => null, "taste" => []]]);
     $this->assertJsonStringEqualsJsonString($json, $serializer->serialize($recipe));
     $this->assertEquals($recipe, $serializer->deserialize($json, Recipe::class));
 }
Example #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']));
         }
     }
 }
 function it_add_add_ingredient_into_shaker_step_to_recipe(Recipe $recipe)
 {
     $command = new AddRecipeStepCommand();
     $command->slug = 'screwdriver';
     $command->type = Actions::ADD_INGREDIENT_INTO_SHAKER;
     $command->name = 'ice';
     $command->amount = 5;
     $recipe->addIngredientIntoShaker(Argument::type(Name::class), Argument::type(Amount::class))->shouldBeCalled();
     $this->handle($command);
 }