Files
duckbrain/tests/Unit/BootstrapTest.php

58 lines
1.8 KiB
PHP

<?php
namespace Tests\Unit;
use PHPUnit\Framework\Attributes\Test;
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
{
#[Test]
public function frameworkClassesAreAutoloaded(): void
{
$this->assertTrue(
class_exists(Neuron::class),
'MISSING AUTOLOAD: autoload.php did not resolve Libs\Neuron; check ROOT_CORE and run from the project root'
);
$neuron = new Neuron(['key' => 'value']);
$this->assertSame('value', $neuron->key);
$this->assertNull($neuron->doesNotExist);
}
#[Test]
public function databaseConstantsPointToInMemorySqlite(): void
{
$this->assertSame(
'sqlite',
DB_TYPE,
'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 should be :memory: so tests never touch disks or servers');
}
#[Test]
public function testDatabaseIsUsable(): void
{
$db = self::db();
$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(['quack']);
$this->assertSame('quack', $db->query('SELECT v FROM smoke')->fetchColumn());
$db->exec('DROP TABLE smoke');
}
}