Files
duckbrain-toolbox/packages/test/tests/bootstrap.php
T
kj eb5e6eeed4 fix(test): self-register Tests\ autoload and migrations dir in bootstrap
The harness failed under a real phpunit run because nothing mapped
Tests\ -> tests/ and Commands\Migration needs migrations/ to exist.
Declare commands:migration as the actual dependency.
2026-10-05 17:36:08 -03:00

48 lines
1.4 KiB
PHP

<?php
// Bootstrap para tests - carga el autoload de Composer
use Libs\Loader;
require_once __DIR__ . '/../vendor/autoload.php';
// Mapeo PSR-4 propio del arbol de pruebas (Tests\ -> tests/) sin exigir que el
// proyecto declare autoload-dev en su composer.json.
spl_autoload_register(function (string $class): void {
if (!str_starts_with($class, 'Tests\\')) {
return;
}
$file = __DIR__ . '/' . str_replace('\\', '/', substr($class, 6)) . '.php';
if (is_file($file)) {
require_once $file;
}
});
// ============================================
// IMPORTANT: Definir constantes ANTES de cargar config.php
// para sobreescribir la configuración para definir una
// base de datos para sólo los test
// ============================================
define('DB_TYPE', 'sqlite');
define('DB_HOST', 'localhost');
define('DB_NAME', ':memory:');
define('DB_USER', '');
define('DB_PASS', '');
// Incluir config.php con el autoloader
@require_once __DIR__ . '/../autoload.php';
// El ledger de migraciones (Commands\Migration) necesita el directorio.
if (!is_dir(ROOT_DIR . '/migrations')) {
mkdir(ROOT_DIR . '/migrations', 0777, true);
}
// Router autoload
Loader::load(ROOT_CORE . '/Routers/');
// Other autoloads
Loader::load(ROOT_CORE . '/Autoloads/');
// Stubs de header()/setcookie() por namespace
require_once __DIR__ . '/Support/http_stubs.php';