Esempio n. 1
0
 /**
  * Transfer the file to another adapter
  *
  * Note that you will receive a different file object depending on whether you're sending to a
  * local or remote file adapter. This will not be the same file object you passed in. You will
  * have 2 independent objects.
  *
  * @param MediaInterface $file The file
  * @param GaufretteAdapterInterface $adapter A gaufrette adapter
  * @param string $key File key (name) used in place of the file being transferred. Useful for overriding the default
  * @return LocalFileInterface|RemoteFileInterface The file object returned depends on the type of gaufrette adapter you're transferring to.
  * @throws UnknownTransferAdapterException When adapter is not a local or remote adapter
  */
 public function transfer(MediaInterface $file, GaufretteAdapterInterface $adapter, $key = null)
 {
     if ($adapter instanceof LocalFileAdapterInterface) {
         $local = new LocalFile($key ?: $file->getKey(), $adapter);
         $local->write($file->read());
         $local = $this->convertFile($local);
         return $local;
     } elseif ($adapter instanceof RemoteFileAdapterInterface) {
         $remote = new RemoteFile($key ?: $file->getKey(), $adapter);
         $remote->write($file->read());
         return $remote;
     } else {
         throw new UnknownTransferAdapterException('Adapter must be a local or remote file adapter to transfer to.');
     }
 }
Esempio n. 2
0
 public function testWriteUnsuccessful()
 {
     $key = 'Foo';
     $adapter = Mockery::mock(self::$fileAdapterInterface);
     $data = 'lorem ipsum';
     $sut = new RemoteFile($key, $adapter);
     $adapter->shouldReceive('write')->with($key, $data)->andReturn(false);
     $this->assertFalse($sut->write($data));
 }