true]); expect($exitCode)->toBe(0); $stagingCount = DB::connection('gescon_import') ->table('condomin_mirror') ->where('cod_stabile', '0021') ->count(); expect($stagingCount)->toBe(644); // Check count per year $count0001 = DB::connection('gescon_import')->table('condomin_mirror')->where('cod_stabile', '0021')->where('source_year', '0001')->count(); $count0003 = DB::connection('gescon_import')->table('condomin_mirror')->where('cod_stabile', '0021')->where('source_year', '0003')->count(); $count0004 = DB::connection('gescon_import')->table('condomin_mirror')->where('cod_stabile', '0021')->where('source_year', '0004')->count(); expect($count0001)->toBe(212) ->and($count0003)->toBe(214) ->and($count0004)->toBe(218); // Check duplicates $duplicates = DB::connection('gescon_import')->select(" SELECT provenance_hash, COUNT(*) as cnt FROM condomin_mirror WHERE cod_stabile = '0021' GROUP BY provenance_hash HAVING cnt > 1 "); expect($duplicates)->toBeEmpty(); // Step 2: Second run (Idempotency) $secondExit = Artisan::call('gescon:import-mirror-0021'); expect($secondExit)->toBe(0); $secondCount = DB::connection('gescon_import') ->table('condomin_mirror') ->where('cod_stabile', '0021') ->count(); expect($secondCount)->toBe(644); // Step 3: Verify real MDB interno column preservation $sample = DB::connection('gescon_import') ->table('condomin_mirror') ->where('cod_stabile', '0021') ->where('source_year', '0001') ->where('id_cond', '127') ->first(); expect($sample)->not->toBeNull() ->and($sample->scala)->toBe('C') ->and($sample->interno)->toBe('3'); });