public function setUp() { $this->arrayThumbPresenter = new ArrayThumbPresenter($this->getPhotoPresenterMock()); $thumbId = new ThumbId(); $url = new HttpUrl('http://test'); $thumbSize = new PhotoThumbSize(15, 10); $this->expected = ['thumbs' => ['10x15' => ['id' => $thumbId->id(), 'url' => $url->value(), 'height' => $thumbSize->height(), 'width' => $thumbSize->width(), 'file' => '']]]; $this->thumb = new PhotoThumb($thumbId, new PhotoId(), $url, $thumbSize); $this->thumbCollection = new PhotoThumbCollection([$this->thumb]); }
/** * @param ThumbId $thumbId * @param Photo $photo * @param PhotoThumbSize $thumbSize * @param HttpUrl $thumbHttpUrl * @return PhotoThumb */ public function generate(ThumbId $thumbId, Photo $photo, PhotoThumbSize $thumbSize, HttpUrl $thumbHttpUrl) { $photoFile = $photo->photoFile() ? $photo->photoFile() : $this->downloadPhoto($photo->getPhotoHttpUrl()); $thumbFile = $this->thumbGeneratorConfig->tempPath() . '/' . $thumbId->id() . '.' . self::CONVERSION_FORMAT; $target = new Box($thumbSize->width(), $thumbSize->height()); $originalImage = $this->imagine->open($photoFile->filePath()); $img = $originalImage->thumbnail($target, ImageInterface::THUMBNAIL_OUTBOUND); $img->save($thumbFile); return new PhotoThumb($thumbId, new PhotoId($photo->id()), $thumbHttpUrl, $thumbSize, new PhotoFile($thumbFile)); }
/** * @test */ public function photoThumbWorks() { $thumbId = new ThumbId(); $photoId = new PhotoId(); $photoFile = new PhotoFile(__DIR__ . '/pixel.png'); $photoThumb = new PhotoThumb($thumbId, $photoId, new HttpUrl('http://works'), new PhotoThumbSize(10, 10), $photoFile); $this->assertEquals($thumbId->id(), $photoThumb->id()); $this->assertEquals($photoId->id(), $photoThumb->photoId()); $this->assertEquals('http://works', $photoThumb->photoThumbHttpUrl()); $this->assertEquals(10, $photoThumb->height()); $this->assertEquals(10, $photoThumb->width()); $this->assertEquals($photoFile->filePath(), __DIR__ . '/pixel.png'); $photoThumb->updatePhotoThumbFile(null); $this->assertNull($photoThumb->photoThumbFile()); }
/** * @return string */ public function id() { return $this->thumbId->id(); }