/** * Test duplication and caching. * * @return void */ public function DupAndCache() { testpack('Dup() and Cache'); $can = R::dispense('can')->setAttr('size', 3); $can->ownCoffee[] = R::dispense('coffee')->setAttr('color', 'black'); $can->sharedTag[] = R::dispense('tag')->setAttr('name', 'cool'); $can = R::load('can', R::store($can)); $d = new RedBean_DuplicationManager(R::$toolbox); $d->setCacheTables(TRUE); ob_start(); R::debug(1); $x = $d->dup($can); $queries = ob_get_contents(); R::debug(0); ob_end_clean(); $len1 = strlen($queries); asrt($len1 > 40, TRUE); asrt(isset($x->ownCoffee), TRUE); asrt(count($x->ownCoffee), 1); asrt(isset($x->sharedTag), TRUE); asrt(count($x->sharedTag), 1); $cache = $d->getSchema(); R::nuke(); $can = R::dispense('can')->setAttr('size', 3); $can->ownCoffee[] = R::dispense('coffee')->setAttr('color', 'black'); $can->sharedTag[] = R::dispense('tag')->setAttr('name', 'cool'); $can = R::load('can', R::store($can)); $d = new RedBean_DuplicationManager(R::$toolbox); /** * $cache = '{"book": { * "id": "INTEGER", * "title": "TEXT" * }, "bean": { * "id": "INTEGER", * "prop": "INTEGER" * }, "pessoa": { * "id": "INTEGER", * "nome": "TEXT", * "nome_meio": "TEXT", * "sobrenome": "TEXT", * "nascimento": "NUMERIC", * "reg_owner": "TEXT" * }, "documento": { * "id": "INTEGER", * "nome_documento": "TEXT", * "numero_documento": "TEXT", * "reg_owner": "TEXT", * "ownPessoa_id": "INTEGER" * }, "can": { * "id": "INTEGER", * "size": "INTEGER" * }, "coffee": { * "id": "INTEGER", * "color": "TEXT", * "can_id": "INTEGER" * }, "tag": { * "id": "INTEGER", * "name": "TEXT" * }, "can_tag": { * "id": "INTEGER", * "tag_id": "INTEGER", * "can_id": "INTEGER" * }}' */ $d->setTables($cache, 1); ob_start(); R::debug(1); $x = $d->dup($can); $queries = ob_get_contents(); ob_end_clean(); R::debug(0); $len2 = strlen($queries); asrt(isset($x->ownCoffee), TRUE); asrt(count($x->ownCoffee), 1); asrt(isset($x->sharedTag), TRUE); asrt(count($x->sharedTag), 1); asrt(json_encode($cache), json_encode($d->getSchema())); asrt($len1 > $len2, TRUE); }