1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-09-20 11:14:03 +00:00

Refactor DeleteTenantStorage tests

Use the *original* 'tenant storage gets deleted during tenant deletion when the DeletingTenant pipeline contains DeleteTenantStorage' test and remove what's not necessary anymore. Also make it clear that enabling FS bootstrapper is not required for the deletion to work -- the tenant directory just has to exist.

Delete the nonsensical 'DeleteTenantStorage does not delete the central storage directory when the filesystem bootstrapper is disabled' test. That one was there to test that the central dir never gets deleted, but it was wrong. Added 'DeleteTenantStorage never deletes the central storage directory' which actually makes the job's realpath() comparison check pass and the job just returns.
This commit is contained in:
lukinovec 2026-09-08 15:00:19 +02:00
parent 45100453c5
commit e6d785a8d1

View file

@ -185,7 +185,7 @@ test('create and delete storage symlinks jobs work', function() {
$this->assertDirectoryDoesNotExist(public_path("public-$tenantKey"));
});
test('tenant storage gets deleted during tenant deletion when the DeletingTenant pipeline contains DeleteTenantStorage', function(bool $suffixStoragePath) {
test('tenant storage gets deleted during tenant deletion when the DeletingTenant pipeline contains DeleteTenantStorage', function (bool $bootstrapperEnabled) {
Event::listen(DeletingTenant::class,
JobPipeline::make([DeleteTenantStorage::class])->send(function (DeletingTenant $event) {
return $event->tenant;
@ -193,40 +193,47 @@ test('tenant storage gets deleted during tenant deletion when the DeletingTenant
);
config([
'tenancy.bootstrappers' => [FilesystemTenancyBootstrapper::class],
// suffix_storage_path only affects the storage_path() helper.
// The disks are scoped to the tenant's storage directory either way,
// so the tenant files end up there.
'tenancy.filesystem.suffix_storage_path' => $suffixStoragePath,
// This is the default tenancy config -- set it here explicitly for clarity
'tenancy.filesystem.suffix_base' => 'tenant',
'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/',
'tenancy.bootstrappers' => $bootstrapperEnabled ? [FilesystemTenancyBootstrapper::class] : [],
]);
$centralStoragePath = storage_path();
$tenantStoragePath = fn (Tenant $tenant) => $centralStoragePath . "/tenant{$tenant->getTenantKey()}";
$tenant = Tenant::create();
$tenantStoragePath = $centralStoragePath . "/tenant{$tenant->getTenantKey()}";
tenancy()->initialize($tenant);
File::ensureDirectoryExists($tenantStoragePath($tenant));
Storage::disk('public')->put('foo.txt', 'tenant file');
expect(file_get_contents($tenantStoragePath . '/app/public/foo.txt'))->toBe('tenant file');
expect(File::isDirectory($centralStoragePath))->toBeTrue();
expect(File::isDirectory($tenantStoragePath($tenant)))->toBeTrue();
$tenant->delete();
expect(File::isDirectory($tenantStoragePath))->toBeFalse();
expect(File::isDirectory($centralStoragePath))->toBeTrue();
})->with([true, false]);
expect(File::isDirectory($tenantStoragePath($tenant)))->toBeFalse();
})->with([
'filesystem bootstrapper enabled' => true,
'filesystem bootstrapper disabled' => false,
]);
test('DeleteTenantStorage does not delete the central storage directory when the filesystem bootstrapper is disabled', function () {
config(['tenancy.bootstrappers' => []]);
$centralStoragePath = storage_path();
test('DeleteTenantStorage never deletes the central storage directory', function () {
$tenant = Tenant::create();
$centralStoragePath = FilesystemTenancyBootstrapper::getBoundCentralStoragePath();
$tenantStoragePath = FilesystemTenancyBootstrapper::getTenantStoragePath($tenant);
File::ensureDirectoryExists($centralStoragePath . '/app');
// Make the tenant storage path a symlink to the central storage directory
File::deleteDirectory($tenantStoragePath);
symlink($centralStoragePath, $tenantStoragePath);
expect(realpath($tenantStoragePath))->toBe(realpath($centralStoragePath));
(new DeleteTenantStorage($tenant))->handle();
expect(File::isDirectory($centralStoragePath))->toBeTrue();
expect(File::isDirectory($centralStoragePath . '/app'))->toBeTrue();
expect(is_link($tenantStoragePath))->toBeTrue();
});
test('the framework/cache directory is created when storage_path is scoped', function (bool $suffixStoragePath) {