public function writeStream($path, $resource) { try { return $this->filesystem->writeStream($path, $resource); } catch (FileExistsException $exception) { return $this->filesystem->updateStream($path, $resource); } }
/** * 1.txt * 2.txt. */ public function testUpdateStream() { $stream = tmpfile(); fwrite($stream, 'OSS text2'); rewind($stream); $this->assertTrue($this->filesystem->updateStream('2.txt', $stream)); fclose($stream); }
function it_should_successfully_update_stream($path, Filesystem $filesystem) { $filesystem->writeStream($path, 'resource2')->willThrow('League\\Flysystem\\FileExistsException'); $filesystem->updateStream($path, 'resource2')->willReturn(true); $this->writeStream($path, 'resource2'); $filesystem->writeStream($path, 'resource2')->shouldBeCalled(); $filesystem->updateStream($path, 'resource2')->shouldBeCalled(); }
/** * @expectedException InvalidArgumentException */ public function testUpdateStreamFail() { $adapter = Mockery::mock('League\\Flysystem\\AdapterInterface'); $adapter->shouldReceive('has')->andReturn(true); $filesystem = new Filesystem($adapter); $filesystem->updateStream('file.txt', 'not a resource'); }
/** * @inheritdoc */ public function updateStream($path, $resource, array $config = []) { try { return $this->fileSystem->updateStream($this->getInnerPath($path), $resource, $config); } catch (FileNotFoundException $e) { throw $this->exceptionWrapper($e, $path); } }
/** * Update an existing file using a stream. * * @param string $path The path of the existing file. * @param resource $resource The file handle. * @param array $config An optional configuration array. * * @throws InvalidArgumentException If $resource is not a file handle. * @throws FileNotFoundException * * @return bool True on success, false on failure. */ public function updateStream($path, $resource, array $config = []) { $result = parent::updateStream($path, $resource, $config); if ($result && ($resource = $this->get($path))) { return $this->dispatch(new SyncFile($resource)); } return $result; }
public function testUpdateStreamInvalid() { $this->setExpectedException('InvalidArgumentException'); $this->filesystem->updateStream('path.txt', '__INVALID__'); }
/** * @inheritdoc */ public function updateStream($path, $resource, array $config = []) { try { return parent::updateStream($path, $resource, $config); } catch (\Exception $e) { $this->errors[] = $e->getMessage(); } return false; }