예제 #1
0
 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);
 }
예제 #2
0
 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());
 }
예제 #4
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);
 }
 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);
 }
예제 #6
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()));
 }
예제 #7
0
파일: Product.php 프로젝트: loic425/Sylius
 /**
  * {@inheritdoc}
  */
 public function addImage(ImageInterface $image)
 {
     $image->setOwner($this);
     $this->images->add($image);
 }