RedUNIT\Base\Typechecking::testTypes PHP Method

testTypes() public method

Test how RedBeanPHP OODB and OODBBean handle type and type casts. Rules: 1. before storing a bean all types are preserved except booleans (they are converted to STRINGS '0' or '1') 2. after store-reload all bean property values are STRINGS or NULL (or ARRAYS but that's only from a user perspective because these are lazy loaded) 3. the ID returned by store() is an INTEGER (if possible; on 32 bit systems overflowing values will be cast to STRINGS!) After loading: ALL VALUES EXCEPT NULL -> STRING NULL -> NULL
public testTypes ( ) : void
return void
    public function testTypes()
    {
        testpack('Beans can only contain STRING and NULL after reload');
        R::nuke();
        $bean = R::dispense('bean');
        $bean->number = 123;
        $bean->float = 12.3;
        $bean->bool = false;
        $bean->bool2 = true;
        $bean->text = 'abc';
        $bean->null = null;
        $bean->datetime = new \DateTime('NOW', new \DateTimeZone('Europe/Amsterdam'));
        $id = R::store($bean);
        asrt(is_int($id), TRUE);
        asrt(is_float($bean->float), TRUE);
        asrt(is_integer($bean->number), TRUE);
        asrt(is_string($bean->bool), TRUE);
        asrt(is_string($bean->bool2), TRUE);
        asrt(is_string($bean->datetime), TRUE);
        asrt(is_string($bean->text), TRUE);
        asrt(is_null($bean->null), TRUE);
        $bean = R::load('bean', $id);
        asrt(is_string($bean->id), TRUE);
        asrt(is_string($bean->float), TRUE);
        asrt(is_string($bean->number), TRUE);
        asrt(is_string($bean->bool), TRUE);
        asrt(is_string($bean->bool2), TRUE);
        asrt(is_string($bean->datetime), TRUE);
        asrt(is_string($bean->text), TRUE);
        asrt(is_null($bean->null), TRUE);
        asrt($bean->bool, '0');
        asrt($bean->bool2, '1');
    }