/** * @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'])); } } }
public function test_recipe_with_top_up_step() { $serializer = new JsonSerializer(); $recipe = new Recipe(new Name("Screwdriver")); $recipe->prepareTheGlass(new Name("Highball"), new Capacity(350)); $recipe->topUpGlass(new Name("Vodka")); $json = json_encode(["name" => "Screwdriver", "publicationDate" => null, "steps" => [["type" => Actions::PREPARE_GLASS, "name" => "Highball", "capacity" => 350, "amount" => 1], ["type" => Actions::TOP_UP_GLASS, "name" => "Vodka"]], "glass" => "Highball", "description" => ["text" => null, "IBAOfficial" => false, "alcoholContent" => null, "taste" => []]]); $this->assertJsonStringEqualsJsonString($json, $serializer->serialize($recipe)); $this->assertEquals($recipe, $serializer->deserialize($json, Recipe::class)); }
function it_add_top_up_glass_step_to_recipe(Recipe $recipe) { $command = new AddRecipeStepCommand(); $command->slug = 'screwdriver'; $command->name = 'vodka'; $command->type = Actions::TOP_UP_GLASS; $recipe->topUpGlass(Argument::type(Name::class))->shouldBeCalled(); $this->handle($command); }