예제 #1
0
 /**
  * @param DomainRecipe $recipe
  * @param array $data
  * @throws \MyDrinks\Domain\Exception\InvalidArgumentException
  * @internal param Recipe $recipe
  */
 private function deserializeDescription(DomainRecipe $recipe, array $data)
 {
     $description = new DomainRecipe\Description();
     if (isset($data['description']['IBAOfficial']) && $data['description']['IBAOfficial'] === true) {
         $description->markAsIBAOfficial();
     }
     if (isset($data['description']['text']) && !empty($data['description']['text'])) {
         $description->setText($data['description']['text']);
     }
     if (isset($data['description']['alcoholContent'])) {
         $description->setAlcoholContent((int) $data['description']['alcoholContent']);
     }
     $recipe->updateDescription($description);
 }
 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;
 }
예제 #3
0
 public function test_recipe_with_description_serialization()
 {
     $serializer = new JsonSerializer();
     $recipe = new Recipe(new Name("Screwdriver"));
     $description = new Description();
     $description->setText("Lorem ipsum");
     $description->markAsIBAOfficial();
     $description->setAlcoholContent(25);
     $taste = (new TasteBuilder())->sour()->spicy()->buildTaste();
     $description->changeTaste($taste);
     $recipe->updateDescription($description);
     $json = json_encode(["name" => "Screwdriver", "publicationDate" => null, "steps" => [], "glass" => null, "description" => ["text" => "Lorem ipsum", "IBAOfficial" => true, "alcoholContent" => 25, "taste" => [Tastes::SOUR, Tastes::SPICY]]]);
     $this->assertJsonStringEqualsJsonString($json, $serializer->serialize($recipe));
     $this->assertEquals($recipe, $serializer->deserialize($json, Recipe::class));
 }
 /**
  * @param UpdateRecipeDescriptionCommand $command
  * @throws RecipeNotFoundException
  * @throws \MyDrinks\Domain\Exception\InvalidArgumentException
  */
 public function handle(UpdateRecipeDescriptionCommand $command)
 {
     $recipe = $this->recipes->findBySlug($command->slug);
     if (is_null($recipe)) {
         throw new RecipeNotFoundException();
     }
     $description = new Description();
     if ((bool) $command->IBAOfficial) {
         $description->markAsIBAOfficial();
     }
     if (strlen($command->text)) {
         $description->setText($command->text);
     }
     if (!is_null($command->alcoholContent)) {
         $description->setAlcoholContent($command->alcoholContent);
     }
     if (!empty($command->taste) && is_array($command->taste)) {
         $tasteBuilder = new TasteBuilder();
         foreach ($command->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;
             }
         }
         $description->changeTaste($tasteBuilder->buildTaste());
     }
     $recipe->updateDescription($description);
 }