70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
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
|
|
{
|
|
#[Test]
|
|
public function constructFromAssociativeArray(): void
|
|
{
|
|
$n = new Neuron(['username' => 'kj', 'level' => 3]);
|
|
|
|
$this->assertSame('kj', $n->username);
|
|
$this->assertSame(3, $n->level);
|
|
}
|
|
|
|
#[Test]
|
|
|
|
public function constructFromObjectCopiesPublicProperties(): 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);
|
|
}
|
|
|
|
#[Test]
|
|
|
|
public function undefinedPropertyIsNullWithoutNotice(): void
|
|
{
|
|
$n = new Neuron();
|
|
|
|
$this->assertNull($n->thisDoesNotExist);
|
|
}
|
|
|
|
#[Test]
|
|
|
|
public function dynamicPropertiesCanBeAssignedAndRead(): void
|
|
{
|
|
$n = new Neuron();
|
|
$n->fresh = ['a', 'b'];
|
|
|
|
$this->assertSame(['a', 'b'], $n->fresh);
|
|
}
|
|
|
|
#[Test]
|
|
|
|
public function nestedValuesArePreservedVerbatim(): void
|
|
{
|
|
$payload = ['meta' => ['tags' => ['x', 'y'], 'n' => null]];
|
|
$n = new Neuron($payload);
|
|
|
|
$this->assertSame($payload['meta'], $n->meta);
|
|
$this->assertNull($n->meta['n']);
|
|
}
|
|
}
|