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); }
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); }
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())); }