Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasmure committed Jun 6, 2019
1 parent 3d639c1 commit 03f6a04
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions spec/Gaufrette/Adapter/OpenStackSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ function it_throws_storage_failure_while_deleting(Container $container, StorageO

function it_renames_file(Container $container, StorageObject $source, StorageObject $dest)
{
$container->objectExists('source')->willReturn(true);
$container->objectExists('dest')->willReturn(false);

$container->getObject('source')->willReturn($source);
Expand All @@ -273,8 +274,16 @@ function it_renames_file(Container $container, StorageObject $source, StorageObj
$this->rename('source', 'dest')->shouldNotThrow();
}

function it_throws_storage_failure_when_source_does_not_exist_during_rename(Container $container)
{
$container->objectExists('source')->willReturn(false);

$this->shouldThrow('Gaufrette\Exception\StorageFailure')->duringrename('source', 'dest');
}

function it_throws_storage_failure_when_dest_already_exists_during_rename(Container $container)
{
$container->objectExists('source')->willReturn(true);
$container->objectExists('dest')->willReturn(true);

$this->shouldThrow('Gaufrette\Exception\StorageFailure')->duringrename('source', 'dest');
Expand Down
2 changes: 1 addition & 1 deletion spec/Gaufrette/FilesystemSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function it_fails_when_a_storage_failure_happens_during_rename(Adapter $adapter)
{
$adapter->exists('filename')->willReturn(true);
$adapter->exists('otherFilename')->willReturn(false);
$adapter->rename('filename', 'otherFilename')->willThrow(StorageFailure::unexpectedFailure('rename', []));
$adapter->rename('filename', 'otherFilename')->willThrow(StorageFailure::class);

$this
->shouldThrow(StorageFailure::class)
Expand Down
2 changes: 1 addition & 1 deletion src/Gaufrette/Adapter/OpenStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function delete($key)
*/
public function rename($sourceKey, $targetKey)
{
if ($this->exists($targetKey)) {
if (!$this->exists($sourceKey) || $this->exists($targetKey)) {
throw StorageFailure::unexpectedFailure(
'rename',
['sourceKey' => $sourceKey, 'targetKey' => $targetKey]
Expand Down

0 comments on commit 03f6a04

Please sign in to comment.