function it_duplicates_product_media($filesystem, ProductMediaInterface $source, ProductMediaInterface $target, File $newFile)
 {
     $target->setFile(Argument::any())->shouldBeCalled();
     $source->getOriginalFilename()->willReturn('akeneo.jpg');
     $target->getOriginalFilename()->willReturn('akeneo.jpg');
     // upload
     $target->getFile()->willReturn($newFile);
     $newFile->getPathname()->willReturn('/tmp/tmp-phpspec');
     // write a fake file in tmp
     $adapter = new LocalAdapter('/tmp');
     $fs = new Filesystem($adapter);
     $fs->write('tmp-phpspec', '', true);
     $source->getFilename()->willReturn('akeneo.jpg');
     $newFile->getFilename()->willReturn('akeneo.jpg');
     $filesystem->write('prefix-akeneo.jpg', '', false)->shouldBeCalled();
     $target->setOriginalFilename('akeneo.jpg')->shouldBeCalled();
     $target->setFilename('prefix-akeneo.jpg')->shouldBeCalled();
     $filesystem->has('akeneo.jpg')->willReturn(true);
     $target->getFilename()->willReturn('akeneo.jpg');
     $newFile->getMimeType()->willReturn('jpg');
     $target->setMimeType('jpg')->shouldBeCalled();
     // update original file name
     $source->getOriginalFilename()->willReturn('akeneo.jpg');
     $target->setOriginalFilename('akeneo.jpg')->shouldBeCalled();
     $this->duplicate($source, $target, 'prefix');
 }
예제 #2
0
 /**
  * Delete a file
  *
  * @param ProductMediaInterface $media
  */
 protected function delete(ProductMediaInterface $media)
 {
     $media->setOriginalFilename(null);
     $media->setFilename(null);
     $media->setMimeType(null);
 }