diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index f4383ff9..6569aede 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -18,6 +18,7 @@ use Stancl\Tenancy\Events\TenantCreated; use Stancl\Tenancy\Events\TenantDeleted; use Stancl\Tenancy\Tests\Etc\TestSeeder; use Stancl\Tenancy\Events\DeletingTenant; +use Stancl\Tenancy\Events\DatabaseMigrated; use Stancl\Tenancy\Tests\Etc\ExampleSeeder; use Stancl\Tenancy\Events\TenancyInitialized; 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); }); +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 () { $tenant = Tenant::create(); Artisan::call('tenants:migrate');