public static function getRoutes(Agency $agency, $version = 0) { /** * @var DB */ $dbObj = DBPool::getInstance(); $version = $version == 0 ? TableUpdate::getVersion() : $version; $dbObj->bindParams(array($agency->getId(), $version)); $routes = $dbObj->get_results("SELECT * FROM route WHERE agency_id=?\n AND version = ? ORDER BY position"); if ($dbObj->num_rows > 0) { $routeArray = array(); foreach ($routes as $r) { $routeObj = new Route(); $routeObj->setId($r->id); $routeObj->setAgency($agency); $routeObj->setTag($r->tag); $routeObj->setColor($r->color); $routeObj->setTitle($r->title); $routeObj->setShortTitle($r->short_title); $routeObj->setLatMin($r->lat_min); $routeObj->setLatMax($r->lat_max); $routeObj->setLonMin($r->lon_min); $routeObj->setLonMax($r->lon_max); $routeObj->setVehicleType($r->vehicle_type); $routeObj->setPosition($r->position); $routeArray[$r->tag] = $routeObj; } return $routeArray; } else { //TODO: Don't use a generic exception throw new Exception("No data available - Route::getRoutes"); } }
public function testBoolean() { foreach (DBTestPool::me()->getPool() as $db) { DBPool::me()->setDefault($db); //creating moscow $moscow = TestCity::create()->setName('Moscow'); $moscow = $moscow->dao()->add($moscow); $moscowId = $moscow->getId(); /* @var $moscow TestCity */ //now moscow capital $moscow->dao()->merge($moscow->setCapital(true)); TestCity::dao()->dropIdentityMap(); Criteria::create(TestCity::dao())->setSilent(false)->add(Expression::isTrue('capital'))->get(); TestCity::dao()->dropIdentityMap(); $moscow = Criteria::create(TestCity::dao())->setSilent(false)->add(Expression::isNull('large'))->get(); TestCity::dao()->dropIdentityMap(); //now moscow large $moscow = $moscow->dao()->merge($moscow->setLarge(true)); TestCity::dao()->dropIdentityMap(); $moscow = TestCity::dao()->getById($moscowId); $this->assertTrue($moscow->getCapital()); $this->assertTrue($moscow->getLarge()); Criteria::create(TestCity::dao())->setSilent(false)->add(Expression::not(Expression::isFalse('large')))->get(); TestCity::dao()->dropIdentityMap(); } }
/** * @group pi */ public function testCustomImportExport() { $dbs = DBTestPool::me()->getPool(); if (empty($dbs)) { $this->fail('For test required at least one DB in config'); } DBPool::me()->setDefault(reset($dbs)); $moscow = TestCity::create()->setCapital(true)->setName('Moscow'); $moscow->dao()->add($moscow); $stalingrad = TestCity::create()->setCapital(false)->setName('Stalingrad'); $stalingrad->dao()->add($stalingrad); $prms = array(); $prms[] = Primitive::identifier('city')->setScalar(true)->of('TestCity')->setMethodName('PrimitiveIdentifierTest::getCityByName')->setExtractMethod('PrimitiveIdentifierTest::getCityName'); $prms[] = Primitive::identifier('city')->setScalar(true)->of('TestCity')->setMethodName(array(get_class($this), 'getCityByName'))->setExtractMethod(function (TestCity $city) { return $city->getName(); }); foreach ($prms as $prm) { $prm->import(array('city' => 'Moscow')); $this->assertEquals($moscow, $prm->getValue()); $this->assertEquals('Moscow', $prm->exportValue()); $prm->importValue($stalingrad); $this->assertequals($stalingrad, $prm->getValue()); $this->assertequals('Stalingrad', $prm->exportValue()); $prm->import(array('city' => $moscow)); $this->assertEquals($moscow, $prm->getValue()); $this->assertEquals('Moscow', $prm->exportValue()); } }
public static function getStops(Agency $agency, $version = 0) { /** * @var DB */ $dbObj = DBPool::getInstance(); $version = $version == 0 ? TableUpdate::getVersion() : $version; $dbObj->bindParams(array($agency->getId(), TableUpdate::getVersion())); $stops = $dbObj->get_results("SELECT * FROM stop WHERE agency_id=?\n AND version = ?"); if ($dbObj->num_rows > 0) { $stopArray = array(); foreach ($stops as $s) { $stopObj = new Stop(); $stopObj->setId($s->id); $stopObj->setAgency($agency); $stopObj->setFlipStopTag($s->flip_stop_tag); $stopObj->setTag($s->tag); $stopObj->setTitle($s->title); $stopObj->setPrettyTitle($s->pretty_title); $stopObj->setLatitude($s->latitude); $stopObj->setLongitude($s->longitude); $stopArray[$s->tag] = $stopObj; } return $stopArray; } else { //TODO: Don't use a generic exception throw new Exception("No data available - Stop::getStops"); } }
public static function increment(DAOConnected &$object, array $fields, $refreshCurrent = true, $query = null) { $objectDao = $object->dao(); if ($query) { $updateQuery = $query; } else { $updateQuery = OSQL::update()->setTable($objectDao->getTable())->where(Expression::eqId('id', $object)); } $mapping = $objectDao->getProtoClass()->getMapping(); foreach ($mapping as $field => $column) { if (isset($fields[$field])) { $updateQuery->set($column, Expression::add($column, $fields[$field])); } } $updateCount = DBPool::getByDao($objectDao)->queryCount($updateQuery); if ($query) { $objectDao->uncacheLists(); } else { $objectDao->uncacheById($object->getId()); } if ($refreshCurrent && !$query) { $object = $objectDao->getById($object->getId()); } return $updateCount; }
/** * @return IOrmEntityAccessor */ function getDao() { if (!$this->dao) { $this->dao = new RdbmsDao(DBPool::getDefault(), $this); } return $this->dao; }
public static function getDirections(Route $route, $version = 0) { /** * @var DB */ $dbObj = DBPool::getInstance(); $version = $version == 0 ? TableUpdate::getVersion() : $version; $dbObj->bindParams(array($route->getId(), $version)); $directions = $dbObj->get_results("SELECT * FROM direction WHERE route_id=?\n AND version = ?"); if ($dbObj->num_rows > 0) { $directionArray = array(); foreach ($directions as $d) { $dirObj = new Direction(); $dirObj->setId($d->id); $dirObj->setName($d->name); $dirObj->setPrettyName($d->pretty_name); $dirObj->setRoute($route); $dirObj->setTag($d->tag); $dirObj->setTitle($d->title); $dirObj->setPrettyTitle($d->pretty_title); $dirObj->setUseForUi($d->use_for_ui); $dirObj->setShow($d->show); $directionArray[$d->tag] = $dirObj; } return $directionArray; } else { //TODO: Don't use a generic exception throw new Exception("No data available - Direction::getDirections"); } }
public function dropList() { $dao = $this->container->getDao(); DBPool::getByDao($dao)->queryNull(OSQL::delete()->from($this->container->getHelperTable())->where(Expression::eq($this->container->getParentIdField(), $this->container->getParentObject()->getId()))); $dao->uncacheLists(); return $this; }
/** * Install hstore * /usr/share/postgresql/contrib # cat hstore.sql | psql -U pgsql -d onphp **/ public function testHstore() { foreach (DBTestPool::me()->getPool() as $connector => $db) { DBPool::me()->setDefault($db); $properties = array('age' => '23', 'weight' => 80, 'comment' => null); $user = TestUser::create()->setCity($moscow = TestCity::create()->setName('Moscow'))->setCredentials(Credentials::create()->setNickname('fake')->setPassword(sha1('passwd')))->setLastLogin(Timestamp::create(time()))->setRegistered(Timestamp::create(time())->modify('-1 day'))->setProperties(Hstore::make($properties)); $moscow = TestCity::dao()->add($moscow); $user = TestUser::dao()->add($user); Cache::me()->clean(); TestUser::dao()->dropIdentityMap(); $user = TestUser::dao()->getById('1'); $this->assertInstanceOf('Hstore', $user->getProperties()); $this->assertEquals($properties, $user->getProperties()->getList()); $form = TestUser::proto()->makeForm(); $form->get('properties')->setFormMapping(array(Primitive::string('age'), Primitive::integer('weight'), Primitive::string('comment'))); $form->import(array('id' => $user->getId())); $this->assertNotNull($form->getValue('id')); $object = $user; FormUtils::object2form($object, $form); $this->assertInstanceOf('Hstore', $form->getValue('properties')); $this->assertEquals(array_filter($properties), $form->getValue('properties')->getList()); $subform = $form->get('properties')->getInnerForm(); $this->assertEquals($subform->getValue('age'), '23'); $this->assertEquals($subform->getValue('weight'), 80); $this->assertNull($subform->getValue('comment')); $user = new TestUser(); FormUtils::form2object($form, $user, false); $this->assertEquals($user->getProperties()->getList(), array_filter($properties)); } }
public static function eq(Query $query, $prefix = null) { if ($prefix === null) { $trace = debug_backtrace(); $prefix = basename($trace[0]['file']) . ':' . $trace[0]['line']; } error_log($prefix . ": " . $query->toDialectString(DBPool::me()->getLink()->getDialect())); }
/** * * @return Boolean - true if changes are present in the current version */ public static function changesPresentInCurrentVersion() { $dbObj = DBPool::getInstance(); $query = "SELECT changes_present FROM version WHERE id = " . TableUpdate::getVersion(); if (true == $dbObj->get_var($query)) { return true; } else { return false; } }
/** * @param DB|GenericDAO $database * @param IsolationLevel $level * @param AccessMode $mode **/ public function __construct($database, IsolationLevel $level = null, AccessMode $mode = null) { if ($database instanceof DB) { $this->db = $database; } elseif ($database instanceof GenericDAO) { $this->db = DBPool::getByDao($database); } else { throw new WrongStateException('$database must be instance of DB or GenericDAO'); } $this->beginTransaction($level, $mode); }
public function testLazy() { foreach (DBTestPool::me()->getPool() as $db) { DBPool::me()->setDefault($db); $parent = TestParentObject::create(); $child = TestChildObject::create()->setParent($parent); $parent->dao()->add($parent); $child->dao()->add($child); $this->assertEquals($parent->getId(), Criteria::create(TestChildObject::dao())->setProjection(Projection::property('parent.id', 'parentId'))->add(Expression::eq('id', $child->getId()))->getCustom('parentId')); } }
public function testCriteria() { foreach (DBTestPool::me()->getPool() as $db) { /* @var $db DB */ DBPool::me()->setDefault($db); $this->getDBCreator()->fillDB(); $queryResult = Criteria::create(TestCity::dao())->getResult(); $this->assertEquals(2, $queryResult->getCount()); Cache::me()->clean(); } }
public function testIpRangeProperty() { foreach (DBTestPool::me()->getPool() as $db) { DBPool::me()->setDefault($db); $akado = TestInternetProvider::create()->setName('Akada')->setRange(IpRange::create(IpAddress::create('192.168.1.1'), IpAddress::create('192.168.1.42'))); TestInternetProvider::dao()->add($akado); $plainRange = Criteria::create(TestInternetProvider::dao())->addProjection(Projection::property('range'))->add(Expression::eq('name', 'Akada'))->getCustom(); $this->assertEquals($plainRange['range'], '192.168.1.1-192.168.1.42'); TestInternetProvider::dao()->add(TestInternetProvider::create()->setName('DomRu')->setRange(IpRange::create('192.168.2.0/24'))); $list = Criteria::create(TestInternetProvider::dao())->addOrder('id')->getList(); $this->assertEquals(count($list), 2); } }
public static function getLink($driver) { global $lang; if (empty(self::$link)) { self::$link = mysql_connect($driver[DBHOST], $driver[DBUSER], $driver[DBPASSWORD]); if (!self::$link) { die($lang[DBCONNECTFAIL]); } if (!mysql_select_db($driver[DATABASE])) { die($lang[DBSELECTFAIL]); } } return self::$link; }
public function testRecursionObjects() { foreach (DBTestPool::me()->getPool() as $db) { DBPool::me()->setDefault($db); $parentProperties = Singleton::getInstance('ProtoTestParentObject')->getPropertyList(); $resultRoot = $parentProperties['root']->getFetchStrategyId() == FetchStrategy::LAZY; $childProperties = Singleton::getInstance('ProtoTestChildObject')->getPropertyList(); $resultParent = $childProperties['parent']->getFetchStrategyId() == FetchStrategy::LAZY; $selfRecursiveProperties = Singleton::getInstance('ProtoTestSelfRecursion')->getPropertyList(); $resultSelfRecursive = $selfRecursiveProperties['parent']->getFetchStrategyId() == FetchStrategy::LAZY; $this->assertTrue($resultRoot); $this->assertTrue($resultParent); $this->assertTrue($resultSelfRecursive); } }
function generateXMLFile(Agency $agencyObj) { $dbObj = DBPool::getInstance(); $routeArray = Route::getRoutes($agencyObj); $stopArray = Stop::getStops($agencyObj); $xmlStr = '<?xml version="1.0" encoding="UTF-8" ?><agency title="' . $agencyObj->getTitle() . '" shortTitle="' . $agencyObj->getShortTitle() . '"></agency>'; $xml = new SimpleXMLElement($xmlStr); foreach ($stopArray as $s) { $stop = $xml->addChild("stop"); $stop->addAttribute("tag", $s->getTag()); $stop->addAttribute("title", $s->getPrettyTitle()); $stop->addAttribute("lat", $s->getLatitude()); $stop->addAttribute("lon", $s->getLongitude()); $stop->addAttribute("oppositeStopTag", $s->getFlipStopTag()); } foreach ($routeArray as $r) { $route = $xml->addChild("route"); $route->addAttribute("tag", $r->getTag()); $route->addAttribute("title", $r->getTitle()); $route->addAttribute("shortTitle", $r->getShortTitle()); $route->addAttribute("color", $r->getColor()); $route->addAttribute("latMin", $r->getLatMin()); $route->addAttribute("latMax", $r->getLatMax()); $route->addAttribute("lonMin", $r->getLonMin()); $route->addAttribute("lonMax", $r->getLonMax()); $route->addAttribute("vehicle", $r->getVehicleType()); $route->addAttribute("sortOrder", $r->getPosition()); $directionsArray = Direction::getDirections($r); foreach ($directionsArray as $d) { $dir = $route->addChild("direction"); $dir->addAttribute("tag", $d->getTag()); $dir->addAttribute("title", $d->getPrettyTitle()); $dir->addAttribute("name", $d->getPrettyName()); $dir->addAttribute("show", $d->getShow() ? "true" : "false"); $dir->addAttribute("useForUI", $d->getUseForUi() ? "true" : "false"); $dbObj->bindParams(array($d->getId())); $stopDirMap = $dbObj->get_results("SELECT a.tag, b.position\n FROM stop as a, stop_direction_map as b\n WHERE a.id=b.stop_id AND b.direction_id=?\n ORDER BY b.position"); if ($dbObj->num_rows > 0) { foreach ($stopDirMap as $m) { $map = $dir->addChild("stop"); $map->addAttribute("tag", $m->tag); } } } } $fileName = Util::getBaseDirectoryPath(Util::XML_FILE) . $agencyObj->getShortTitle() . ".xml"; Util::prettyPrintXml($xml, $fileName); }
/** * @throws WrongArgumentException * @return ManyToManyLinkedLazy **/ public function sync($insert, $update = array(), $delete) { Assert::isTrue($update === array()); $dao = $this->container->getDao(); $db = DBPool::getByDao($dao); if ($insert) { for ($i = 0, $size = count($insert); $i < $size; ++$i) { $db->queryNull($this->makeInsertQuery($insert[$i])); } } if ($delete) { $db->queryNull($this->makeDeleteQuery($delete)); $dao->uncacheByIds($delete); } return $this; }
/** * @throws WrongArgumentException * @return OneToManyLinkedLazy **/ public function sync($insert, $update = array(), $delete) { Assert::isTrue($update === array()); $db = DBPool::getByDao($this->container->getDao()); $uc = $this->container; $dao = $uc->getDao(); if ($insert) { $db->queryNull($this->makeMassUpdateQuery($insert)); } if ($delete) { // unlink or drop $uc->isUnlinkable() ? $db->queryNull($this->makeMassUpdateQuery($delete)) : $db->queryNull(OSQL::delete()->from($dao->getTable())->where(Expression::in($uc->getChildIdField(), $delete))); $dao->uncacheByIds($delete); } return $this; }
/** * @throws BaseException * @return ModelAndView **/ public function run(Prototyped $subject, Form $form, HttpRequest $request) { Assert::isFalse($this->running, 'command already running'); Assert::isTrue($subject instanceof DAOConnected); $this->db = DBPool::getByDao($subject->dao()); $this->db->begin(); try { $mav = $this->command->run($subject, $form, $request); $this->running = true; return $mav; } catch (BaseException $e) { $this->db->rollback(); throw $e; } Assert::isUnreachable(); }
public function testGetByEmptyId() { foreach (DBTestPool::me()->getPool() as $db) { DBPool::me()->setDefault($db); $this->getByEmptyIdTest(0); $this->getByEmptyIdTest(null); $this->getByEmptyIdTest(''); $this->getByEmptyIdTest('0'); $this->getByEmptyIdTest(false); $empty = TestLazy::create(); $this->assertNull($empty->getCity()); $this->assertNull($empty->getCityOptional()); $this->assertNull($empty->getEnum()); $this->assertNull($empty->getStaticEnum()); } }
public static function suite() { $suite = new TestSuite('onPHP-' . ONPHP_VERSION); // meta, DB and DAOs ordered tests portion if (self::$dbs) { try { /** * @todo fail - constructor with argument, but static method 'me' - without */ Singleton::getInstance('DBTestPool', self::$dbs)->connect(); } catch (Exception $e) { Singleton::dropInstance('DBTestPool'); Singleton::getInstance('DBTestPool'); } // build stuff from meta $metaDir = ONPHP_TEST_PATH . 'meta' . DIRECTORY_SEPARATOR; $path = ONPHP_META_PATH . 'bin' . DIRECTORY_SEPARATOR . 'build.php'; $_SERVER['argv'] = array(); $_SERVER['argv'][0] = $path; $_SERVER['argv'][1] = $metaDir . 'config.inc.php'; $_SERVER['argv'][2] = $metaDir . 'config.meta.xml'; $_SERVER['argv'][] = '--force'; $_SERVER['argv'][] = '--no-schema-check'; $_SERVER['argv'][] = '--drop-stale-files'; include $path; AutoloaderPool::get('onPHP')->addPaths(array(ONPHP_META_AUTO_BUSINESS_DIR, ONPHP_META_AUTO_DAO_DIR, ONPHP_META_AUTO_PROTO_DIR, ONPHP_META_DAO_DIR, ONPHP_META_BUSINESS_DIR, ONPHP_META_PROTO_DIR)); $dBCreator = DBTestCreator::create()->setSchemaPath(ONPHP_META_AUTO_DIR . 'schema.php')->setTestPool(DBTestPool::me()); $out = MetaConfiguration::me()->getOutput(); foreach (DBTestPool::me()->getPool() as $connector => $db) { DBPool::me()->setDefault($db); $out->info('Using ')->info(get_class($db), true)->infoLine(' connector.'); $dBCreator->dropDB(true); $dBCreator->createDB()->fillDB(); MetaConfiguration::me()->checkIntegrity(); $out->newLine(); $dBCreator->dropDB(); } DBPool::me()->dropDefault(); } foreach (self::$paths as $testPath) { foreach (glob($testPath . '*Test' . EXT_CLASS, GLOB_BRACE) as $file) { $suite->addTestFile($file); } } return $suite; }
public static function getAgencies() { $dbObj = DBPool::getInstance(); $agencies = $dbObj->get_results("SELECT * FROM agency"); if ($dbObj->num_rows > 0) { $agencyArray = array(); foreach ($agencies as $a) { $agencyObj = new Agency(); $agencyObj->setId($a->id); $agencyObj->setTitle($a->title); $agencyObj->setShortTitle($a->short_title); $agencyObj->setDefaultVehicleType($a->default_vehicle); $agencyArray[$a->short_title] = $agencyObj; } return $agencyArray; } else { throw new Exception("There are no agencies in the database"); } }
protected static function connectModel($model, $host) { // cached handle is not null // and new host is null // use cached if (self::$db_handle !== null && $host === null) { $model->setDBH(self::$db_handle); } elseif ($host !== null) { // use a new host $dbh = DBPool::getConnection($host); $model->setDBH($dbh); } elseif (self::$db_handle == null && $host == null) { // db_handle is null and host is null // (initiate default) $handle = DBPool::getDefCX(); $model->setDBH($handle); self::$db_handle = $handle; } }
public function testInnerTransaction() { foreach (DBTestPool::me()->getPool() as $connector => $db) { DBPool::me()->setDefault($db); $this->getDBCreator()->fillDB(); $moscow = TestCity::dao()->getByLogic(Expression::eq('name', 'Moscow')); $piter = TestCity::dao()->getByLogic(Expression::eq('name', 'Saint-Peterburg')); $cityNewer = function (TestCity $city) { $city->dao()->merge($city->setName('New ' . $city->getName())); }; $citiesNewer = function ($moscow, $piter) use($cityNewer, $db) { $cityNewer($moscow); InnerTransactionWrapper::create()->setDB($db)->setFunction($cityNewer)->run($piter); }; InnerTransactionWrapper::create()->setDao($moscow->dao())->setFunction($citiesNewer)->run($moscow, $piter); $this->assertNotNull(TestCity::dao()->getByLogic(Expression::eq('name', 'New Moscow'))); $this->assertNotNull(TestCity::dao()->getByLogic(Expression::eq('name', 'New Saint-Peterburg'))); } }
public function updateStopDirMap() { /** * @var DB */ $dbObj = DBPool::getInstance(); $routeArray = Route::getRoutes($this->agency); $stopArray = Stop::getStops($this->agency); $bartApiKey = $this->appConfig['BART_API_KEY']; foreach ($routeArray as $routeTag => $routeObj) { $pos = 0; $directionArray = Direction::getDirections($routeObj); foreach ($directionArray as $dirTag => $dirObj) { //We're only interested in the directions we're showing if (!$dirObj->getShow()) { continue; } //Fetch the direction details $apiURL = str_replace(BartApiEndPoints::DIRECTION, $dirObj->getTag(), BartApiEndPoints::ROUTE_INFO . $bartApiKey); $dirInfoXmlBuilder = new XmlObjBuilder($apiURL); $dirInfoXml = $dirInfoXmlBuilder->getXmlObj(); foreach ($dirInfoXml->routes->route->config as $c) { foreach ($c as $station) { $pos++; $stopTag = (string) $station; $tempStopObj = $stopArray[$stopTag]; $stopId = $tempStopObj->getId(); $tempDirObj = $directionArray[$dirTag]; $dirId = $tempDirObj->getId(); $dbObj->bindParams(array($stopId, $dirId, $pos, TableUpdate::getVersion())); $dbObj->query("INSERT INTO stop_direction_map\n (stop_id, direction_id, position, version, created_date)\n VALUES (?, ?, ?, ?, NOW())"); if ($dbObj->rows_affected != 1) { //TODO: Log it } } //Stations } } //Directions } //Routes }
public function getDesiredSize() { $meta = $this->meta; $dbr = DBPool::get($meta['cluster'], $meta['dbname']); try { $res = $dbr->select('image', 'sum(img_size) as total'); } catch (DBQueryError $e) { return false; } foreach ($res as $row) { $total = $row->total; if ($total === null) { $total = false; } else { $total = intval($total); } return $total; } return false; }
/** * @return OneToManyLinkedFull **/ public function sync($insert, $update = array(), $delete) { $uc = $this->container; $dao = $uc->getDao(); if ($delete) { DBPool::getByDao($dao)->queryNull(OSQL::delete()->from($dao->getTable())->where(Expression::eq(new DBField($uc->getParentIdField()), $uc->getParentObject()->getId()))->andWhere(Expression::in($uc->getChildIdField(), ArrayUtils::getIdsArray($delete)))); $dao->uncacheByIds(ArrayUtils::getIdsArray($delete)); } if ($insert) { for ($i = 0, $size = count($insert); $i < $size; ++$i) { $dao->add($insert[$i]); } } if ($update) { for ($i = 0, $size = count($update); $i < $size; ++$i) { $dao->save($update[$i]); } } return $this; }
public function unified() { $user = TestUser::dao()->getById(1); $encapsulant = TestEncapsulant::dao()->getPlainList(); $collectionDao = $user->getEncapsulants(); $collectionDao->fetch()->setList($encapsulant); $collectionDao->save(); unset($collectionDao); // fetch $encapsulantsList = $user->getEncapsulants()->getList(); $piter = TestCity::dao()->getById(1); $moscow = TestCity::dao()->getById(2); for ($i = 0; $i < 10; $i++) { $this->assertEquals($encapsulantsList[$i]->getId(), $i + 1); $this->assertEquals($encapsulantsList[$i]->getName(), $i); $cityList = $encapsulantsList[$i]->getCities()->getList(); $this->assertEquals($cityList[0], $piter); $this->assertEquals($cityList[1], $moscow); } unset($encapsulantsList); // lazy fetch $encapsulantsList = $user->getEncapsulants(true)->getList(); for ($i = 1; $i < 11; $i++) { $this->assertEquals($encapsulantsList[$i], $i); } // count $user->getEncapsulants()->clean(); $this->assertEquals($user->getEncapsulants()->getCount(), 10); $criteria = Criteria::create(TestEncapsulant::dao())->add(Expression::in('cities.id', array($piter->getId(), $moscow->getId()))); $user->getEncapsulants()->setCriteria($criteria); $this->assertEquals($user->getEncapsulants()->getCount(), 20); // distinct count $user->getEncapsulants()->clean(); $user->getEncapsulants()->setCriteria($criteria->setDistinct(true)); if (DBPool::me()->getLink() instanceof SQLite) { // TODO: sqlite does not support such queries yet return null; } $this->assertEquals($user->getEncapsulants()->getCount(), 10); }