75 lines
2.4 KiB
PHP
75 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Concerns;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Costruisce una connessione `legacy` SQLite in-memory che replica le tabelle v1
|
|
* lette dall'ETL (`institution`), così gli importer si testano senza un MySQL v1.
|
|
*/
|
|
trait CreatesLegacyDatabase
|
|
{
|
|
/** Riconfigura la connessione `legacy` su SQLite :memory: e ne crea lo schema v1. */
|
|
protected function fakeLegacyConnection(): void
|
|
{
|
|
config()->set('database.connections.legacy', [
|
|
'driver' => 'sqlite',
|
|
'database' => ':memory:',
|
|
'prefix' => '',
|
|
'foreign_key_constraints' => false,
|
|
]);
|
|
DB::purge('legacy');
|
|
|
|
$schema = Schema::connection('legacy');
|
|
$schema->dropIfExists('institution');
|
|
|
|
$schema->create('institution', function (Blueprint $table) {
|
|
$table->unsignedBigInteger('id')->primary();
|
|
$table->unsignedBigInteger('category');
|
|
$table->string('name', 255);
|
|
$table->string('abbreviation', 5);
|
|
$table->string('address', 255);
|
|
$table->decimal('lat', 10, 6);
|
|
$table->decimal('lon', 10, 6);
|
|
$table->string('url', 2000)->nullable();
|
|
$table->string('logo', 255);
|
|
$table->string('uuid', 36);
|
|
$table->string('color', 50)->nullable();
|
|
$table->string('city', 100);
|
|
$table->boolean('is_storage_place');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Inserisce una riga `institution` legacy e ne restituisce l'id.
|
|
*
|
|
* @param array<string, mixed> $overrides
|
|
*/
|
|
protected function insertLegacyInstitution(array $overrides = []): int
|
|
{
|
|
$row = array_merge([
|
|
'id' => fake()->unique()->numberBetween(1, 1_000_000),
|
|
'category' => 3,
|
|
'name' => 'Some Museum',
|
|
'abbreviation' => 'SM',
|
|
'address' => 'Main Street 1',
|
|
'lat' => 55.704660,
|
|
'lon' => 13.191007,
|
|
'url' => 'https://example.org/',
|
|
'logo' => 'default.jpg',
|
|
'uuid' => (string) Str::uuid(),
|
|
'color' => '#abcdef',
|
|
'city' => 'Lund',
|
|
'is_storage_place' => 1,
|
|
], $overrides);
|
|
|
|
DB::connection('legacy')->table('institution')->insert($row);
|
|
|
|
return (int) $row['id'];
|
|
}
|
|
}
|