コード例 #1
0
 /**
  *  Test file upload when filename contains directories
  * @dataProvider filenameWithDirectoriesDataProvider
  */
 public function testFilenameWithDirectoriesIsUploadedToCorrectDirectory($dir, $filename, $expectedDir, $expectedFileName)
 {
     $obj = new DummyEntity();
     $file = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\File\\UploadedFile')->disableOriginalConstructor()->getMock();
     $prop = $this->getMockBuilder('\\ReflectionProperty')->disableOriginalConstructor()->getMock();
     $name = new \stdClass();
     $namer = $this->getMockBuilder('Vich\\UploaderBundle\\Naming\\NamerInterface')->disableOriginalConstructor()->getMock();
     $namer->expects($this->once())->method('name')->with($obj, $name)->will($this->returnValue($filename));
     $prop->expects($this->any())->method('getName')->will($this->returnValue($name));
     $mapping = $this->getMock('Vich\\UploaderBundle\\Mapping\\PropertyMapping');
     $mapping->expects($this->once())->method('getNamer')->will($this->returnValue($namer));
     $mapping->expects($this->any())->method('getProperty')->will($this->returnValue($prop));
     $mapping->expects($this->once())->method('getFileNameProperty')->will($this->returnValue($prop));
     $mapping->expects($this->once())->method('getPropertyValue')->with($obj)->will($this->returnValue($file));
     $mapping->expects($this->once())->method('getDeleteOnUpdate')->will($this->returnValue(false));
     $mapping->expects($this->once())->method('hasNamer')->will($this->returnValue(true));
     $mapping->expects($this->once())->method('getUploadDir')->with($obj, $name)->will($this->returnValue($dir));
     $this->factory->expects($this->once())->method('fromObject')->with($obj)->will($this->returnValue(array($mapping)));
     $file->expects($this->once())->method('move')->with($expectedDir, $expectedFileName);
     $storage = new FileSystemStorage($this->factory);
     $storage->upload($obj);
 }
コード例 #2
0
 /**
  * Test the resolve path method throws exception
  * when an invaid field name is specified.
  *
  * @expectedException \InvalidArgumentException
  */
 public function testResolvePathThrowsExceptionOnInvalidFieldName()
 {
     $obj = new DummyEntity();
     $this->factory->expects($this->once())->method('fromField')->with($obj, 'oops')->will($this->returnValue(null));
     $storage = new FileSystemStorage($this->factory);
     $storage->resolvePath($obj, 'oops');
 }
コード例 #3
0
 /**
  * Gets filepath
  *
  * @param Image $image
  *
  * @return string|null
  */
 protected function getFilepath(Image $image)
 {
     $path = $this->storage->resolvePath($image, 'file');
     return $path ? 'gaufrette://' . $path : null;
 }