test(unit): Add Neuron and Validator regression tests

This commit is contained in:
kj
2026-09-05 13:43:35 -03:00
parent bf03e10b54
commit d594aa3ec1
3 changed files with 235 additions and 10 deletions

View File

@@ -19,12 +19,12 @@ final class BootstrapTest extends TestCase
{
$this->assertTrue(
class_exists(Neuron::class),
'FALTA AUTOLOAD: autoload.php no resolvio Libs\Neuron; revisa ROOT_CORE y ejecuta desde la raiz'
'MISSING AUTOLOAD: autoload.php did not resolve Libs\Neuron; check ROOT_CORE and run from the project root'
);
$neuron = new Neuron(['clave' => 'valor']);
$this->assertSame('valor', $neuron->clave);
$this->assertNull($neuron->inexistente);
$neuron = new Neuron(['key' => 'value']);
$this->assertSame('value', $neuron->key);
$this->assertNull($neuron->doesNotExist);
}
public function testDatabaseConstantsPointToInMemorySqlite(): void
@@ -32,20 +32,20 @@ final class BootstrapTest extends TestCase
$this->assertSame(
'sqlite',
DB_TYPE,
'FALTA OVERRIDE: DB_TYPE viene de config.php; el bootstrap debe definir las constantes ANTES de require autoload.php'
'MISSING OVERRIDE: DB_TYPE comes from config.php; the bootstrap must define the DB_* constants BEFORE requiring autoload.php'
);
$this->assertSame(':memory:', DB_NAME, 'DB_NAME deberia ser :memory: para no tocar discos ni servidores');
$this->assertSame(':memory:', DB_NAME, 'DB_NAME should be :memory: so tests never touch disks or servers');
}
public function testTestDatabaseIsUsable(): void
{
$db = self::db();
$this->assertInstanceOf(PDO::class, $db, 'No se pudo obtener la PDO de prueba');
$this->assertSame($db, self::db(), 'Database::getInstance deberia devolver el mismo singleton');
$this->assertInstanceOf(PDO::class, $db, 'Could not obtain the test PDO connection');
$this->assertSame($db, self::db(), 'Database::getInstance should return the same singleton');
$db->exec('CREATE TABLE smoke (id INTEGER PRIMARY KEY, v TEXT)');
$db->prepare('INSERT INTO smoke (v) VALUES (?)')->execute(['cuac']);
$this->assertSame('cuac', $db->query('SELECT v FROM smoke')->fetchColumn());
$db->prepare('INSERT INTO smoke (v) VALUES (?)')->execute(['quack']);
$this->assertSame('quack', $db->query('SELECT v FROM smoke')->fetchColumn());
$db->exec('DROP TABLE smoke');
}
}