Skip to content

Commit

Permalink
Update tests for pseudo directories
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Apr 1, 2022
1 parent 8274444 commit 623e9d3
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions tests/SwiftAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public function testDirectoryExists()
$this->container->shouldReceive('listObjects')
->once()
->with([
'prefix' => 'hello',
'prefix' => 'hello/',
'delimiter' => '/',
])
->andReturn($objects);

Expand All @@ -138,7 +139,8 @@ public function testDirectoryExists()
$this->container->shouldReceive('listObjects')
->once()
->with([
'prefix' => 'world',
'prefix' => 'world/',
'delimiter' => '/',
])
->andReturn($objects);

Expand All @@ -161,7 +163,8 @@ public function testListContents()
$this->container->shouldReceive('listObjects')
->once()
->with([
'prefix' => 'hello',
'prefix' => 'hello/',
'delimiter' => '/',
])
->andReturn($objects);

Expand All @@ -172,9 +175,7 @@ public function testListContents()
'mime_type' => 'text/html; charset=UTF-8',
'visibility' => null,
'file_size' => 0,
'extra_metadata' => [
'type' => 'file',
],
'extra_metadata' => [],
];

$contents = $this->adapter->listContents('hello', false);
Expand All @@ -188,6 +189,34 @@ public function testListContents()
$this->assertEquals($times, $count);
}

public function testListContentsPseudoDirectory()
{
$object = Mockery::mock(StorageObject::class);
$object->name = 'name/';
$generator = function () use ($object) {
yield $object;
};
$objects = $generator();
$this->container->shouldReceive('listObjects')
->once()
->with([
'prefix' => 'hello/',
'delimiter' => '/',
])
->andReturn($objects);

$expect = [
'path' => 'name',
'type' => 'dir',
'visibility' => null,
'extra_metadata' => [],
'last_modified' => null,
];

$contents = iterator_to_array($this->adapter->listContents('hello', false));
$this->assertEquals($expect, $contents[0]->jsonSerialize());
}

public function testMove()
{
$this->object->shouldReceive('copy')->once()->with([
Expand Down Expand Up @@ -358,9 +387,7 @@ public function testMetadataMethods()
'mime_type' => 'text/html; charset=UTF-8',
'visibility' => null,
'file_size' => 0,
'extra_metadata' => [
'type' => 'file',
],
'extra_metadata' => [],
];

foreach ($methods as $method) {
Expand Down

0 comments on commit 623e9d3

Please sign in to comment.