Skip to content

Commit

Permalink
Merge pull request #6 from thewilkybarkid/mimetype
Browse files Browse the repository at this point in the history
Use set mimetype
  • Loading branch information
twistor authored May 30, 2019
2 parents a11bf3f + d629070 commit d0e8747
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MemoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public function getMetadata($path)
*/
public function getMimetype($path)
{
$mimetype = Util::guessMimeType($path, $this->storage[$path]['contents']);
$mimetype = isset($this->storage[$path]['mimetype']) ? $this->storage[$path]['mimetype'] :
Util::guessMimeType($path, $this->storage[$path]['contents']);

return [
'mimetype' => $mimetype,
Expand Down Expand Up @@ -223,6 +224,9 @@ public function update($path, $contents, Config $config)
$this->storage[$path]['timestamp'] = $config->get('timestamp', time());
$this->storage[$path]['size'] = Util::contentSize($contents);
$this->storage[$path]['visibility'] = $config->get('visibility', $this->storage[$path]['visibility']);
if ($config->has('mimetype')) {
$this->storage[$path]['mimetype'] = $config->get('mimetype');
}

return $this->getMetadata($path);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/MemoryAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,24 @@ public function testGetMetadata()
$this->assertSame(8, $meta['size']);
$this->assertSame('public', $meta['visibility']);
$this->assertTrue(is_int($meta['timestamp']));

$this->adapter->write('dir/file.txt', '', new Config(['mimetype' => 'mime/type']));

$meta = $this->adapter->getMetadata('dir/file.txt');

$this->assertCount(6, $meta);
$this->assertSame('mime/type', $meta['mimetype']);
}

public function testGetMimetype()
{
$this->adapter->write('dir/file.txt', 'contents', new Config(['mimetype' => 'mime/type']));

$meta = $this->adapter->getMimetype('file.txt');
$this->assertSame('text/plain', $meta['mimetype']);

$meta = $this->adapter->getMimetype('dir/file.txt');
$this->assertSame('mime/type', $meta['mimetype']);
}

public function testGetSize()
Expand Down

0 comments on commit d0e8747

Please sign in to comment.