/** * @param PhotoThumb $thumb * @param Photo $photo * @return null|PhotoFile */ public function uploadThumb(PhotoThumb $thumb, Photo $photo) { $destinyPath = $this->localStorageConfig->storagePath() . '/' . $this->getMd5Path($photo->resourceId()) . '/' . $photo->id(); $this->createPathIfNotExists($destinyPath); $newPhotoFilePath = sprintf('%s/%s_%dx%d.%s', $destinyPath, $photo->slug(), $thumb->width(), $thumb->height(), $thumb->photoThumbFile()->format()); copy($thumb->photoThumbFile()->filePath(), $newPhotoFilePath); return new PhotoFile($newPhotoFilePath); }
/** * @test */ public function uploadAndDeleteOnePhotoWorks() { $photoId = new PhotoId(); $resourceId = new ResourceId('test'); $photoName = new PhotoName('test'); $photoFile = new PhotoFile(__DIR__ . '/photo_to_upload.png'); $altCollection = new PhotoAltCollection(); $this->storage->upload(new Photo($photoId, $resourceId, $photoName, $this->storage->getPhotoHttpUrlBy($photoId, $resourceId, $photoName, $photoFile), $altCollection, new Position(), $photoFile)); $uploadedPhoto = $this->config->storagePath() . '/' . $this->getMd5Path($resourceId->id()) . '/' . $photoId->id() . '/' . $photoName->slug() . '.' . $photoFile->format(); $this->assertTrue(file_exists($uploadedPhoto)); $this->assertTrue($this->storage->remove(new Photo($photoId, $resourceId, $photoName, $this->storage->getPhotoHttpUrlBy($photoId, $resourceId, $photoName, $photoFile), $altCollection, new Position(), new PhotoFile($uploadedPhoto)))); }