dox Executable Documentation

Validate type

Boolean

$type = new BooleanType();
$this->assertTrue($type->is(true));
$this->assertTrue($type->is(false));
$this->assertFalse($type->is(0));
$this->assertEquals($type->__toString(), 'boolean');

Double

$type = new DoubleType();
$this->assertTrue($type->is(0.0));
$this->assertFalse($type->is(0));
$this->assertEquals($type->__toString(), 'double');

Float

$type = new FloatType();
$this->assertTrue($type->is(0.0));
$this->assertFalse($type->is(0));
$this->assertEquals($type->__toString(), 'float');

Long

$type = new LongType();
$this->assertTrue($type->is(0));
$this->assertFalse($type->is(0.0));
$this->assertEquals($type->__toString(), 'long');

Integer

$type = new IntegerType();
$this->assertTrue($type->is(0));
$this->assertFalse($type->is(0.0));
$this->assertEquals($type->__toString(), 'integer');

String

$type = new StringType();
$this->assertTrue($type->is('foo'));
$this->assertFalse($type->is(0));
$this->assertEquals($type->__toString(), 'string');

Array

$type = new ArrayType(new BooleanType());
$this->assertTrue($type->is(array()));
$this->assertTrue($type->is(array(true, false)));
$this->assertFalse($type->is(array(true, 0)));
$this->assertEquals($type->__toString(), 'boolean[]');

Class

$type = new ClassType(ValidateTypeTest_Foo::$CLASS);
$this->assertTrue($type->is(new ValidateTypeTest_Foo()));
$this->assertTrue($type->is(new ValidateTypeTest_Bar()));
$this->assertFalse($type->is(new \StdClass()));
$this->assertFalse($type->is('foo'));
$this->assertEquals($type->__toString(), ValidateTypeTest_Foo::$CLASS);

Multi

$type = new MultiType(array(new StringType(), new BooleanType()));
$this->assertTrue($type->is('foo'));
$this->assertTrue($type->is(true));
$this->assertFalse($type->is(0));
$this->assertEquals($type->__toString(), 'string|boolean');

Nullable

$type = new NullableType(new StringType());
$this->assertTrue($type->is(null));
$this->assertTrue($type->is('foo'));
$this->assertFalse($type->is(0));
$this->assertEquals($type->__toString(), 'null|string');

Null

$type = new NullType();
$this->assertTrue($type->is(null));
$this->assertFalse($type->is('foo'));
$this->assertEquals($type->__toString(), 'null');

Unknown

$type = new UnknownType('foo bar');
$this->assertTrue($type->is(null));
$this->assertTrue($type->is('foo'));
$this->assertTrue($type->is(0));
$this->assertEquals($type->__toString(), 'foo bar');

Unknwon unknown

$type = new UnknownType();
$this->assertTrue($type->is(null));
$this->assertTrue($type->is('foo'));
$this->assertTrue($type->is(0));
$this->assertEquals($type->__toString(), 'mixed');