Пример #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);
 }
Пример #2
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));
 }
 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;
 }