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 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);
 }
Esempio n. 3
0
 /**
  * @return int
  */
 public function count()
 {
     return $this->filesystem->foldersCount('/');
 }
Esempio n. 4
0
 /**
  * @param $slug
  */
 public function removeImageFor($slug)
 {
     $path = $this->generateBasePath($slug);
     $filePath = $this->composeJpgFilePath($slug, $path);
     $this->filesystem->remove($filePath);
 }