lithium\tests\cases\data\collection\DocumentSetTest::testInitialCastingOnSubObject PHP Method

testInitialCastingOnSubObject() public method

    public function testInitialCastingOnSubObject()
    {
        $model = $this->_model;
        $schema = new DocumentSchema(array('fields' => array('_id' => array('type' => 'id'), 'body' => array('type' => 'string'), 'foo' => array('type' => 'object'), 'foo.bar' => array('type' => 'int')), 'types' => array('int' => 'integer'), 'handlers' => array('integer' => function ($v) {
            return (int) $v;
        })));
        $array = new DocumentSet(compact('model', 'schema') + array('data' => array(array('_id' => '4cb4ab6d7addf98506010002', 'body' => 'body1', 'foo' => (object) array('bar' => '1')), array('_id' => '4cb4ab6d7addf98506010003', 'body' => 'body2', 'foo' => (object) array('bar' => '2')), array('_id' => '4cb4ab6d7addf98506010004', 'body' => 'body3', 'foo' => (object) array('bar' => '3')))));
        foreach ($array as $document) {
            $this->assertInternalType('string', $document->_id);
            $this->assertInternalType('string', $document->body);
            $this->assertInternalType('object', $document->foo);
            $this->assertInternalType('string', $document->foo->bar);
        }
        $array = new DocumentSet(compact('model', 'schema') + array('data' => array(array('_id' => '4cb4ab6d7addf98506010002', 'body' => 'body1', 'foo' => array('bar' => '1')), array('_id' => '4cb4ab6d7addf98506010003', 'body' => 'body2', 'foo' => array('bar' => '2')), array('_id' => '4cb4ab6d7addf98506010004', 'body' => 'body3', 'foo' => array('bar' => '3')))));
        foreach ($array as $document) {
            $this->assertInternalType('string', $document->_id);
            $this->assertInternalType('string', $document->body);
            $this->assertInternalType('object', $document->foo);
            $this->assertInternalType('int', $document->foo->bar);
        }
    }