test(bootstrap): add smoke test for autoload and test DB
This commit is contained in:
51
tests/Unit/BootstrapTest.php
Normal file
51
tests/Unit/BootstrapTest.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use Libs\Neuron;
|
||||||
|
use PDO;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BootstrapTest - DuckBrain test harness
|
||||||
|
*
|
||||||
|
* Prueba de humo de la infraestructura: autoload de composer + framework,
|
||||||
|
* constantes de la DB de prueba y conexión PDO realmente utilizable. Si
|
||||||
|
* algo del entorno está mal, esta prueba falla primero con el diagnóstico.
|
||||||
|
*/
|
||||||
|
final class BootstrapTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFrameworkClassesAreAutoloaded(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(
|
||||||
|
class_exists(Neuron::class),
|
||||||
|
'FALTA AUTOLOAD: autoload.php no resolvio Libs\Neuron; revisa ROOT_CORE y ejecuta desde la raiz'
|
||||||
|
);
|
||||||
|
|
||||||
|
$neuron = new Neuron(['clave' => 'valor']);
|
||||||
|
$this->assertSame('valor', $neuron->clave);
|
||||||
|
$this->assertNull($neuron->inexistente);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDatabaseConstantsPointToInMemorySqlite(): void
|
||||||
|
{
|
||||||
|
$this->assertSame(
|
||||||
|
'sqlite',
|
||||||
|
DB_TYPE,
|
||||||
|
'FALTA OVERRIDE: DB_TYPE viene de config.php; el bootstrap debe definir las constantes ANTES de require autoload.php'
|
||||||
|
);
|
||||||
|
$this->assertSame(':memory:', DB_NAME, 'DB_NAME deberia ser :memory: para no tocar discos ni servidores');
|
||||||
|
}
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
$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->exec('DROP TABLE smoke');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user