1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 07:54:03 +00:00

Add test for not stopping tenants:migrate after the first failure

This commit is contained in:
lukinovec 2023-01-05 18:12:10 +01:00
parent b69c523f08
commit 146570f7e9

View file

@ -18,6 +18,7 @@ use Stancl\Tenancy\Events\TenantCreated;
use Stancl\Tenancy\Events\TenantDeleted; use Stancl\Tenancy\Events\TenantDeleted;
use Stancl\Tenancy\Tests\Etc\TestSeeder; use Stancl\Tenancy\Tests\Etc\TestSeeder;
use Stancl\Tenancy\Events\DeletingTenant; use Stancl\Tenancy\Events\DeletingTenant;
use Stancl\Tenancy\Events\DatabaseMigrated;
use Stancl\Tenancy\Tests\Etc\ExampleSeeder; use Stancl\Tenancy\Tests\Etc\ExampleSeeder;
use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\BootstrapTenancy;
@ -124,6 +125,32 @@ test('migrate command only throws exceptions if skip-failing is not passed', fun
expect(fn() => pest()->artisan('tenants:migrate --schema-path="tests/Etc/tenant-schema.dump" --skip-failing'))->not()->toThrow(TenantDatabaseDoesNotExistException::class); expect(fn() => pest()->artisan('tenants:migrate --schema-path="tests/Etc/tenant-schema.dump" --skip-failing'))->not()->toThrow(TenantDatabaseDoesNotExistException::class);
}); });
test('migrate command does not stop after the first failure if skip-failing is passed', function() {
$tenants = collect([
Tenant::create(),
$tenantWithoutDatabase = Tenant::create(),
Tenant::create(),
]);
$migratedTenants = 0;
Event::listen(DatabaseMigrated::class, function() use (&$migratedTenants) {
$migratedTenants++;
});
$databaseToDrop = $tenantWithoutDatabase->run(fn() => DB::connection()->getDatabaseName());
DB::statement("DROP DATABASE `$databaseToDrop`");
Artisan::call('tenants:migrate', [
'--schema-path' => '"tests/Etc/tenant-schema.dump"',
'--skip-failing' => true,
'--tenants' => $tenants->pluck('id')->toArray(),
]);
expect($migratedTenants)->toBe(2);
});
test('dump command works', function () { test('dump command works', function () {
$tenant = Tenant::create(); $tenant = Tenant::create();
Artisan::call('tenants:migrate'); Artisan::call('tenants:migrate');