Skip to content

Commit

Permalink
Merge 'dilab/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Dec 17, 2023
2 parents ede435d + 27fa0c5 commit 6c0a31a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ vendor/*
composer.lock
.idea
.vscode
/.phpunit.result.cache
.phpunit.cache/*
.phpunit.*.cache
/build
6 changes: 3 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" colors="true" backupGlobals="false" bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.result.cache">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="./vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.result.cache" backupStaticProperties="false">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
Expand All @@ -8,8 +8,8 @@
</coverage>
<logging/>
<testsuites>
<testsuite name="Unit tests">
<directory suffix=".php">test/</directory>
<testsuite name="Package Test Suite">
<directory suffix=".php">./test/</directory>
</testsuite>
</testsuites>
<source>
Expand Down
File renamed without changes.
11 changes: 5 additions & 6 deletions src/Resumable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
11 changes: 5 additions & 6 deletions test/src/ResumableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit 6c0a31a

Please sign in to comment.