public function testReadAndDeleteFailedRead() { $path = 'path.txt'; $this->prophecy->has($path)->willReturn(true); $this->prophecy->read($path)->willReturn(false); $response = $this->filesystem->readAndDelete($path); $this->assertFalse($response); }
/** * @inheritdoc */ public function readAndDelete($path) { $innerPath = $this->getInnerPath($path); try { $return = $this->fileSystem->readAndDelete($innerPath); } catch (FileNotFoundException $e) { throw $this->exceptionWrapper($e, $path); } if ($return !== false) { $this->invokePlugin("removePathFromIndex", [$path, $innerPath], $this); } return $return; }
public function testReadAndDeleteFail() { $path = 'path.ext'; $expected = false; $mock = Mockery::mock('League\\Flysystem\\Adapter\\AbstractAdapter[has,read,delete]'); $adapter = new Filesystem($mock); $mock->shouldReceive('has')->andReturn(true); $mock->shouldReceive('read')->once()->with($path)->andReturn($expected); $result = $adapter->readAndDelete($path); $this->assertEquals($expected, $result); }
/** * Handles the command execution. * * @param UploadImage $command * @return null|string * * @todo check permission */ public function handle(UploadImage $command) { // check if the user can upload images, otherwise return $this->assertCan($command->actor, 'flagrow.image.upload'); $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'image'); $command->file->moveTo($tmpFile); $file = new UploadedFile($tmpFile, $command->file->getClientFilename(), $command->file->getClientMediaType(), $command->file->getSize(), $command->file->getError(), true); // validate the file $this->validator->maxFileSize = $this->settings->get('flagrow.image-upload.maxFileSize', 2048); $this->validator->assertValid(['image' => $file]); // resize if enabled if ($this->settings->get('flagrow.image-upload.mustResize')) { $manager = new ImageManager(); $manager->make($tmpFile)->fit($this->settings->get('flagrow.image-upload.resizeMaxWidth', 100), $this->settings->get('flagrow.image-upload.resizeMaxHeight', 100))->save(); } $image = (new Image())->forceFill(['user_id' => $command->actor->id, 'upload_method' => $this->settings->get('flagrow.image-upload.uploadMethod', 'local'), 'created_at' => Carbon::now(), 'file_name' => sprintf('%d-%s.%s', $command->actor->id, Str::quickRandom(), $file->guessExtension() ?: 'jpg'), 'file_size' => $file->getSize()]); // fire the Event ImageWillBeSaved, which can be extended and/or modified elsewhere $this->events->fire(new ImageWillBeSaved($command->actor, $image, $file)); $tmpFilesystem = new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))); $meta = $this->upload->uploadContents($image->file_name, $tmpFilesystem->readAndDelete(pathinfo($tmpFile, PATHINFO_BASENAME))); if ($meta) { $image->file_url = array_get($meta, 'url'); if ($image->isDirty()) { $image->save(); } return $image; } return false; }
/** * Read and delete a file. * * @param string $path * @return string|false file contents */ public function readAndDelete($path) { if (StringHelper::isRegexp($path) && !($path = $this->searchByPattern($path))) { return false; } try { return parent::readAndDelete($path); } catch (\Exception $e) { $this->errors[] = StringHelper::replace(FileException::UNKNOWN_FILE, ['path' => $path]); } return false; }