Skip to content

Commit f5d9978

Browse files
committed
Act on failing directory creation
1 parent a60a13c commit f5d9978

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/Adapter/AwsS3.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ public function write($path, $contents, $config = null)
8989
$options['ACL'] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? 'public-read' : 'private';
9090
}
9191

92-
$this->client->putObject($options);
92+
$result = $this->client->putObject($options);
93+
94+
if ($result === false) {
95+
return false;
96+
}
9397

9498
if ($visibility) {
9599
$options['visibility'] = $visibility;

tests/AwsS3Tests.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,23 @@ public function testListContents()
7878
{
7979
$mock = $this->getS3Client();
8080
$mock->shouldReceive('listObjects')->once()->andReturn(Mockery::self());
81-
$result = array('Contents' => array(array('Key' => 'path', 'ContentLength' => 20, 'ContentType' => 'text/plain')));
81+
$result = array('Contents' => array(
82+
array('Key' => 'path', 'ContentLength' => 20, 'ContentType' => 'text/plain'),
83+
array('Key' => 'path/to/dir/'),
84+
));
8285
$mock->shouldReceive('getAll')->with(array('Contents'))->andReturn($result);
8386
$adapter = new Adapter($mock, 'bucketname');
8487
$listing = $adapter->listContents();
85-
$this->assertCount(1, $listing);
86-
$item = reset($listing);
87-
$this->assertArrayHasKey('path', $item);
88-
$this->assertArrayHasKey('type', $item);
89-
$this->assertArrayHasKey('mimetype', $item);
88+
$this->assertCount(2, $listing);
89+
$first = reset($listing);
90+
$this->assertArrayHasKey('path', $first);
91+
$this->assertArrayHasKey('type', $first);
92+
$this->assertArrayHasKey('mimetype', $first);
93+
$last = end($listing);
94+
$this->assertArrayHasKey('path', $first);
95+
$this->assertArrayHasKey('type', $first);
96+
$this->assertEquals($last['type'], 'dir');
97+
9098
}
9199

92100
public function testSetVisibility()
@@ -158,6 +166,15 @@ public function testCreateDir()
158166
$this->assertEquals('dir', $result['type']);
159167
}
160168

169+
public function testCreateDirFail()
170+
{
171+
$mock = $this->getS3Client();
172+
$mock->shouldReceive('putObject')->andReturn(false);
173+
$adapter = new Adapter($mock, 'bucketname');
174+
$result = $adapter->createDir('something');
175+
$this->assertFalse($result);
176+
}
177+
161178
public function testRead()
162179
{
163180
$mock = $this->getS3Client();

0 commit comments

Comments
 (0)