Skip to content

Commit

Permalink
Ensure we throw an exception when we try to resolve a mime-type for a…
Browse files Browse the repository at this point in the history
… non-existing file.
  • Loading branch information
frankdejonge committed Apr 11, 2022
1 parent 267e29d commit dea7299
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Local/LocalFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ public function mimeType(string $path): FileAttributes
{
$location = $this->prefixer->prefixPath($path);
error_clear_last();

if ( ! is_file($location)) {
throw UnableToRetrieveMetadata::mimeType($location, 'No such file exists.');
}

$mimeType = $this->mimeTypeDetector->detectMimeTypeFromFile($location);

if ($mimeType === null) {
Expand Down
6 changes: 5 additions & 1 deletion src/Local/LocalFilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace League\Flysystem\Local;

use League\MimeTypeDetection\FinfoMimeTypeDetector;
use const LOCK_EX;
use League\Flysystem\AdapterTestUtilities\FilesystemAdapterTestCase;
use League\Flysystem\Config;
Expand Down Expand Up @@ -539,7 +540,10 @@ public function fetching_unknown_mime_type_of_a_file(): void
public function not_being_able_to_get_mimetype(): void
{
$this->expectException(UnableToRetrieveMetadata::class);
$adapter = new LocalFilesystemAdapter(static::ROOT);
$adapter = new LocalFilesystemAdapter(
location: static::ROOT,
mimeTypeDetector: new FinfoMimeTypeDetector(),
);
$adapter->mimeType('flysystem.svg');
}

Expand Down

0 comments on commit dea7299

Please sign in to comment.