public function setUpDatabase() { // Use connection information from the generation config (and just add the aliases) include dirname(__FILE__) . '/config/database_schema_generator.inc.php'; $dbName = $config['dsn']['db_name']; $testDbConfig = $config['dsn']; $testDbConfig['aliases'] = array($dbName); CoughDatabaseFactory::addConfig($testDbConfig); $this->db = CoughDatabaseFactory::getDatabase($dbName); }
public function initDatabase() { // setup database require dirname(dirname(__FILE__)) . '/database_config.inc.php'; $testDbConfig = $dsn; $testDbConfig['adapter'] = $this->adapterName; $testDbConfig['aliases'] = array($dsn['db_name']); CoughDatabaseFactory::reset(); CoughDatabaseFactory::addConfig($testDbConfig); $this->db = CoughDatabaseFactory::getDatabase($dsn['db_name']); }
public function testGetDatabase() { // 2008-08-18/AWB: As of CoughPHP 1.3, an exception will be thrown with message // saying to check your config. It should mention something about // CoughDatabaseFactory::addConfig(), and possibly include a URL for more // documentation. // // trying to access a non-existing database object should return null // $this->assertNull(CoughDatabaseFactory::getDatabase('missingDbAlias')); // trying to access a non-existing database object should throw an exception try { CoughDatabaseFactory::getDatabase('missingDbAlias'); $threwException = false; } catch (Exception $e) { $threwException = true; } $this->assertTrue($threwException, 'Should throw an exception when DB alias does not exist.'); // test default adapter = "as" and old style "aliases" param $testDbConfig = array('driver' => 'mysql', 'host' => 'localhost', 'user' => 'cough_test', 'pass' => 'cough_test', 'port' => '3306', 'aliases' => array('cough_test1')); CoughDatabaseFactory::addConfig($testDbConfig); $test1Db = CoughDatabaseFactory::getDatabase('cough_test1'); $this->assertIsA($test1Db, 'CoughAsDatabase'); // test specifying adapter as "as" and new "db_name_hash" param $testDbConfig = array('adapter' => 'as', 'driver' => 'mysql', 'host' => 'localhost', 'user' => 'cough_test', 'pass' => 'cough_test', 'port' => '3306', 'db_name_hash' => array('cough_test2' => 'test_cough_object')); CoughDatabaseFactory::addConfig($testDbConfig); $test2Db = CoughDatabaseFactory::getDatabase('cough_test2'); $this->assertIsA($test2Db, 'CoughAsDatabase'); // test new style aliases param $testDbConfig = array('driver' => 'mysql', 'host' => 'localhost', 'user' => 'cough_test', 'pass' => 'cough_test', 'port' => '3306', 'aliases' => array('cough_test4' => 'test_cough_object')); CoughDatabaseFactory::addConfig($testDbConfig); $test4Db = CoughDatabaseFactory::getDatabase('cough_test4'); $this->assertIsA($test4Db, 'CoughAsDatabase'); // // test specifying adapter as "pdo" // $testDbConfig = array( // 'adapter' => 'pdo', // 'driver' => 'mysql', // 'host' => 'localhost', // 'user' => 'cough_test', // 'pass' => 'cough_test', // 'port' => '3306', // 'aliases' => array('cough_test3' => 'test_cough_object') // ); // CoughDatabaseFactory::addConfig($testDbConfig); // $test3Db = CoughDatabaseFactory::getDatabase('cough_test3'); // $this->assertIsA($test3Db, 'CoughPdoDatabaseAdapter'); // test getting the same database object back $test1DbReference = CoughDatabaseFactory::getDatabase('cough_test1'); $this->assertReference($test1Db, $test1DbReference); $this->assertIdentical($test1Db, $test1DbReference); $this->assertFalse($test2Db === $test1DbReference); // $this->assertFalse($test3Db === $test1DbReference); }
public function __construct() { // include cough generator, core cough, and the as_database DAL. $coughRoot = dirname(dirname(dirname(__FILE__))); require_once $coughRoot . '/cough_generator/load.inc.php'; require_once $coughRoot . '/cough/load.inc.php'; require_once $coughRoot . '/as_database/load.inc.php'; // Setup DB config require dirname(dirname(__FILE__)) . '/database_config.inc.php'; $coughDbConfig = $dsn; $coughDbConfig['aliases'] = array($dsn['db_name']); CoughDatabaseFactory::addConfig($coughDbConfig); // Cache the db object for rest of tests $this->db = CoughDatabaseFactory::getDatabase($dsn['db_name']); // Clean DB before start $this->dropAllTables(); }