Skip to content

Commit

Permalink
Add bare bucket transfer manager test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeskew committed Jul 22, 2015
1 parent 5f83656 commit 656ad9e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/S3/Transfer.php
Expand Up @@ -319,14 +319,14 @@ private function createS3Key($filename)
{
$relative_file_path = ltrim(
preg_replace('#^' . preg_quote($this->source['path']) . '#', '', $filename),
'/'
'/\\'
);

if (isset($this->s3Args['Key'])) {
return rtrim($this->s3Args['Key'], '/').'/'.$relative_file_path;
} else {
return $relative_file_path;
}

return $relative_file_path;
}

private function addDebugToBefore($debug)
Expand Down
27 changes: 27 additions & 0 deletions tests/S3/TransferTest.php
Expand Up @@ -187,6 +187,33 @@ public function testDownloadsObjects()
`rm -rf $dir`;
}

public function testCanUploadToBareBucket()
{
$s3 = $this->getMockBuilder('Aws\S3\S3Client')
->disableOriginalConstructor()
->getMock();

$filesInDirectory = array_filter(
iterator_to_array(\Aws\recursive_dir_iterator(__DIR__)),
function ($path) { return !is_dir($path); }
);

$s3->expects($this->exactly(count($filesInDirectory)))
->method('getCommand')
->with(
'PutObject',
new \PHPUnit_Framework_Constraint_Callback(function (array $args) use ($filesInDirectory) {
return 'bare-bucket' === $args['Bucket']
&& in_array($args['SourceFile'], $filesInDirectory)
&& __DIR__ . '/' . $args['Key'] === $args['SourceFile'];
})
)
->willReturn($this->getMock('Aws\CommandInterface'));

(new Transfer($s3, __DIR__, 's3://bare-bucket'))
->transfer();
}

private function mockResult(callable $fn)
{
return function (callable $handler) use ($fn) {
Expand Down

0 comments on commit 656ad9e

Please sign in to comment.