/** * @param Recipe $recipe */ private function prepareGlassShakerAndLiquidForShaker(Recipe $recipe) { $recipe->prepareTheGlass(new Name("Highball"), new Recipe\Supply\Capacity(250)); $recipe->prepareTheShaker(new Recipe\Supply\Capacity(250)); $recipe->pourIntoShaker(new Name("Vodka"), new Recipe\Supply\Capacity(100)); $recipe->shakeShakerContent(); $recipe->strainIntoGlassFromShaker(); }
function it_add_pour_into_glass_from_shaker_step_to_recipe(Recipe $recipe) { $command = new AddRecipeStepCommand(); $command->slug = 'screwdriver'; $command->type = Actions::STRAIN_INTO_GLASS_FROM_SHAKER; $recipe->strainIntoGlassFromShaker()->shouldBeCalled(); $this->handle($command); }
/** * @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_pouring_and_shaker_steps_serialization() { $serializer = new JsonSerializer(); $recipe = new Recipe(new Name("Screwdriver")); $recipe->prepareTheGlass(new Name("Highball"), new Capacity(350)); $recipe->pourIntoGlass(new Name("Vodka"), new Capacity(50)); $recipe->prepareTheShaker(new Capacity(350)); $recipe->pourIntoShaker(new Name("Vodka"), new Capacity(50)); $recipe->shakeShakerContent(); $recipe->strainIntoGlassFromShaker(); $json = json_encode(["name" => "Screwdriver", "publicationDate" => null, "steps" => [["type" => Actions::PREPARE_GLASS, "name" => "Highball", "capacity" => 350, "amount" => 1], ["type" => Actions::POUR_INTO_GLASS, "name" => "Vodka", "capacity" => 50], ["type" => Actions::PREPARE_SHAKER, "capacity" => 350], ["type" => Actions::POUR_INTO_SHAKER, "name" => "Vodka", "capacity" => 50], ["type" => Actions::SHAKE_SHAKER_CONTENT], ["type" => Actions::STRAIN_INTO_GLASS_FROM_SHAKER]], "glass" => "Highball", "description" => ["text" => null, "IBAOfficial" => false, "alcoholContent" => null, "taste" => []]]); $this->assertJsonStringEqualsJsonString($json, $serializer->serialize($recipe)); $this->assertEquals($recipe, $serializer->deserialize($json, Recipe::class)); }