Ejemplo n.º 1
0
 public function upload(ImageInterface $image)
 {
     if (!$image->hasFile()) {
         return;
     }
     if (null !== $image->getPath()) {
         $this->remove($image->getPath());
     }
     do {
         $hash = md5(uniqid(mt_rand(), true));
         $path = $this->expandPath($hash . '.' . $image->getFile()->guessExtension());
     } while ($this->filesystem->has($path));
     $image->setPath($path);
     $this->filesystem->write($image->getPath(), file_get_contents($image->getFile()->getPathname()));
 }
Ejemplo n.º 2
0
 function it_uses_image_uploader_to_upload_images(GenericEvent $event, ImageAwareInterface $subject, ImageInterface $image, ImageUploaderInterface $uploader)
 {
     $event->getSubject()->willReturn($subject);
     $subject->getImages()->willReturn([$image]);
     $image->hasFile()->willReturn(true);
     $image->getPath()->willReturn('some_path');
     $uploader->upload($image)->shouldBeCalled();
     $this->uploadImage($event);
 }
Ejemplo n.º 3
0
 function it_uses_image_uploader_to_upload_images_for_simple_product(GenericEvent $event, ProductInterface $product, ProductVariantInterface $variant, ImageInterface $image, ImageUploaderInterface $uploader, VariantResolverInterface $variantResolver)
 {
     $event->getSubject()->willReturn($product);
     $product->isSimple()->willReturn(true);
     $variantResolver->getVariant($product)->willReturn($variant);
     $variant->getImages()->willReturn([$image]);
     $image->hasFile()->willReturn(true);
     $image->getPath()->willReturn('some_path');
     $uploader->upload($image)->shouldBeCalled();
     $this->uploadProductImage($event);
 }