Skip to content

Commit

Permalink
Merge pull request #2 from treyssatvincent/tech/MissingNextcloudUsern…
Browse files Browse the repository at this point in the history
…ameException

tech: add a MissingNextcloudUsernameException
  • Loading branch information
treyssatvincent committed Dec 20, 2023
2 parents 282e631 + bd608a5 commit 966c91e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/MissingNextcloudUsernameException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Nino\FilesystemProviders;

class MissingNextcloudUsernameException extends \Exception
{
public function __construct()
{
parent::__construct("Missing userName in filesystems.disks.nextcloud (config/filesystems.php)");
}
}
2 changes: 1 addition & 1 deletion src/NextcloudServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function boot(): void
{
Storage::extend('nextcloud', static function ($app, $config) {
if (empty($config['userName'])) {
throw new \Exception('No userName in config.'); // TODO: custom Exception
throw new MissingNextcloudUsernameException();
}

$client = new WebDAVClient($config);
Expand Down
9 changes: 9 additions & 0 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Config;
use League\Flysystem\WebDAV\WebDAVAdapter;
use Nino\FilesystemProviders\MissingNextcloudUsernameException;
use Nino\FilesystemProviders\NextcloudServiceProvider;
use Orchestra\Testbench\TestCase;

Expand Down Expand Up @@ -69,4 +70,12 @@ public function it_can_have_an_optional_directory(): void
$filesystem->getAdapter()->publicUrl($fileName, new Config())
);
}

/** @test */
public function it_throws_exception_on_empty_userName(): void
{
$this->app['config']->set(self::CONFIG_KEY . '.userName', '');
$this->expectException(MissingNextcloudUsernameException::class);
Storage::disk('nextcloud');
}
}

0 comments on commit 966c91e

Please sign in to comment.