nur-sery/nur_tests/b/params/ParametrableTest.php

84 lines
2.4 KiB
PHP

<?php
namespace nur\b\params;
use nur\b\params\impl\BPB2;
use nur\b\params\impl\BPC1;
use nur\b\params\impl\BPC2;
use nur\b\params\impl\BPD1;
use nur\b\params\impl\BPD2;
use nur\b\params\impl\MyParametrable;
use nur\t\TestCase;
class ParametrableTest extends TestCase {
function testDefaults() {
$top = new BPC1();
self::assertSame([null, null, null, null], $top->getTopData());
$top->setParametrableParams(null);
self::assertSame([null, null, null, null], $top->getTopData());
$top->setParametrableParams([null, null, null, null]);
self::assertSame(["", null, false, null], $top->getTopData());
$sub = new BPC2();
self::assertSame([null, null, null, null, null, null, null, null], $sub->getSubData());
$sub->setParametrableParams(null);
self::assertSame([null, null, null, null, null, null, null, null], $sub->getSubData());
$sub->setParametrableParams([null, null, null, null, null, null, null, null]);
self::assertSame(["", null, false, null, "", null, false, null], $sub->getSubData());
}
function testDefaults2() {
Txx("od11");
$od11 = new BPD1();
self::assertSame([null, "boum", null, 18], $od11->od1Values());
Txx("od12");
$od12 = new BPD1([
"string" => "hello",
"nstring" => "world",
"int" => 15,
"nint" => 39,
]);
self::assertSame(["hello", "world", 15, 39], $od12->od1Values());
Txx("od21");
$od21 = new BPD2();
self::assertSame([42, 18, null, null], $od21->od2Values());
Txx("od22");
$od22 = new BPD2([
"int" => 15,
"nint" => 39,
"bool" => true,
"nbool" => false,
]);
self::assertSame([15, 39, true, false], $od22->od2Values());
}
function testProps() {
$second = new BPB2();
$second->setParametrableParams([
"first" => "premier",
"second" => "20",
]);
self::assertSame(["premier", 20], $second->getData());
}
function testMyParametrable() {
$p = new MyParametrable([
"name" => "plouf",
]);
self::assertSame("plouf", $p->getName());
self::assertNull($p->isActive());
self::assertNull($p->getNumber());
self::assertNull($p->whatIsMasked());
$p->setName("pouet");
self::assertSame("pouet", $p->getName());
$p->setNumber(2);
self::assertSame(12, $p->getNumber());
$p->setMasked("hidden");
self::assertNull($p->getMasked());
self::assertSame("hidden", $p->whatIsMasked());
}
}