/** * @param RemoveRecipeImageCommand $command * @throws RecipeImageNotFoundException * @throws RecipeNotFoundException */ public function handle(RemoveRecipeImageCommand $command) { $recipe = $this->recipes->findBySlug($command->slug); if (is_null($recipe)) { throw new RecipeNotFoundException(); } if (!$this->imageStorage->hasImageFor($command->slug)) { throw new RecipeImageNotFoundException(); } $this->imageStorage->removeImageFor($command->slug); }
function it_updates_recipe_description(Recipes $recipes, ImageStorage $imageStorage) { $recipes->findBySlug("screwdriver")->willReturn($this->createRecipe()); $command = new RemoveRecipeImageCommand(); $command->slug = 'screwdriver'; $imageStorage->hasImageFor("screwdriver")->willReturn(true); $imageStorage->removeImageFor("screwdriver")->shouldBeCalled(); $this->handle($command); }
/** * @param $slug * @return bool */ public function hasImage($slug) { return $this->imageStorage->hasImageFor($slug); }