Skip to content

Commit

Permalink
Act on failing directory creation
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Mar 22, 2014
1 parent a60a13c commit f5d9978
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/Adapter/AwsS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 23 additions & 6 deletions tests/AwsS3Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f5d9978

Please sign in to comment.