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);
 }
 function it_updates_recipe_description(Recipes $recipes, ImageStorage $imageStorage, Filesystem $filesystem)
 {
     $recipes->findBySlug("screwdriver")->willReturn(new Recipe(new Name("Screwdriver")));
     $command = new UploadRecipeImageCommand();
     $command->slug = 'screwdriver';
     $command->image = new FakeFile("fake_image.jpg");
     $command->extension = 'jpg';
     $filesystem->read('fake_image.jpg')->willReturn('content');
     $imageStorage->saveImageFor(Argument::type(Image::class), "screwdriver")->shouldBeCalled();
     $this->handle($command);
 }
 /**
  * @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);
 }
 /**
  * @param UploadRecipeImageCommand $command
  * @throws RecipeNotFoundException
  * @throws RuntimeException
  */
 public function handle(UploadRecipeImageCommand $command)
 {
     $recipe = $this->recipes->findBySlug($command->slug);
     if (is_null($recipe)) {
         throw new RecipeNotFoundException();
     }
     if (!$command->image instanceof \SplFileInfo) {
         throw new RuntimeException("UploadRecipeImageHandler expected image to implement \\SplFileInfo");
     }
     $image = new Image($command->slug . '.' . $command->extension, $this->filesystem->read($command->image->getRealPath()));
     $this->imageStorage->saveImageFor($image, $command->slug);
 }
Beispiel #5
0
 /**
  * @param $slug
  * @return bool
  */
 public function getImagePath($slug)
 {
     return $this->imageUrlResolver->resolveUrlFor($this->imageStorage->getPathFor($slug));
 }