feature test su institution

This commit is contained in:
Giuseppe Naponiello
2026-06-22 22:14:15 +02:00
parent cc4e174880
commit fe73662903
39 changed files with 2432 additions and 1 deletions

View File

@@ -0,0 +1,94 @@
<?php
namespace Tests\Feature\Etl;
use Database\Seeders\InstitutionCategorySeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\Concerns\CreatesLegacyDatabase;
use Tests\TestCase;
class V1ImportCommandTest extends TestCase
{
use CreatesLegacyDatabase;
use RefreshDatabase;
public function test_it_imports_and_reports_counts(): void
{
$this->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();
}
}