diff --git a/spec/Gaufrette/Adapter/LocalSpec.php b/spec/Gaufrette/Adapter/LocalSpec.php index 9066430c8..230f8c189 100644 --- a/spec/Gaufrette/Adapter/LocalSpec.php +++ b/spec/Gaufrette/Adapter/LocalSpec.php @@ -33,6 +33,13 @@ function it_is_a_mime_type_provider() $this->shouldHaveType('Gaufrette\Adapter\MimeTypeProvider'); } + function it_throws_when_the_base_directory_does_not_exist() + { + $this->beConstructedWith('/do-no-exists'); + + $this->shouldThrow(StorageFailure::class)->duringInstantiation(); + } + function it_gets_the_file_mime_type() { $this->mimeType('filename')->shouldReturn('text/plain'); diff --git a/src/Gaufrette/Adapter/Local.php b/src/Gaufrette/Adapter/Local.php index eb30227d1..ccdd64973 100644 --- a/src/Gaufrette/Adapter/Local.php +++ b/src/Gaufrette/Adapter/Local.php @@ -23,7 +23,6 @@ class Local implements Adapter, MimeTypeProvider { protected $directory; - private $create; private $mode; /** @@ -39,6 +38,12 @@ public function __construct($directory, $mode = 0777) if (is_link($this->directory)) { $this->directory = realpath($this->directory); } + + if (!is_dir($this->directory)) { + throw new StorageFailure( + sprintf('Directory "%s" does not exist.', $directory) + ); + } } /**