Files
Investidor-V2/tools/portal-qa-environment.php
nala 6ddafc95ba
tests / ci (push) Canceled after 0s
oportunidades 4
2026-10-10 07:03:59 +02:00

40 lines
2.1 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
// One stable key for the already encrypted isolated restore. Never generate/rotate it here.
function portalQaEnvironment(string $sessionDriver = 'array'): array
{
$root = dirname(__DIR__);
$backup = json_decode(file_get_contents($root.'/storage/app/private/investmoz-v2/opportunity-resources-backup-proof.json'), true, 512, JSON_THROW_ON_ERROR);
$target = $backup['restored_target'];
if (! ($backup['restore_verified'] ?? false) || ! preg_match('/^desk_restore_\d{8}_\d{6}_test$/D', $target['database']) || (int) $target['port'] !== 55441) {
throw new RuntimeException('Verified isolated QA required.');
}
$cache = $root.'/storage/framework/cache/portal-investor-qa-config.php';
if (is_file($cache)) {
throw new RuntimeException('QA config cache must be reconciled before use; active cache is untouched.');
}
foreach (['APP_ENV' => 'testing', 'APP_URL' => 'http://127.0.0.1:18097', 'APP_KEY' => 'base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
'APP_PREVIOUS_KEYS' => '', 'APP_CONFIG_CACHE' => $cache, 'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441',
'DB_DATABASE' => $target['database'], 'DB_USERNAME' => 'postgres', 'DB_PASSWORD' => '', 'DB_URL' => '', 'SESSION_DRIVER' => $sessionDriver,
'SESSION_COOKIE' => 'opportunity_resources_qa', 'CACHE_STORE' => 'array', 'QUEUE_CONNECTION' => 'sync'] as $key => $value) {
putenv($key.'='.$value);
$_ENV[$key] = $_SERVER[$key] = $value;
}
return $target;
}
function portalQaAssertTarget(array $target): object
{
$identity = DB::selectOne('SELECT current_database() AS database,inet_server_port() AS port');
if (! app()->environment('testing') || $identity->database !== $target['database'] || (int) $identity->port !== 55441
|| config('database.connections.pgsql.host') !== '127.0.0.1' || config('database.connections.pgsql.url')
|| app()->configurationIsCached() || config('app.key') !== getenv('APP_KEY')) {
throw new RuntimeException('QA configuration/actual target mismatch; refused before writes.');
}
return $identity;
}