From 5b2cce347a41251be6fb788b2406633b17a461c8 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 27 Mar 2026 11:58:00 +0100 Subject: [PATCH] Add test for CreateTenantStorage --- .../FilesystemTenancyBootstrapperTest.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php b/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php index 04b4e1ed..4594d7aa 100644 --- a/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php +++ b/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php @@ -13,6 +13,7 @@ use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Jobs\CreateStorageSymlinks; use Stancl\Tenancy\Jobs\RemoveStorageSymlinks; use Stancl\Tenancy\Listeners\BootstrapTenancy; +use Stancl\Tenancy\Jobs\CreateTenantStorage; use Stancl\Tenancy\Jobs\DeleteTenantStorage; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; @@ -184,6 +185,26 @@ test('create and delete storage symlinks jobs work', function() { $this->assertDirectoryDoesNotExist(public_path("public-$tenantKey")); }); +test('tenant storage gets created when TenantCreated listens to CreateTenantStorage', function() { + config([ + 'tenancy.bootstrappers' => [ + FilesystemTenancyBootstrapper::class, + ], + ]); + + Event::listen(TenantCreated::class, + JobPipeline::make([CreateTenantStorage::class])->send(function (TenantCreated $event) { + return $event->tenant; + })->shouldBeQueued(false)->toListener() + ); + + $centralStoragePath = storage_path(); + $tenant = Tenant::create(); + $tenantStoragePath = $centralStoragePath . '/tenant' . $tenant->getTenantKey(); + + $this->assertDirectoryExists($tenantStoragePath . '/framework/cache'); +}); + test('tenant storage can get deleted after the tenant when DeletingTenant listens to DeleteTenantStorage', function() { Event::listen(DeletingTenant::class, JobPipeline::make([DeleteTenantStorage::class])->send(function (DeletingTenant $event) { @@ -260,4 +281,3 @@ test('scoped disks are scoped per tenant', function () { expect(file_get_contents(storage_path() . "/app/public/scoped_disk_prefix/foo.txt"))->toBe('central2'); expect(file_get_contents(storage_path() . "/tenant{$tenant->id}/app/public/scoped_disk_prefix/foo.txt"))->toBe('tenant'); }); -