Skip to content

Commit

Permalink
Fix the Filesystem manager's exception on unsupported driver
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Oct 18, 2019
1 parent 91553d8 commit 9a3e6a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Illuminate/Filesystem/FilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,18 @@ protected function get($name)
protected function resolve($name)
{
$config = $this->getConfig($name);
$name = $config['driver'] ?? $name;

if (isset($this->customCreators[$config['driver']])) {
if (isset($this->customCreators[$name])) {
return $this->callCustomCreator($config);
}

$driverMethod = 'create'.ucfirst($config['driver']).'Driver';
$driverMethod = 'create'.ucfirst($name).'Driver';

if (method_exists($this, $driverMethod)) {
return $this->{$driverMethod}($config);
} else {
throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported.");
throw new InvalidArgumentException("Driver [{$name}] is not supported.");
}
}

Expand Down Expand Up @@ -298,7 +299,7 @@ public function set($name, $disk)
*/
protected function getConfig($name)
{
return $this->app['config']["filesystems.disks.{$name}"];
return $this->app['config']["filesystems.disks.{$name}"] ?: [];
}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/Filesystem/FilesystemManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Illuminate\Tests\Filesystem;

use Illuminate\Filesystem\FilesystemManager;
use Illuminate\Foundation\Application;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

class FilesystemManagerTest extends TestCase
{
public function testExceptionThrownOnUnsupportedDriver()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Driver [unsupported-disk] is not supported.');

$filesystem = new FilesystemManager(tap(new Application, function ($app) {
$app['config'] = ['filesystems.disks.unsupported-disk' => null];
}));

$filesystem->disk('unsupported-disk');
}
}

0 comments on commit 9a3e6a9

Please sign in to comment.