diff --git a/src/Upload/Storage/FileSystem.php b/src/Upload/Storage/FileSystem.php index 7b1382b..644f197 100644 --- a/src/Upload/Storage/FileSystem.php +++ b/src/Upload/Storage/FileSystem.php @@ -79,6 +79,7 @@ public function __construct($directory, $overwrite = false) * @param \Upload\FileInfoInterface $file The file object to upload * @throws \Upload\Exception If overwrite is false and file already exists * @throws \Upload\Exception If error moving file to destination + * @return string The location of the file uploaded */ public function upload(\Upload\FileInfoInterface $fileInfo) { @@ -90,6 +91,8 @@ public function upload(\Upload\FileInfoInterface $fileInfo) if ($this->moveUploadedFile($fileInfo->getPathname(), $destinationFile) === false) { throw new \Upload\Exception('File could not be moved to final destination.', $fileInfo); } + + return $destinationFile; } /** @@ -106,4 +109,14 @@ protected function moveUploadedFile($source, $destination) { return move_uploaded_file($source, $destination); } + + /** + * Get directory + * + * @return string + */ + public function getDirectory() + { + return rtrim($this->directory, DIRECTORY_SEPARATOR); + } } diff --git a/tests/Storage/FileSystemTest.php b/tests/Storage/FileSystemTest.php index 06d0abf..49c347d 100644 --- a/tests/Storage/FileSystemTest.php +++ b/tests/Storage/FileSystemTest.php @@ -1,6 +1,11 @@ upload($fileInfo); } + + + + public function testReturnsUploadedFileName() + { + $storage = $this->getMock( + '\Upload\Storage\FileSystem', + array('moveUploadedFile'), + array($this->assetsDirectory, true) + ); + + $storage->expects($this->any()) + ->method('moveUploadedFile') + ->will($this->returnValue(true)); + + $fileName = dirname(__DIR__) . '/assets/foo.txt'; + + $fileInfo = new \Upload\FileInfo( + $fileName + ); + + $this->assertEquals($fileName, $storage->upload($fileInfo), "Got file name"); + $this->assertEquals($this->assetsDirectory, $storage->getDirectory(), "Got upload directory"); + } }