Files
Investidor-V2/tools/simulator-qa-router.php
nala 1106509116
tests / ci (push) Canceled after 0s
vrsao 2
2026-10-08 14:02:01 +02:00

68 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Vite;
// Local smoke-test router. Its database target is intentionally fixed to the
// disposable PHPUnit database; do not reuse it for development or production.
$root = dirname(__DIR__);
$qaEnvironment = [
'APP_ENV' => 'testing',
'APP_DEBUG' => 'true',
'DB_CONNECTION' => 'pgsql',
'DB_HOST' => '127.0.0.1',
'DB_PORT' => '55441',
'DB_DATABASE' => 'investmoz_test',
'DB_USERNAME' => 'investmoz_test',
'DB_PASSWORD' => '',
'DB_URL' => '',
'QUEUE_CONNECTION' => 'sync',
'SESSION_DRIVER' => 'array',
'CACHE_STORE' => 'array',
];
foreach ($qaEnvironment as $key => $value) {
putenv($key.'='.$value);
$_ENV[$key] = $value;
$_SERVER[$key] = $value;
}
$path = rawurldecode(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/');
$asset = $root.'/public'.$path;
if ($path !== '/' && is_file($asset)) {
return false;
}
require_once $root.'/vendor/autoload.php';
$app = require $root.'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
// Keep QA on the checked-in build manifest; the developer Vite server may be
// stale or backed by a different working copy and is never the QA frontend.
Vite::useHotFile($root.'/storage/framework/investmoz-qa-hot-file');
$configuration = $app->make('config');
$connectionName = $configuration->get('database.default');
$connection = $configuration->get('database.connections.'.$connectionName, []);
// Fail before opening a connection if cached config or .env changes the target.
if ($connectionName !== 'pgsql'
|| ($connection['host'] ?? null) !== '127.0.0.1'
|| (string) ($connection['port'] ?? '') !== '55441'
|| ($connection['database'] ?? null) !== 'investmoz_test'
|| ! in_array($connection['url'] ?? null, [null, ''], true)) {
http_response_code(503);
exit('QA database configuration did not match the fixed target.');
}
$identity = $app->make('db')->connection($connectionName)->selectOne(
'select current_database() as database, host(inet_server_addr()) as host, inet_server_port() as port',
);
if ($identity->database !== 'investmoz_test' || $identity->host !== '127.0.0.1' || (int) $identity->port !== 55441) {
http_response_code(503);
exit('Connected database did not match the fixed QA target.');
}
header('X-Investmoz-QA-Target: '.$identity->database.':'.$identity->port);
$app->handleRequest(Request::capture());