From eb5e6eeed4ef5c5988f4ec03ff727c08874667d8 Mon Sep 17 00:00:00 2001 From: kj Date: Mon, 5 Oct 2026 17:36:08 -0300 Subject: [PATCH] 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. --- packages/test/duckbrain.json | 18 ++++++++++++++---- packages/test/tests/bootstrap.php | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/test/duckbrain.json b/packages/test/duckbrain.json index 0bdef51..ddb749a 100644 --- a/packages/test/duckbrain.json +++ b/packages/test/duckbrain.json @@ -2,15 +2,25 @@ "name": "test", "version": "0.1.0", "description": "Kit de pruebas PHPUnit para Duckbrain", - "core": { "requires": ">=0.1", "tested": "0.1" }, + "core": { + "requires": ">=0.1", + "tested": "0.1" + }, "php": ">=8.1", "components": { "harness": { - "files": ["phpunit.xml", "tests"], - "require": { "commands:cli": ">=0.1" } + "files": [ + "phpunit.xml", + "tests" + ], + "require": { + "commands:migration": ">=0.1" + } } }, - "default": ["harness"], + "default": [ + "harness" + ], "post-install": [ "composer require --dev phpunit/phpunit:^11.0 fakerphp/faker", "composer dump-autoload" diff --git a/packages/test/tests/bootstrap.php b/packages/test/tests/bootstrap.php index 1b59515..36c3d7f 100644 --- a/packages/test/tests/bootstrap.php +++ b/packages/test/tests/bootstrap.php @@ -6,6 +6,18 @@ 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 @@ -20,6 +32,11 @@ 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/');