From f5d9978f38828cdfa18da5930df7ebc4d30fa1da Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Sat, 22 Mar 2014 22:53:52 +0100 Subject: [PATCH] Act on failing directory creation --- src/Adapter/AwsS3.php | 6 +++++- tests/AwsS3Tests.php | 29 +++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/Adapter/AwsS3.php b/src/Adapter/AwsS3.php index ef2a094c3..a1483b0f3 100644 --- a/src/Adapter/AwsS3.php +++ b/src/Adapter/AwsS3.php @@ -89,7 +89,11 @@ public function write($path, $contents, $config = null) $options['ACL'] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? 'public-read' : 'private'; } - $this->client->putObject($options); + $result = $this->client->putObject($options); + + if ($result === false) { + return false; + } if ($visibility) { $options['visibility'] = $visibility; diff --git a/tests/AwsS3Tests.php b/tests/AwsS3Tests.php index 79e5a6d25..d8c19f2ed 100644 --- a/tests/AwsS3Tests.php +++ b/tests/AwsS3Tests.php @@ -78,15 +78,23 @@ public function testListContents() { $mock = $this->getS3Client(); $mock->shouldReceive('listObjects')->once()->andReturn(Mockery::self()); - $result = array('Contents' => array(array('Key' => 'path', 'ContentLength' => 20, 'ContentType' => 'text/plain'))); + $result = array('Contents' => array( + array('Key' => 'path', 'ContentLength' => 20, 'ContentType' => 'text/plain'), + array('Key' => 'path/to/dir/'), + )); $mock->shouldReceive('getAll')->with(array('Contents'))->andReturn($result); $adapter = new Adapter($mock, 'bucketname'); $listing = $adapter->listContents(); - $this->assertCount(1, $listing); - $item = reset($listing); - $this->assertArrayHasKey('path', $item); - $this->assertArrayHasKey('type', $item); - $this->assertArrayHasKey('mimetype', $item); + $this->assertCount(2, $listing); + $first = reset($listing); + $this->assertArrayHasKey('path', $first); + $this->assertArrayHasKey('type', $first); + $this->assertArrayHasKey('mimetype', $first); + $last = end($listing); + $this->assertArrayHasKey('path', $first); + $this->assertArrayHasKey('type', $first); + $this->assertEquals($last['type'], 'dir'); + } public function testSetVisibility() @@ -158,6 +166,15 @@ public function testCreateDir() $this->assertEquals('dir', $result['type']); } + public function testCreateDirFail() + { + $mock = $this->getS3Client(); + $mock->shouldReceive('putObject')->andReturn(false); + $adapter = new Adapter($mock, 'bucketname'); + $result = $adapter->createDir('something'); + $this->assertFalse($result); + } + public function testRead() { $mock = $this->getS3Client();