/** * @param CreateNewRecipeCommand $command * @throws RecipeAlreadyExistsException */ public function handle(CreateNewRecipeCommand $command) { $recipe = $this->recipeFactory->createRecipe($command->name); if ($this->recipes->hasRecipeWithName($recipe->getName())) { throw new RecipeAlreadyExistsException(); } $this->recipes->add($recipe); }
function it_adds_new_recipe_into_recipes(Recipes $recipes) { $recipes->hasRecipeWithName(Argument::type(Name::class))->willReturn(false); $recipes->add(Argument::type(Recipe::class))->shouldBeCalled(); $command = new CreateNewRecipeCommand(); $command->name = "Screwdriver"; $this->handle($command); }