Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
k-holy committed Apr 27, 2023
2 parents 10b4e5d + 1a6a0d9 commit 0f145e5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -3,7 +3,7 @@
"homepage": "https://github.com/k-holy/volcanus-file-uploader",
"type": "library",
"description": "file uploader",
"version": "3.1.1",
"version": "3.1.2",
"license": "MIT",
"authors": [
{
Expand Down
10 changes: 8 additions & 2 deletions src/Uploader.php
Expand Up @@ -154,8 +154,14 @@ public function validate(FileInterface $file, FileValidator $validator): bool
*/
public function move(FileInterface $file): string
{
$moveDirectory = $this->config('moveDirectory');
$moveRetry = $this->config('moveRetry');
$moveDirectory = (string)$this->config('moveDirectory');
if (!isset($moveDirectory) || strlen($moveDirectory) === 0) {
throw new UploaderException('moveDirectory is not specified.');
}
$moveRetry = (int)$this->config('moveRetry');
if (!isset($moveRetry) || $moveRetry === 0) {
throw new UploaderException('moveRetry is not specified.');
}
if ($file->isValid()) {
$this->prepareMove($moveDirectory);
$extension = $file->getClientExtension();
Expand Down
36 changes: 36 additions & 0 deletions tests/Volcanus/FileUploader/Test/UploaderTest.php
Expand Up @@ -283,6 +283,42 @@ public function testMove()
$this->assertFileExists($movedPath);
}

public function testMoveRaiseExceptionWhenMoveDirectoryIsNotSpecified()
{
$this->expectException(UploaderException::class);

$file = $this->copyFile(
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'this-is.jpg'
);

unlink($file->getPath());

$uploader = new Uploader([
'moveDirectory' => null,
'moveRetry' => 1,
]);

$uploader->move($file);
}

public function testMoveRaiseExceptionWhenMoveRetryIsNotSpecified()
{
$this->expectException(UploaderException::class);

$file = $this->copyFile(
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'this-is.jpg'
);

unlink($file->getPath());

$uploader = new Uploader([
'moveDirectory' => $this->tempDir,
'moveRetry' => null,
]);

$uploader->move($file);
}

public function testMoveRaiseExceptionWhenAllRetryFailed()
{
$this->expectException(UploaderException::class);
Expand Down

0 comments on commit 0f145e5

Please sign in to comment.