function it_returns_an_image_by_code(ImageInterface $image) { $image->getCode()->willReturn('thumbnail'); $image->setOwner($this)->shouldBeCalled(); $this->addImage($image); $this->getImageByCode('thumbnail')->shouldReturn($image); }
function let(Filesystem $filesystem, ImageInterface $image) { $filesystem->has(Argument::any())->willReturn(false); $file = new File(__FILE__, 'img.jpg'); $image->getFile()->willReturn($file); $this->beConstructedWith($filesystem); }
function it_does_not_add_violation_if_there_is_no_duplication_of_a_code(ImageInterface $firstImage, ImageInterface $secondImage) { $firstImage->getCode()->willReturn('car'); $secondImage->getCode()->willReturn('wipers'); $this->addViolationAt('[0].code', Argument::type('string'))->shouldNotBeCalled(); $this->addViolationAt('[1].code', Argument::type('string'))->shouldNotBeCalled(); $this->validate(new ArrayCollection($firstImage->getWrappedObject(), $secondImage->getWrappedObject()), new ImageUniqueCode()); }
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())); }
/** * {@inheritdoc} */ public function addImage(ImageInterface $image) { $image->setOwner($this); $this->images->add($image); }