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.
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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/');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user