70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
|
<?php
|
||
|
namespace nur\sery\wip\php\access;
|
||
|
|
||
|
use nulib\tests\TestCase;
|
||
|
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));
|
||
|
}
|
||
|
}
|