Skip to content

Commit

Permalink
test(storage): Add base test for filesystem tenant disk
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieread committed Sep 29, 2024
1 parent 2203f6a commit 5149c71
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/Services/FilesystemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);

namespace Sprout\Tests\Services;

use Illuminate\Config\Repository;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Sprout\Managers\TenancyManager;
use Workbench\App\Models\TenantModel;

#[Group('services'), Group('filesystem')]
class FilesystemTest extends TestCase
{
use WithWorkbench, RefreshDatabase;

protected $enablesPackageDiscoveries = true;

protected function defineEnvironment($app): void
{
tap($app['config'], static function (Repository $config) {
$config->set('multitenancy.providers.tenants.model', TenantModel::class);
$config->set('filesystems.disks.tenant', [
'driver' => 'sprout',
'disk' => 'local',
'tenancy' => 'tenants',
]);
});
}

#[Test]
public function canCreateScopedTenantFilesystemDisk(): void
{
$tenant = TenantModel::factory()->createOne();

app(TenancyManager::class)->get()->setTenant($tenant);

$disk = Storage::disk('tenant');

$this->assertNotNull($disk);
$this->assertSame($tenant->getTenantResourceKey(), basename($disk->path('')));
}
}

0 comments on commit 5149c71

Please sign in to comment.