67 lines
5.3 KiB
PHP
67 lines
5.3 KiB
PHP
<?php
|
|
|
|
use App\Models\InvestmentDossier;
|
|
use App\Models\Opportunity;
|
|
use App\Models\Project;
|
|
use App\Models\Sector;
|
|
use Illuminate\Contracts\Console\Kernel;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
foreach (['APP_ENV' => 'testing', 'APP_KEY' => 'base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=', 'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441', 'DB_DATABASE' => 'investmoz_v2_20261008_test', 'DB_USERNAME' => 'postgres', 'DB_PASSWORD' => '', 'DB_URL' => ''] as $key => $value) {
|
|
putenv($key.'='.$value);
|
|
$_ENV[$key] = $_SERVER[$key] = $value;
|
|
}
|
|
require dirname(__DIR__).'/vendor/autoload.php';
|
|
$app = require dirname(__DIR__).'/bootstrap/app.php';
|
|
$app->make(Kernel::class)->bootstrap();
|
|
$connection = DB::connection();
|
|
if ($connection->getDatabaseName() !== 'investmoz_v2_20261008_test' || (string) $connection->getConfig('port') !== '55441' || $connection->getConfig('host') !== '127.0.0.1' || ! in_array($connection->getConfig('url'), [null, ''], true)) {
|
|
throw new RuntimeException('QA configuration required');
|
|
}
|
|
$identity = DB::selectOne('SELECT current_database() AS name,inet_server_port() AS port');
|
|
if ($identity->name !== 'investmoz_v2_20261008_test' || (int) $identity->port !== 55441) {
|
|
throw new RuntimeException('QA identity required');
|
|
}
|
|
$manifest = DB::transaction(function () {
|
|
$nodes = [];
|
|
$parent = null;
|
|
foreach (['country', 'province', 'district', 'admin_post', 'locality', 'site'] as $type) {
|
|
$id = (string) Str::uuid();
|
|
DB::table('geo_locations')->insert(['id' => $id, 'code' => $id, 'name' => 'Territory QA '.$type, 'location_type' => $type, 'parent_id' => $parent, 'data_classification' => 'public',
|
|
'source_system' => 'cartografia-workbook', 'external_id' => '964a187ad32ea553b9e112cd159caa90b900050c42b7329594a75bcd798a96ff:'.$id]);
|
|
$nodes[$type] = $id;
|
|
$parent = $id;
|
|
}
|
|
$second = (string) Str::uuid();
|
|
DB::table('geo_locations')->insert(['id' => $second, 'code' => $second, 'name' => 'Territory QA second site', 'location_type' => 'site', 'parent_id' => $nodes['locality'], 'data_classification' => 'public']);
|
|
foreach ([$nodes['site'], $second] as $index => $id) {
|
|
DB::table('geo_geometries')->insert(['id' => (string) Str::uuid(), 'geo_location_id' => $id, 'geometry_type' => 'point', 'data_classification' => 'public', 'source_system' => 'Synthetic QA coordinates; no real source',
|
|
'geom' => DB::raw('ST_SetSRID(ST_MakePoint('.(32.5 + $index / 10).',-25.9),4326)'), 'properties' => json_encode(['source_date' => '2026-10-08'])]);
|
|
}
|
|
DB::table('geo_geometries')->insert(['id' => (string) Str::uuid(), 'geo_location_id' => $nodes['site'], 'geometry_type' => 'polygon', 'data_classification' => 'public', 'source_system' => 'Synthetic QA boundary; not official',
|
|
'geom' => DB::raw("ST_GeomFromText('POLYGON((32 -26,33 -26,33 -25,32 -25,32 -26))',4326)"), 'properties' => json_encode(['source_date' => '2026-10-08'])]);
|
|
$project = Project::factory()->create(['name' => 'Territory QA project', 'status' => 'draft', 'data_classification' => 'internal']);
|
|
$dossier = InvestmentDossier::create(['project_id' => $project->id, 'title' => 'Territory QA dossier', 'source' => 'Synthetic QA source', 'content' => ['location' => 'Synthetic QA site'], 'publication_status' => 'published', 'published_at' => now()->subMinute(), 'approval_basis' => 'document_owner', 'approval_evidence' => 'Synthetic isolated QA disclosure']);
|
|
DB::table('project_locations')->insert(['id' => (string) Str::uuid(), 'project_id' => $project->id, 'geo_location_id' => $nodes['site'], 'role' => 'primary', 'data_classification' => 'public', 'source_system' => 'Synthetic QA source']);
|
|
DB::table('project_locations')->insert(['id' => (string) Str::uuid(), 'project_id' => $project->id, 'geo_location_id' => $nodes['district'], 'role' => 'impact', 'data_classification' => 'public', 'source_system' => 'Synthetic QA impact']);
|
|
$sector = Sector::firstOrCreate(['slug' => 'territory-qa'], ['name' => 'Territory QA', 'is_active' => true]);
|
|
$cases = [];
|
|
foreach (['direct', 'context', 'multiple', 'insufficient', 'without-point'] as $kind) {
|
|
$opportunity = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'TERR-QA-'.Str::uuid(), 'title' => 'Territory QA '.$kind, 'slug' => 'territory-qa-'.$kind.'-'.Str::uuid(), 'status' => 'published', 'published_at' => now()->subMinute()]);
|
|
if ($kind === 'context') {
|
|
DB::table('opportunity_projects')->insert(['opportunity_id' => $opportunity->id, 'project_id' => $project->id]);
|
|
}
|
|
foreach (match ($kind) {
|
|
'direct' => [$nodes['site']], 'multiple' => [$nodes['site'], $second], 'without-point' => [$nodes['district']], default => []
|
|
} as $id) {
|
|
DB::table('opportunity_locations')->insert(['opportunity_id' => $opportunity->id, 'geo_location_id' => $id]);
|
|
}
|
|
$cases[$kind] = ['id' => $opportunity->id, 'slug' => $opportunity->slug];
|
|
}
|
|
|
|
return ['database' => 'investmoz_v2_20261008_test', 'port' => 55441, 'cases' => $cases, 'dossier' => $dossier->id, 'district' => $nodes['district']];
|
|
});
|
|
file_put_contents(dirname(__DIR__).'/storage/app/private/investmoz-v2/territory-qa-fixtures.json', json_encode($manifest, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
|
|
echo json_encode($manifest, JSON_THROW_ON_ERROR).PHP_EOL;
|