/**
  * @return Recipe
  */
 private function createRecipe()
 {
     $recipe = new Recipe(new Name("Screwdriver"));
     $recipe->prepareTheGlass(new Name("Highball"), new Capacity(350));
     $recipe->pourIntoGlass(new Name("Vodka"), new Capacity(150));
     return $recipe;
 }
 /**
  * @param Recipe $recipe
  * @throws RecipeNotFoundException
  */
 public function remove(Recipe $recipe)
 {
     if (!$this->hasRecipeWithName($recipe->getName())) {
         throw new RecipeNotFoundException(sprintf("Recipe \"%s\" does not exists", (string) $recipe->getName()));
     }
     $this->filesystem->remove(DIRECTORY_SEPARATOR . $this->slugGenerator->generateFrom((string) $recipe->getName()));
 }
Beispiel #3
0
 /**
  * @param Recipe $recipe
  * @return array
  * @throws RuntimeException
  * @throws \MyDrinks\Domain\Exception\Recipe\StepException
  */
 private function serializeSteps(Recipe $recipe)
 {
     $data = [];
     $steps = $recipe->getSteps();
     foreach ($steps as $step) {
         switch (get_class($step)) {
             case Step\PrepareTheGlass::class:
                 $data[] = ['type' => Actions::PREPARE_GLASS, 'name' => (string) $step->getName(), 'capacity' => $step->getCapacity()->getMilliliters(), 'amount' => $step->getAmount()->getValue()];
                 break;
             case Step\PourIntoGlass::class:
                 $data[] = ['type' => Actions::POUR_INTO_GLASS, 'name' => (string) $step->getName(), 'capacity' => $step->getCapacity()->getMilliliters()];
                 break;
             case Step\PrepareTheShaker::class:
                 $data[] = ['type' => Actions::PREPARE_SHAKER, 'capacity' => $step->getCapacity()->getMilliliters()];
                 break;
             case Step\PourIntoShaker::class:
                 $data[] = ['type' => Actions::POUR_INTO_SHAKER, 'name' => (string) $step->getName(), 'capacity' => $step->getCapacity()->getMilliliters()];
                 break;
             case Step\ShakeShakerContent::class:
                 $data[] = ['type' => Actions::SHAKE_SHAKER_CONTENT];
                 break;
             case Step\StrainIntoGlassFromShaker::class:
                 $data[] = ['type' => Actions::STRAIN_INTO_GLASS_FROM_SHAKER];
                 break;
             case Step\FillGlass::class:
                 $data[] = ['type' => Actions::FILL_GLASS, 'name' => (string) $step->getContentName()];
                 break;
             case Step\FillShaker::class:
                 $data[] = ['type' => Actions::FILL_SHAKER, 'name' => (string) $step->getContentName()];
                 break;
             case Step\AddIngredientIntoGlass::class:
                 $data[] = ['type' => Actions::ADD_INGREDIENT_INTO_GLASS, 'name' => (string) $step->getIngredientName(), 'amount' => $step->getAmount()->getValue()];
                 break;
             case Step\AddIngredientIntoShaker::class:
                 $data[] = ['type' => Actions::ADD_INGREDIENT_INTO_SHAKER, 'name' => (string) $step->getIngredientName(), 'amount' => $step->getAmount()->getValue()];
                 break;
             case Step\EmptyTheGlass::class:
                 $data[] = ['type' => Actions::EMPTY_GLASS_CONTENT];
                 break;
             case Step\TopUpGlass::class:
                 $data[] = ['type' => Actions::TOP_UP_GLASS, 'name' => (string) $step->getName()];
                 break;
             case Step\StirGlassContent::class:
                 $data[] = ['type' => Actions::STIR_GLASS_CONTENT];
                 break;
             case Step\IgniteGlassContent::class:
                 $data[] = ['type' => Actions::IGNITE_GLASS_CONTENT];
                 break;
             case Step\GarnishGlass::class:
                 $data[] = ['type' => Actions::GARNISH_GLASS, 'name' => (string) $step->getDecorationName()];
                 break;
             case Step\MuddleGlassContent::class:
                 $data[] = ['type' => Actions::MUDDLE_GLASS_CONTENT];
                 break;
             default:
                 throw new RuntimeException(sprintf("Unknown step class \"%s\"", get_class($step)));
         }
     }
     return $data;
 }
 function it_save_and_index_updated_recipes(Storage $storage, SearchEngine $searchEngine)
 {
     $recipe = new Recipe(new Name("Screwdriver"));
     $recipe->publish();
     $command = new EditCommand($recipe, new ChangeSet());
     $searchEngine->indexRecipe(Argument::any())->shouldBeCalled();
     $storage->save(Argument::type(Recipe::class))->shouldBeCalled();
     $this->handle($command);
 }
 /**
  * @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();
 }
 private function createRecipe($name)
 {
     $faker = Factory::create();
     $recipe = new Recipe(new Name($name));
     $description = new Description();
     $description->markAsIBAOfficial();
     $description->setText($faker->text(1000));
     $recipe->updateDescription($description);
     $recipe->prepareTheGlass(new Name("Highball"), new Recipe\Supply\Capacity(250));
     $recipe->addIngredientIntoGlass(new Name("Ice Cubes"), new Recipe\Supply\Amount(5));
     $recipe->pourIntoGlass(new Name("Vodka"), new Recipe\Supply\Capacity(50));
     $recipe->pourIntoGlass(new Name("Orange Juice"), new Recipe\Supply\Capacity(100));
     $recipe->garnishGlass(new Name("Orange Slice"), new Recipe\Supply\Amount(1));
     return $recipe;
 }
 public static function createFromRecipe(Recipe $recipe)
 {
     $command = new UpdateRecipeDescriptionCommand();
     $command->text = $recipe->getDescription()->getText();
     $command->IBAOfficial = $recipe->getDescription()->isOfficialIBA();
     $command->alcoholContent = $recipe->getDescription()->getAlcoholContent();
     $taste = $recipe->getDescription()->getTaste();
     if ($taste->isSweet()) {
         $command->taste[] = Tastes::SWEET;
     }
     if ($taste->isSpicy()) {
         $command->taste[] = Tastes::SPICY;
     }
     if ($taste->isBitter()) {
         $command->taste[] = Tastes::BITTER;
     }
     if ($taste->isSalty()) {
         $command->taste[] = Tastes::SALTY;
     }
     if ($taste->isSour()) {
         $command->taste[] = Tastes::SOUR;
     }
     return $command;
 }
Beispiel #8
0
 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));
 }
Beispiel #9
0
 /**
  * @param Recipe $recipe
  */
 public function remove(Recipe $recipe)
 {
     unset($this->recipes[(string) $recipe->getName()]);
 }
Beispiel #10
0
 /**
  * @param $recipe
  * @param array $data
  */
 private function deserializeTaste(DomainRecipe $recipe, array $data)
 {
     $tasteBuilder = new TasteBuilder();
     if (array_key_exists('taste', $data)) {
         foreach ($data['taste'] as $tasteName) {
             switch ($tasteName) {
                 case Tastes::SWEET:
                     $tasteBuilder->sweet();
                     break;
                 case Tastes::BITTER:
                     $tasteBuilder->bitter();
                     break;
                 case Tastes::SALTY:
                     $tasteBuilder->salty();
                     break;
                 case Tastes::SPICY:
                     $tasteBuilder->spicy();
                     break;
                 case Tastes::SOUR:
                     $tasteBuilder->sour();
                     break;
             }
         }
     }
     $recipe->getDescription()->changeTaste($tasteBuilder->buildTaste());
 }
 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);
 }
 /**
  * @param Recipe $recipe
  */
 public function removeRecipeFromIndex(Recipe $recipe)
 {
     $params = ['index' => ElasticSearch::INDEX, 'type' => 'recipe', 'id' => $this->slugGenerator->generateFrom((string) $recipe->getName())];
     $this->client->delete($params);
     $this->client->indices()->refresh();
 }