Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Fix the Filesystem manager's exception on unsupported driver #30331

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}