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

59
tests/Unit/NeuronTest.php Normal file
View File

@@ -0,0 +1,59 @@
<?php
namespace Tests\Unit;
use Libs\Neuron;
use Tests\TestCase;
/**
* NeuronTest - DuckBrain test harness
*
* Regression net para el contenedor de valores del core: construcción
* desde array/objeto, propiedades dinámicas y null en inexistentes.
*/
final class NeuronTest extends TestCase
{
public function testConstructFromAssociativeArray(): void
{
$n = new Neuron(['username' => 'kj', 'level' => 3]);
$this->assertSame('kj', $n->username);
$this->assertSame(3, $n->level);
}
public function testConstructFromObjectCopiesPublicProperties(): void
{
$source = new \stdClass();
$source->id = 7;
$source->email = 'kj@example.com';
$n = new Neuron($source);
$this->assertSame(7, $n->id);
$this->assertSame('kj@example.com', $n->email);
}
public function testUndefinedPropertyIsNullWithoutNotice(): void
{
$n = new Neuron();
$this->assertNull($n->thisDoesNotExist);
}
public function testDynamicPropertiesCanBeAssignedAndRead(): void
{
$n = new Neuron();
$n->fresh = ['a', 'b'];
$this->assertSame(['a', 'b'], $n->fresh);
}
public function testNestedValuesArePreservedVerbatim(): void
{
$payload = ['meta' => ['tags' => ['x', 'y'], 'n' => null]];
$n = new Neuron($payload);
$this->assertSame($payload['meta'], $n->meta);
$this->assertNull($n->meta['n']);
}
}