71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
namespace nur\sery\php\access;
|
|
|
|
use nulib\tests\TestCase;
|
|
use nur\sery\wip\php\access\ValueAccess;
|
|
use stdClass;
|
|
|
|
class ValueAccessTest extends TestCase {
|
|
function testAccess() {
|
|
$default = new stdClass();
|
|
|
|
#
|
|
$i = null;
|
|
$a = new ValueAccess($i);
|
|
self::assertFalse($a->exists());
|
|
self::assertFalse($a->available());
|
|
self::assertSame($default, $a->get($default));
|
|
|
|
$i = false;
|
|
$a = new ValueAccess($i);
|
|
self::assertTrue($a->exists());
|
|
self::assertTrue($a->available());
|
|
self::assertSame(false, $a->get($default));
|
|
|
|
$i = "";
|
|
$a = new ValueAccess($i);
|
|
self::assertTrue($a->exists());
|
|
self::assertTrue($a->available());
|
|
self::assertSame("", $a->get($default));
|
|
|
|
#
|
|
$i = null;
|
|
$a = new ValueAccess($i, ["allow_null" => false]);
|
|
self::assertFalse($a->exists());
|
|
self::assertFalse($a->available());
|
|
self::assertSame($default, $a->get($default));
|
|
|
|
$i = null;
|
|
$a = new ValueAccess($i, ["allow_null" => true]);
|
|
self::assertTrue($a->exists());
|
|
self::assertTrue($a->available());
|
|
self::assertSame(null, $a->get($default));
|
|
|
|
#
|
|
$i = false;
|
|
$a = new ValueAccess($i, ["allow_false" => false]);
|
|
self::assertTrue($a->exists());
|
|
self::assertFalse($a->available());
|
|
self::assertSame($default, $a->get($default));
|
|
|
|
$i = false;
|
|
$a = new ValueAccess($i, ["allow_false" => true]);
|
|
self::assertTrue($a->exists());
|
|
self::assertTrue($a->available());
|
|
self::assertSame(false, $a->get($default));
|
|
|
|
#
|
|
$i = "";
|
|
$a = new ValueAccess($i, ["allow_empty" => false]);
|
|
self::assertTrue($a->exists());
|
|
self::assertFalse($a->available());
|
|
self::assertSame($default, $a->get($default));
|
|
|
|
$i = "";
|
|
$a = new ValueAccess($i, ["allow_empty" => true]);
|
|
self::assertTrue($a->exists());
|
|
self::assertTrue($a->available());
|
|
self::assertSame("", $a->get($default));
|
|
}
|
|
}
|