protected function setUp()
 {
     $this->filesystemMap = $this->getMockBuilder('Knp\\Bundle\\GaufretteBundle\\FilesystemMap')->disableOriginalConstructor()->getMock();
     $this->filesystem = $this->getMockBuilder('Gaufrette\\Filesystem')->setMethods(['get'])->disableOriginalConstructor()->getMock();
     $this->filesystemMap->expects($this->once())->method('get')->with('attachments')->will($this->returnValue($this->filesystem));
     $this->factory = new Factory();
     $this->emailAttachmentTransformer = new EmailAttachmentTransformer($this->filesystemMap, $this->factory);
 }
 /**
  * Test that FileNotFound exception is catched
  */
 public function testRemoveNotFoundFile()
 {
     $mapping = $this->getMock('Vich\\UploaderBundle\\Mapping\\PropertyMapping');
     $obj = new DummyEntity();
     $prop = $this->getMockBuilder('\\ReflectionProperty')->disableOriginalConstructor()->getMock();
     $prop->expects($this->any())->method('getValue')->with($obj)->will($this->returnValue('file.txt'));
     $prop->expects($this->any())->method('getName')->will($this->returnValue('nameProperty'));
     $mapping->expects($this->once())->method('getDeleteOnRemove')->will($this->returnValue(true));
     $mapping->expects($this->any())->method('getUploadDir')->will($this->returnValue('filesystemKey'));
     $mapping->expects($this->once())->method('getFileNameProperty')->will($this->returnValue($prop));
     $mapping->expects($this->once())->method('getProperty')->will($this->returnValue($prop));
     $filesystem = $this->getFilesystemMock();
     $filesystem->expects($this->once())->method('delete')->with('file.txt')->will($this->throwException(new FileNotFound('File Not Found')));
     $this->filesystemMap->expects($this->once())->method('get')->with('filesystemKey')->will($this->returnValue($filesystem));
     $this->factory->expects($this->once())->method('fromObject')->with($obj)->will($this->returnValue(array($mapping)));
     $storage = new GaufretteStorage($this->factory, $this->filesystemMap);
     $storage->remove($obj, 'file');
 }
Пример #3
0
 public function testUploadDoesNotSetMetadataWhenUsingNonMetadataSupporterAdapter()
 {
     $adapter = $this->getMockBuilder('\\Gaufrette\\Adapter\\Apc')->disableOriginalConstructor()->getMock();
     $file = $this->getUploadedFileMock();
     $file->expects($this->once())->method('getClientOriginalName')->will($this->returnValue('filename'));
     $file->expects($this->once())->method('getPathname')->will($this->returnValue($this->getValidUploadDir() . DIRECTORY_SEPARATOR . 'test.txt'));
     $this->mapping->expects($this->once())->method('getFile')->will($this->returnValue($file));
     $this->mapping->expects($this->once())->method('getUploadDestination')->will($this->returnValue('filesystemKey'));
     $filesystem = $this->getFilesystemMock();
     $imb = $this->getMockBuilder('\\Gaufrette\\Stream\\InMemoryBuffer')->disableOriginalConstructor()->setMethods(array('open', 'write', 'close'))->getMock();
     $imb->expects($this->once())->method('open')->will($this->returnValue(true));
     $imb->expects($this->once())->method('write')->will($this->returnValue(true));
     $imb->expects($this->once())->method('close')->will($this->returnValue(true));
     $filesystem->expects($this->once())->method('createStream')->will($this->returnValue($imb));
     $this->filesystemMap->expects($this->once())->method('get')->with('filesystemKey')->will($this->returnValue($filesystem));
     $adapter->expects($this->never())->method('setMetadata')->will($this->returnValue(null));
     $filesystem->expects($this->any())->method('getAdapter')->will($this->returnValue($adapter));
     $this->storage->upload($this->object, $this->mapping);
 }