Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/S3/Transfer.php

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part_size is missing a docblock entry in the "The options array can contain the following key value pairs..." section

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Transfer implements PromisorInterface
private $sourceMetadata;
private $destination;
private $concurrency;
private $partSize;
private $mupThreshold;
private $before;
private $after;
Expand Down Expand Up @@ -118,6 +119,9 @@ public function __construct(
$this->concurrency = isset($options['concurrency'])
? $options['concurrency']
: MultipartUploader::DEFAULT_CONCURRENCY;
$this->partSize = isset($options['part_size'])
? $options['part_size']
: MultipartUploader::PART_MIN_SIZE;
Comment on lines +122 to +124

@stobrien89 stobrien89 Jun 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be some validation here against MultipartUploader::PART_MIN_SIZE and MultipartUploader::PART_MAX_SIZE. If it's less than the min size or greater than the max size, throw an InvalidArgumentException

$this->mupThreshold = isset($options['mup_threshold'])
? $options['mup_threshold']
: 16777216;
Expand Down Expand Up @@ -387,6 +391,7 @@ private function uploadMultipart($filename)
'before_upload' => $this->before,
'before_complete' => $this->before,
'concurrency' => $this->concurrency,
'part_size' => $this->partSize,
'add_content_md5' => $this->addContentMD5
]))->promise();
}
Expand Down
34 changes: 34 additions & 0 deletions tests/S3/TransferTest.php

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a couple more tests following the validation suggestions above

Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,40 @@ public function testDoesMultipartForLargeFilesWithFileInfoAsSource()
`rm -rf $dir`;
}

public function testMultipartForLargeFilesDoesUsePartSize()
{
$s3 = $this->getTestClient('s3');
$this->addMockResults($s3, [
new Result(['UploadId' => '123']),
new Result(['ETag' => 'a']),
new Result(['ETag' => 'b']),
new Result(['UploadId' => '123']),
]);

$dir = sys_get_temp_dir() . '/unittest';
`rm -rf $dir`;
mkdir($dir);
$filename = new SplFileInfo($dir . '/large.txt');
$f = fopen($filename, 'w+');
$line = str_repeat('.', 1024);
for ($i = 0; $i < 20000; $i++) {
fwrite($f, $line);
}
fclose($f);

$res = fopen('php://temp', 'r+');
$t = new Transfer($s3, $dir, 's3://foo/bar', [
'part_size' => 1024 * 1024 * 10,
'debug' => $res
]);

$t->transfer();
rewind($res);
$output = stream_get_contents($res);
$this->assertStringNotContainsString("Transferring $filename -> s3://foo/bar/large.txt (UploadPart) : Part=3", $output);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test asserts only the absence of a Part=3 line. better to assert positively or via mock command capture (Middleware::tap())

`rm -rf $dir`;
}

public function testDownloadsObjects()
{
$s3 = $this->getTestClient('s3');
Expand Down