public function testNameReturnsAnUniqueName()
 {
     $file = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\File\\File')->disableOriginalConstructor()->getMock();
     $file->expects($this->any())->method('guessExtension')->will($this->returnValue('jpeg'));
     $entity = new DummyEntity();
     $entity->setFile($file);
     $namer = new UniqidNamer();
     $this->assertRegExp('/[a-z0-9]{13}.jpeg/', $namer->name($entity, 'file'));
 }
示例#2
0
 /**
  * @dataProvider fileDataProvider
  */
 public function testNameReturnsAnUniqueName($originalName, $guessedExtension, $pattern)
 {
     $file = $this->getUploadedFileMock();
     $file->expects($this->any())->method('getClientOriginalName')->will($this->returnValue($originalName));
     $file->expects($this->any())->method('guessExtension')->will($this->returnValue($guessedExtension));
     $entity = new \DateTime();
     $mapping = $this->getMockBuilder('Vich\\UploaderBundle\\Mapping\\PropertyMapping')->disableOriginalConstructor()->getMock();
     $mapping->expects($this->once())->method('getFile')->with($entity)->will($this->returnValue($file));
     $namer = new UniqidNamer();
     $this->assertRegExp($pattern, $namer->name($entity, $mapping));
 }
 /**
  * Construit le nom du fichier à partir de l'objet
  * @param  [type]          $object  [description]
  * @param  PropertyMapping $mapping [description]
  * @return [type]                   [description]
  */
 public function name($object, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     $extension = $this->getExtension($file);
     $name = uniqid();
     if (is_null($object->getId())) {
         $name = parent::name($object, $mapping);
     } elseif (!is_null($extension)) {
         $name = $object->getId() . '.' . $extension;
     }
     return $name;
 }
示例#4
0
 /**
  * Creates a name for the file being uploaded.
  *
  * @param object $object The object the upload is attached to.
  * @param PropertyMapping $mapping The mapping to use to manipulate the given object.
  *
  * @return string The file name.
  */
 public function name($object, PropertyMapping $mapping)
 {
     $namer = new UniqidNamer();
     return $namer->name($object, $mapping);
     // TODO: Implement name() method.
 }