test(unit): Add Neuron and Validator regression tests
This commit is contained in:
59
tests/Unit/NeuronTest.php
Normal file
59
tests/Unit/NeuronTest.php
Normal 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']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user