Exemplo n.º 1
0
 /**
  * Transfer local images to cloud storage.
  */
 public function transferLocalImages()
 {
     $this->imageResource->orWhere(function (Builder $query) {
         $query->where('filename', '!=', '');
         $query->whereNotNull('filename');
     })->get()->each(function (Image $image) {
         $this->dispatcher->fire(new NewImageEvent($image));
     });
 }
Exemplo n.º 2
0
 /**
  * @param Image $image
  *
  * @return ImagickCollection
  */
 public function preProcess(Image $image) : ImagickCollection
 {
     $this->imagick->readImage($image->storageLocation());
     $this->imagick->setFilename($image->filename());
     $collection = new ImagickCollection([$this->imagick]);
     foreach ($this->transformers as $transformer) {
         $transformer->applyTo($collection);
     }
     return $collection;
 }
Exemplo n.º 3
0
 /**
  * Should pre-process and transfer an image.
  */
 public function testHandle()
 {
     $filename = '/tmp/' . uniqid();
     file_put_contents($filename, '');
     $this->image->expects($this->atLeastOnce())->method('storageLocation')->willReturn($filename);
     $preProcessed = $this->makeMock(ImagickContract::class);
     $this->imagePreProcessor->expects($this->atLeastOnce())->method('preProcess')->with($this->image)->willReturn(new ImagickCollection([$preProcessed]));
     $this->config->expects($this->atLeastOnce())->method('get')->willReturn('foobar_endpoint');
     $fileContent = 'foo bar';
     $preProcessed->expects($this->atLeastOnce())->method('getImageBlob')->willReturn($fileContent);
     $this->filesystem->expects($this->atLeastOnce())->method('put')->with($this->isType('string'), $fileContent, $this->isType('array'));
     $this->newImageListener->handle($this->event);
 }
Exemplo n.º 4
0
 /**
  * @param string $filename
  *
  * @return MockInterface
  */
 private function expectImageCreation(string $filename = null) : MockInterface
 {
     if ($filename === null) {
         $filename = $this->generator()->anyInteger();
     }
     $newImage = $this->mockery(Image::class);
     $newImage->shouldReceive('getAttribute')->with('filename')->andReturn($filename);
     $newImage->shouldReceive('filename')->andReturn($filename);
     $newImage->shouldReceive('getAttribute')->with('id')->andReturn($this->generator()->anyInteger());
     $this->imageResource->shouldReceive('create')->andReturn($newImage);
     return $newImage;
 }
Exemplo n.º 5
0
 /**
  * @return Image
  */
 protected function createImage() : Image
 {
     return Image::create(['alt_text' => str_random(), 'url' => $this->faker()->slug]);
 }
Exemplo n.º 6
0
 /**
  * Should be able to get the CRUD id for the image.
  */
 public function testCrudID()
 {
     $image = new Image();
     $image->id = 123;
     $this->assertEquals($image->id, $image->crudId());
 }
Exemplo n.º 7
0
 /**
  * @param Product $product
  *
  * @return Image
  */
 protected function attachImageToProduct(Product $product) : Image
 {
     $image = Image::create(['alt_text' => str_random(), 'url' => $this->generator()->anySlug()]);
     $product->images()->attach($image->id);
     return $image;
 }
Exemplo n.º 8
0
 /**
  * @param Image $imageResource
  *
  * @return SplFileObject
  */
 private function storageImageFile(Image $imageResource) : SplFileObject
 {
     try {
         return new SplFileObject($imageResource->storageLocation());
     } catch (\RuntimeException $e) {
         return new SplTempFileObject();
     }
 }
Exemplo n.º 9
0
 /**
  * @return Generator|Image[]
  */
 private function makeImages() : Generator
 {
     for ($i = 0, $count = random_int(1, 2); $i < $count; $i++) {
         (yield Image::create(['alt_text' => $this->faker()->words(3, true), 'url' => secure_asset("/img/lorem/{$this->faker()->numberBetween(1, 5)}.jpg#" . uniqid('', true))]));
     }
 }