seed(InstitutionCategorySeeder::class); $this->fakeLegacyConnection(); $this->insertLegacyInstitution(['id' => 1]); $this->artisan('v1:import') ->expectsOutputToContain('created 1, updated 0, skipped 0') ->assertSuccessful(); $this->assertDatabaseCount('institutions', 1); } public function test_dry_run_writes_nothing(): void { $this->seed(InstitutionCategorySeeder::class); $this->fakeLegacyConnection(); $this->insertLegacyInstitution(['id' => 1]); $this->artisan('v1:import --dry-run') ->expectsOutputToContain('DRY-RUN') ->assertSuccessful(); $this->assertDatabaseCount('institutions', 0); } public function test_only_filter_skips_unmatched_importers(): void { $this->seed(InstitutionCategorySeeder::class); $this->fakeLegacyConnection(); $this->insertLegacyInstitution(['id' => 1]); $this->artisan('v1:import --only=nonexistent')->assertSuccessful(); $this->assertDatabaseCount('institutions', 0); } public function test_it_prints_importer_warnings(): void { $this->seed(InstitutionCategorySeeder::class); $this->fakeLegacyConnection(); $this->insertLegacyInstitution(['id' => 99, 'category' => 999]); $this->artisan('v1:import') ->expectsOutputToContain('category 999') ->assertSuccessful(); } public function test_it_fails_when_an_importer_throws(): void { // Connessione raggiungibile (getPdo ok) ma senza la tabella `institution`: // l'import lancia, il comando intercetta e fallisce. config()->set('database.connections.legacy', [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ]); DB::purge('legacy'); $this->seed(InstitutionCategorySeeder::class); $this->artisan('v1:import') ->expectsOutputToContain('failed') ->assertFailed(); } public function test_it_fails_when_the_legacy_connection_is_unavailable(): void { config()->set('database.connections.legacy', [ 'driver' => 'sqlite', 'database' => '/nonexistent/path/legacy.sqlite', 'prefix' => '', ]); DB::purge('legacy'); $this->artisan('v1:import') ->expectsOutputToContain('Legacy connection unavailable') ->assertFailed(); } }