diff --git a/.gitignore b/.gitignore index 4e0caa9..d07e812 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ vendor/* composer.lock .idea .vscode -/.phpunit.result.cache +.phpunit.cache/* +.phpunit.*.cache /build diff --git a/phpunit.xml b/phpunit.xml index cd5ee77..2a1f1f9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + @@ -8,8 +8,8 @@ - - test/ + + ./test/ diff --git a/README.md b/readme.md similarity index 100% rename from README.md rename to readme.md diff --git a/src/Resumable.php b/src/Resumable.php index 59c81f7..68e9c69 100644 --- a/src/Resumable.php +++ b/src/Resumable.php @@ -198,10 +198,9 @@ public function handleChunk(): ResponseInterface $files = $this->request->getUploadedFiles(); $identifier = $this->resumableParam($this->resumableOption['identifier']); $filename = $this->resumableParam($this->resumableOption['filename']); - $totalChunks = (int) $this->resumableParam($this->resumableOption['totalChunks']); $chunkNumber = (int) $this->resumableParam($this->resumableOption['chunkNumber']); $chunkSize = (int) $this->resumableParam($this->resumableOption['chunkSize']); - $totalSize = (int) $this->resumableParam($this->resumableOption['totalSize']); + $totalChunks = (int) $this->resumableParam($this->resumableOption['totalChunks']); if ($chunkSize <= 0) { $this->log('The chunk size is <= 0'); @@ -212,7 +211,7 @@ public function handleChunk(): ResponseInterface if (count($files) > 0) { $firstFile = array_shift($files); if ($firstFile instanceof UploadedFileInterface) { - $chunkDir = $this->tmpChunkDir($identifier) . DIRECTORY_SEPARATOR; + $chunkDir = $this->tmpChunkDir($identifier) . DIRECTORY_SEPARATOR; $this->chunkFile = $chunkDir . $this->tmpChunkFilename($filename, $chunkNumber); $this->log('Moving chunk', ['identifier' => $identifier, 'chunkNumber' => $chunkNumber]); // On the server that received the upload @@ -316,10 +315,10 @@ public function resumableParams(): array return []; } - public function isFileUploadComplete(string $filename, string $identifier, int $numOfChunks): bool + public function isFileUploadComplete(string $filename, string $identifier, int $totalChunks): bool { - for ($i = 1; $i <= $numOfChunks; $i++) { - if (! $this->isChunkUploaded($identifier, $filename, $i)) { + for ($i = 1; $i <= $totalChunks; $i++) { + if (!$this->isChunkUploaded($identifier, $filename, $i)) { return false; } } diff --git a/test/src/ResumableTest.php b/test/src/ResumableTest.php index aa826e9..0cc3723 100644 --- a/test/src/ResumableTest.php +++ b/test/src/ResumableTest.php @@ -35,14 +35,14 @@ protected function setUp(): void { $this->psr17Factory = new Psr17Factory(); - $this->request = $this->psr17Factory->createServerRequest('GET', 'http://example.com'); + $this->request = $this->psr17Factory->createServerRequest('GET', 'http://example.com'); $this->response = $this->psr17Factory->createResponse(200); $this->refreshResumable(); } private function refreshResumable(): void { - $this->resumable = new Resumable($this->request, $this->response); + $this->resumable = new Resumable($this->request, $this->response); $this->resumable->tempFolder = 'test/tmp'; $this->resumable->uploadFolder = 'test/uploads'; } @@ -200,7 +200,6 @@ public function testHandleChunk(): void $this->assertFileDoesNotExist($uploadedFile);// It was moved $this->assertTrue(unlink($this->resumable->uploadFolder . '/' . $uploadedFileName)); - } public function testResumableParamsGetRequest(): void @@ -322,9 +321,9 @@ public function testTmpChunkDir(): void public function testTmpChunkFile(): void { - $filename = 'example-file.png'; - $chunkNumber = 1; - $expected = $filename . '.' . str_pad((string) $chunkNumber, 4, '0', STR_PAD_LEFT); + $filename = 'example-file.png'; + $chunkNumber = 1; + $expected = $filename . '.' . str_pad((string) $chunkNumber, 4, '0', STR_PAD_LEFT); $this->assertEquals($expected, $this->resumable->tmpChunkFilename($filename, $chunkNumber)); }