Skip to content

Commit

Permalink
Merge pull request #30 from chrisnharvey/content-type
Browse files Browse the repository at this point in the history
Add content type configuration to write and writeStream
  • Loading branch information
mzur authored Apr 5, 2022
2 parents 47f6283 + 7702a19 commit 453860a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/SwiftAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,17 @@ public function setVisibility(string $path, string $visibility): void

protected function getWriteData(string $path, Config $config): array
{
return ['name' => $path];
$data = ['name' => $path];

if ($contentType = $config->get('contentType')) {
$data['contentType'] = $contentType;
}

if ($detectContentType = $config->get('detectContentType')) {
$data['detectContentType'] = $detectContentType;
}

return $data;
}

protected function getObjectInstance(string $path): StorageObject
Expand Down
18 changes: 16 additions & 2 deletions tests/SwiftAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,17 @@ public function testWrite()
->with([
'name' => 'hello',
'content' => 'world',
'contentType' => 'text/plain',
'detectContentType' => true,
])
->andReturn($this->object);

$response = $this->adapter->write('hello', 'world', $this->config);
$config = $this->config->extend([
'contentType' => 'text/plain',
'detectContentType' => true,
]);

$response = $this->adapter->write('hello', 'world', $config);

$this->assertNull($response);
}
Expand All @@ -306,9 +313,16 @@ public function testWriteStream()
$this->container->shouldReceive('createObject')->once()->with([
'name' => 'hello',
'stream' => $this->adapter->streamMock,
'contentType' => 'text/plain',
'detectContentType' => true,
])->andReturn($this->object);

$response = $this->adapter->writeStream('hello', $stream, $this->config);
$config = $this->config->extend([
'contentType' => 'text/plain',
'detectContentType' => true,
]);

$response = $this->adapter->writeStream('hello', $stream, $config);

$this->assertNull($response);
}
Expand Down

0 comments on commit 453860a

Please sign in to comment.