Skip to content

Commit 5b2cce3

Browse files
committed
Add test for CreateTenantStorage
1 parent 873488b commit 5b2cce3

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Stancl\Tenancy\Jobs\CreateStorageSymlinks;
1414
use Stancl\Tenancy\Jobs\RemoveStorageSymlinks;
1515
use Stancl\Tenancy\Listeners\BootstrapTenancy;
16+
use Stancl\Tenancy\Jobs\CreateTenantStorage;
1617
use Stancl\Tenancy\Jobs\DeleteTenantStorage;
1718
use Stancl\Tenancy\Listeners\RevertToCentralContext;
1819
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
@@ -184,6 +185,26 @@
184185
$this->assertDirectoryDoesNotExist(public_path("public-$tenantKey"));
185186
});
186187

188+
test('tenant storage gets created when TenantCreated listens to CreateTenantStorage', function() {
189+
config([
190+
'tenancy.bootstrappers' => [
191+
FilesystemTenancyBootstrapper::class,
192+
],
193+
]);
194+
195+
Event::listen(TenantCreated::class,
196+
JobPipeline::make([CreateTenantStorage::class])->send(function (TenantCreated $event) {
197+
return $event->tenant;
198+
})->shouldBeQueued(false)->toListener()
199+
);
200+
201+
$centralStoragePath = storage_path();
202+
$tenant = Tenant::create();
203+
$tenantStoragePath = $centralStoragePath . '/tenant' . $tenant->getTenantKey();
204+
205+
$this->assertDirectoryExists($tenantStoragePath . '/framework/cache');
206+
});
207+
187208
test('tenant storage can get deleted after the tenant when DeletingTenant listens to DeleteTenantStorage', function() {
188209
Event::listen(DeletingTenant::class,
189210
JobPipeline::make([DeleteTenantStorage::class])->send(function (DeletingTenant $event) {
@@ -260,4 +281,3 @@
260281
expect(file_get_contents(storage_path() . "/app/public/scoped_disk_prefix/foo.txt"))->toBe('central2');
261282
expect(file_get_contents(storage_path() . "/tenant{$tenant->id}/app/public/scoped_disk_prefix/foo.txt"))->toBe('tenant');
262283
});
263-

0 commit comments

Comments
 (0)