public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$Default = \jf\DatabaseManager::$DefaultIndex; $setting = \jf\DatabaseManager::Configuration(); $config = new \jf\DatabaseSetting("mysqli", $setting->DatabaseName, $setting->Username, $setting->Password, $setting->Host, $setting->TablePrefix); \jf\DatabaseManager::AddConnection($config, 2); \jf\DatabaseManager::$DefaultIndex = \jf\DatabaseManager::FindIndex($config); }
/** * @depends testAddConnection */ function testFindIndex() { $userConfig = \jf\DatabaseManager::Configuration("test"); $dbConfig = new \jf\DatabaseSetting($userConfig->Adapter, "db_find", $userConfig->Username, $userConfig->Password, $userConfig->Host, $userConfig->TablePrefix); \jf\DatabaseManager::AddConnection($dbConfig, "find_index"); $this->assertEquals("find_index", \jf\DatabaseManager::FindIndex($dbConfig)); $anotherConfig = new \jf\DatabaseSetting($userConfig->Adapter, "db_another_find", $userConfig->Username, $userConfig->Password, $userConfig->Host, $userConfig->TablePrefix); $this->assertFalse(\jf\DatabaseManager::FindIndex($anotherConfig)); }
function __construct() { $userConfig = \jf\DatabaseManager::Configuration(); switch ($userConfig->Adapter) { case "mysqli": case "pdo_mysql": case "mariaDB": $this->add("jf/test/lib/db/adapter/pdo_mysql"); $this->add("jf/test/lib/db/adapter/mysqli"); $this->add("jf/test/lib/db/adapter/mariaDB"); break; case "pdo_sqlite": $this->add("jf/test/lib/db/adapter/pdo_mysql"); break; } }
public static function Config($prefix = "app_") { self::$config = new Doctrine\ORM\Configuration(); // (2) // Proxy Configuration (3) self::$config->setProxyDir(__DIR__ . "/doctrine/proxy_cache"); self::$config->setProxyNamespace(jf_Application_Name . '\\Proxies'); self::$config->setAutoGenerateProxyClasses(jf::$RunMode->IsDevelop()); // Mapping Configuration (4) //$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(__DIR__."/entities/xml"); //$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(__DIR__."/config/mappings/yml"); $driverImpl = self::$config->newDefaultAnnotationDriver(__DIR__ . "/../model"); self::$config->setMetadataDriverImpl($driverImpl); // Caching Configuration (5) if (jf::$RunMode->IsDeploy() and function_exists("apc_exists")) { self::$cache = new \Doctrine\Common\Cache\ApcCache(); } else { self::$cache = new \Doctrine\Common\Cache\ArrayCache(); } self::$config->setMetadataCacheImpl(self::$cache); self::$config->setQueryCacheImpl(self::$cache); // database configuration parameters (6) $db = \jf\DatabaseManager::Configuration(); $adapter = $db->Adapter; if ($adapter == "mysql" or $adapter == "mysqli" or !$adapter) { $adapter = "pdo_mysql"; } $conn = array('driver' => $adapter, 'user' => $db->Username, 'password' => $db->Password, 'host' => $db->Host, 'dbname' => $db->DatabaseName, 'charset' => 'utf8', 'path' => $db->DatabaseName); require_once __DIR__ . "/doctrine/sqllogger.php"; self::$config->setSQLLogger(new Doctrine\DBAL\Logging\jframeworkSQLLogger()); // obtaining the entity manager (7) self::$eventManager = new Doctrine\Common\EventManager(); self::$tablePrefix = new \Doctrine\Extensions\TablePrefix($prefix); self::$eventManager->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, self::$tablePrefix); self::$entityManager = \Doctrine\ORM\EntityManager::create($conn, self::$config, self::$eventManager); }
function TablePrefix() { return \jf\DatabaseManager::Configuration()->TablePrefix; }