From 4173749069702bcf3ca9ca72ed5d8ff8b7359188 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 28 Oct 2025 15:39:36 +0100 Subject: [PATCH] Add regression test --- composer.json | 3 +- .../FilesystemTenancyBootstrapperTest.php | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 393d0d8a..b03e1b2f 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "doctrine/dbal": "^3.6.0", "spatie/valuestore": "^1.2.5", "pestphp/pest": "^3.0", - "larastan/larastan": "^3.0" + "larastan/larastan": "^3.0", + "league/flysystem-path-prefixing": "^3.0" }, "autoload": { "psr-4": { diff --git a/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php b/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php index 857e0eac..bf62f3d0 100644 --- a/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php +++ b/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php @@ -200,3 +200,31 @@ test('tenant storage can get deleted after the tenant when DeletingTenant listen expect(File::isDirectory($tenantStoragePath))->toBeFalse(); }); + +test('scoped disks are scoped per tenant', function () { + config([ + 'tenancy.bootstrappers' => [ + FilesystemTenancyBootstrapper::class, + ], + 'filesystems.disks.scoped_disk' => [ + 'driver' => 'scoped', + 'disk' => 'public', + 'prefix' => 'scoped_disk_prefix', + ], + ]); + + $tenant = Tenant::create(); + + $storagePath = storage_path() . "/tenant{$tenant->id}"; + + // Resolve scoped_disk before initializing tenancy + Storage::disk('scoped_disk'); + + tenancy()->initialize($tenant); + + Storage::disk('scoped_disk')->put('foo.txt', 'foo text'); + + tenancy()->end(); + + expect(File::exists($storagePath . '/app/public/scoped_disk_prefix/foo.txt'))->toBeTrue(); +});