static function configure() { if (empty($_COOKIE['selenium'])) { return; } $cookie = $_COOKIE['selenium']; App::import('Model', 'ConnectionManager', false); ClassRegistry::flush(); Configure::write('Cache.disable', true); $testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects())); $_prefix = null; if ($testDbAvailable) { // Try for test DB restore_error_handler(); @($db =& ConnectionManager::getDataSource('test')); set_error_handler('simpleTestErrorHandler'); $testDbAvailable = $db->isConnected(); } // Try for default DB if (!$testDbAvailable) { $db =& ConnectionManager::getDataSource('default'); } $_prefix = $db->config['prefix']; $db->config['prefix'] = $cookie . '_'; ConnectionManager::create('test_suite', $db->config); $db->config['prefix'] = $_prefix; // Get db connection $db =& ConnectionManager::getDataSource('test_suite'); $db->cacheSources = false; ClassRegistry::config(array('ds' => 'test_suite')); }
protected static function _isDatasourceAvailable($datasource = 'default') { if (self::_instantiated($datasource)) { return true; } $sourceList = ConnectionManager::enumConnectionObjects(); return array_key_exists($datasource, $sourceList); }
/** * setUp * * @return void */ public function setUp() { parent::setUp(); $this->Model = new StripeAppModel(); $this->Model->setDataSource('stripe_test'); $sources = ConnectionManager::enumConnectionObjects(); $this->skipIf(!in_array('stripe_test', array_keys($sources)), '`stripe_test` db config not found'); }
/** * Sets up the environment for each test method * * @return void * @access public */ public function startTest() { $connections = ConnectionManager::enumConnectionObjects(); if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') { $config = new DATABASE_CONFIG(); $this->_config = $config->test; } ConnectionManager::create('mongo_test', $this->_config); }
/** * setUp * * @return void */ public function setUp() { parent::setUp(); $this->Model = new StripeCustomer(); $this->Model->setDataSource('stripe_test'); $sources = ConnectionManager::enumConnectionObjects(); $this->skipIf(!in_array('stripe_test', array_keys($sources)), '`stripe_test` db config not found'); $this->Source = $this->Model->getDataSource('stripe_test'); $this->Source->Http = $this->getMock('HttpSocket', array('request')); }
/** * Sets up the environment for each test method * * @return void * @access public */ public function startTest() { $connections = ConnectionManager::enumConnectionObjects(); if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') { $config = new DATABASE_CONFIG(); $this->_config = $config->test; } ConnectionManager::create('mongo_test', $this->_config); $this->Mongo = new MongodbSource($this->_config); $this->Post = ClassRegistry::init(array('class' => 'SqlCompatiblePost', 'alias' => 'Post', 'ds' => 'mongo_test')); $this->_setupData(); }
public function setUp() { $connections = ConnectionManager::enumConnectionObjects(); if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') { $config = new DATABASE_CONFIG(); $this->_config = $config->test; } if (!isset($connections['test_mongo'])) { ConnectionManager::create('test_mongo', $this->_config); $this->Mongo = new MongodbSource($this->_config); } $this->Post = ClassRegistry::init(array('class' => 'SqlCompatiblePost', 'alias' => 'Post', 'ds' => 'test_mongo'), true); }
/** * Get a user specified Connection name * * @return void */ public function getConfig() { App::uses('ConnectionManager', 'Model'); $configs = ConnectionManager::enumConnectionObjects(); $useDbConfig = key($configs); if (!is_array($configs) || empty($configs)) { return $this->execute(); } $connections = array_keys($configs); if (count($connections) > 1) { $useDbConfig = $this->in(__d('cake_console', 'Use Database Config') . ':', $connections, $useDbConfig); } return $useDbConfig; }
/** * Sets up the environment for each test method * * @return void * @access public */ public function startTest() { $connections = ConnectionManager::enumConnectionObjects(); if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') { $config = new DATABASE_CONFIG(); $this->_config = $config->test; } ConnectionManager::create('mongo_test', $this->_config); $this->Mongo = new MongodbSource($this->_config); $this->Post = ClassRegistry::init('Post'); $this->Post->setDataSource('mongo_test'); $this->mongodb =& ConnectionManager::getDataSource($this->Post->useDbConfig); $this->dropData(); }
private function getSlave() { if (!defined('APP_DEV') || APP_DEV) { return $this->useDbConfig; } $sources_list = ConnectionManager::enumConnectionObjects(); $slaves = array(); foreach ($sources_list as $name => $values) { if (preg_match('/^slave[0-9]+$/i', $name) == 1) { $slaves[] = $name; } } return $slaves[rand(0, count($slaves) - 1)]; }
protected function _initDb() { $testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects())); if ($testDbAvailable) { // Try for test DB restore_error_handler(); $db = ConnectionManager::getDataSource('test'); $testDbAvailable = $db->isConnected(); } // Try for default DB if (!$testDbAvailable) { $db = ConnectionManager::getDataSource('default'); $db->config['prefix'] = 'test_suite_'; } ConnectionManager::create('test_suite', $db->config); ClassRegistry::config(array('ds' => 'test_suite')); }
public function authorize($user, \CakeRequest $request) { $dbs = ConnectionManager::enumConnectionObjects(); $connNames = array_keys($dbs); $Apis = key($this->settings['Apis']) === 0 ? $this->settings['Apis'] : array_keys($this->settings['Apis']); $apiNames = array_intersect($Apis, $connNames); $authorized = true; foreach ($apiNames as $name) { $storeMethod = empty($this->settings['Apis'][$name]['store']) ? 'Db' : ucfirst($this->settings['Apis'][$name]['store']); $Store = $this->_getTokenStore($storeMethod); if ($Store instanceof TokenStoreInterface) { $allowed = $Store->checkToken($name, $user['id']); } $this->controller()->Apis[$name]['authorized'] = $allowed; if (!$allowed) { $authorized = false; } } return $authorized; }
/** * Initializes this class with a DataSource object to use as default for all fixtures * * @return void */ protected function _initDb() { if ($this->_initialized) { return; } $testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects())); $_prefix = null; if ($testDbAvailable) { // Try for test DB @($db = ConnectionManager::getDataSource('test')); $testDbAvailable = $db->isConnected(); } else { throw new MissingConnectionException(__('You need to create a $test datasource connection to start using fixtures')); } if (!$testDbAvailable) { throw new MissingConnectionException(__('Unable to connect to the $test datasource')); } $this->_db = $db; ClassRegistry::config(array('ds' => 'test')); $this->_initialized = true; }
/** * Truncates all tables and loads fixtures into db * * @return void * @access public */ function main() { if (!empty($this->args) && $this->args[0] != 'all') { $fixtures = $this->args; foreach ($fixtures as $i => $fixture) { $fixtures[$i] = APP . 'tests/fixtures/' . $fixture . '_fixture.php'; } } elseif (!empty($this->args) && $this->args[0] == 'all') { App::import('Folder'); $Folder = new Folder(APP . 'tests/fixtures'); $fixtures = $Folder->findRecursive('.+_fixture\\.php'); } else { $this->out('Usage: cake fixtures [ all | <table-name-singluar> ]'); return; } $datasource = 'default'; if (isset($this->params['datasource'])) { $datasource = $this->params['datasource']; } $list = ConnectionManager::enumConnectionObjects(); if (!isset($list[$datasource])) { $this->error("Data Source", "Non-existent data source '{$datasource}'"); } $db = ConnectionManager::getDataSource($datasource); $records = 0; foreach ($fixtures as $path) { require_once $path; $name = str_replace('_fixture.php', '', basename($path)); $class = Inflector::camelize($name) . 'Fixture'; $Fixture =& new $class($db); $this->out('-> Truncating table "' . $Fixture->table . '"'); $db->truncate($Fixture->table); $Fixture->insert($db); $fixtureRecords = count($Fixture->records); $records += $fixtureRecords; $this->out('-> Inserting ' . $fixtureRecords . ' records for "' . $Fixture->table . '"'); } $this->out(sprintf('-> Done inserting %d records for %d tables', $records, count($fixtures))); }
/** * Sets up the configuration for the model, and loads databse from Multi Tenant Site * * @param Model $model Model using this behavior. * @param array $config Configuration options. * @return void */ public function __construct($id = false, $table = null, $ds = null) { // usar el correspondiente al tenant //debug( Router::$_requests ); if (CakeSession::started()) { $currentTenant = MtSites::getSiteName(); if ($currentTenant) { // listar sources actuales $sources = ConnectionManager::enumConnectionObjects(); //copiar del default $tenantConf = $sources['default']; // colocar el nombre de la base de datos $tenantConf['database'] = $tenantConf['database'] . "_" . $currentTenant; // crear la conexion con la bd $confName = 'tenant_' . $currentTenant; ConnectionManager::create($confName, $tenantConf); // usar tenant para este model $this->useDbConfig = $confName; } } // ahora construir el Model parent::__construct($id, $table, $ds); }
function testHabtmWithThreeDatabases() { $config = ConnectionManager::enumConnectionObjects(); $this->skipIf(!isset($config['test']) || !isset($config['test2']) || !isset($config['test_database_three']), 'Primary, secondary, and tertiary test databases not configured, skipping test.' . ' To run these tests, you must define $test, $test2, and $test_database_three in your database configuration.'); $this->loadFixtures('Player', 'Guild', 'GuildsPlayer', 'Armor', 'ArmorsPlayer'); $Player = ClassRegistry::init('Player'); $Player->bindModel(array('hasAndBelongsToMany' => array('Armor' => array('with' => 'ArmorsPlayer', 'unique' => true))), false); $this->assertEquals('test', $Player->useDbConfig); $this->assertEquals('test2', $Player->Armor->useDbConfig); $this->assertEquals('test_database_three', $Player->ArmorsPlayer->useDbConfig); $players = $Player->find('count'); $this->assertEquals(4, $players); $spongebob = $Player->create(array('id' => 10, 'name' => 'spongebob')); $spongebob['Armor'] = array('Armor' => array(1, 2, 3, 4)); $result = $Player->save($spongebob); $expected = array('Player' => array('id' => 10, 'name' => 'spongebob'), 'Armor' => array('Armor' => array(1, 2, 3, 4, 1, 2, 3, 4))); unset($result['Player']['created']); unset($result['Player']['updated']); $this->assertEquals($expected, $result); $spongebob = $Player->find('all', array('conditions' => array('Player.id' => 10))); $spongeBobsArmors = Set::extract('/Armor', $spongebob); $this->assertEquals(4, count($spongeBobsArmors)); }
/** * Loads a class, registers the object in the registry and returns instance of the object. ClassRegistry::init() * is used as a factory for models, and handle correct injecting of settings, that assist in testing. * * Examples * Simple Use: Get a Post model instance ```ClassRegistry::init('Post');``` * * Expanded: ```array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry');``` * * Model Classes can accept optional ```array('id' => $id, 'table' => $table, 'ds' => $ds, 'alias' => $alias);``` * * When $class is a numeric keyed array, multiple class instances will be stored in the registry, * no instance of the object will be returned * ``` * array( * array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry'), * array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry'), * array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry') * ); * ``` * * @param string|array $class as a string or a single key => value array instance will be created, * stored in the registry and returned. * @param bool $strict if set to true it will return false if the class was not found instead * of trying to create an AppModel * @return object instance of ClassName. * @throws CakeException when you try to construct an interface or abstract class. */ public static function init($class, $strict = false) { $_this = ClassRegistry::getInstance(); if (is_array($class)) { $objects = $class; if (!isset($class[0])) { $objects = array($class); } } else { $objects = array(array('class' => $class)); } $defaults = array(); if (isset($_this->_config['Model'])) { $defaults = $_this->_config['Model']; } $count = count($objects); $availableDs = null; foreach ($objects as $settings) { if (is_numeric($settings)) { trigger_error(__d('cake_dev', '(ClassRegistry::init() Attempted to create instance of a class with a numeric name'), E_USER_WARNING); return false; } if (is_array($settings)) { $pluginPath = null; $settings += $defaults; $class = $settings['class']; list($plugin, $class) = pluginSplit($class); if ($plugin) { $pluginPath = $plugin . '.'; $settings['plugin'] = $plugin; } if (empty($settings['alias'])) { $settings['alias'] = $class; } $alias = $settings['alias']; $model = $_this->_duplicate($alias, $class); if ($model) { $_this->map($alias, $class); return $model; } App::uses($plugin . 'AppModel', $pluginPath . 'Model'); App::uses($class, $pluginPath . 'Model'); if (class_exists($class) || interface_exists($class)) { $reflection = new ReflectionClass($class); if ($reflection->isAbstract() || $reflection->isInterface()) { throw new CakeException(__d('cake_dev', 'Cannot create instance of %s, as it is abstract or is an interface', $class)); } $testing = isset($settings['testing']) ? $settings['testing'] : false; if ($testing) { $settings['ds'] = 'test'; $defaultProperties = $reflection->getDefaultProperties(); if (isset($defaultProperties['useDbConfig'])) { $useDbConfig = $defaultProperties['useDbConfig']; if ($availableDs === null) { $availableDs = array_keys(ConnectionManager::enumConnectionObjects()); } if (in_array('test_' . $useDbConfig, $availableDs)) { $useDbConfig = 'test_' . $useDbConfig; } if (strpos($useDbConfig, 'test') === 0) { $settings['ds'] = $useDbConfig; } } } if ($reflection->getConstructor()) { $instance = $reflection->newInstance($settings); } else { $instance = $reflection->newInstance(); } if ($strict && !$instance instanceof Model) { $instance = null; } } if (!isset($instance)) { $appModel = 'AppModel'; if ($strict) { return false; } elseif ($plugin && class_exists($plugin . 'AppModel')) { $appModel = $plugin . 'AppModel'; } $settings['name'] = $class; $instance = new $appModel($settings); } $_this->map($alias, $class); } } if ($count > 1) { return true; } return $instance; }
/** * testMultischemaFixtureWithThreeDatabases, three databases * * @return void */ public function testMultischemaFixtureWithThreeDatabases() { $config = ConnectionManager::enumConnectionObjects(); $this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.'); $this->skipIf(!isset($config['test']) || !isset($config['test2']) || !isset($config['test_database_three']), 'Primary, secondary, and tertiary test databases not configured, skipping test. To run this test define $test, $test2, and $test_database_three in your database configuration.'); $this->loadFixtures('Player', 'Guild', 'GuildsPlayer', 'Armor', 'ArmorsPlayer'); $Player = ClassRegistry::init('Player'); $Player->bindModel(array('hasAndBelongsToMany' => array('Armor' => array('with' => 'ArmorsPlayer'))), false); $this->assertEquals('test', $Player->useDbConfig); $this->assertEquals('test', $Player->Guild->useDbConfig); $this->assertEquals('test2', $Player->Guild->GuildsPlayer->useDbConfig); $this->assertEquals('test2', $Player->GuildsPlayer->useDbConfig); $this->assertEquals('test2', $Player->Armor->useDbConfig); $this->assertEquals('test_database_three', $Player->Armor->ArmorsPlayer->useDbConfig); $this->assertEquals('test', $Player->getDataSource()->configKeyName); $this->assertEquals('test', $Player->Guild->getDataSource()->configKeyName); $this->assertEquals('test2', $Player->GuildsPlayer->getDataSource()->configKeyName); $this->assertEquals('test2', $Player->Armor->getDataSource()->configKeyName); $this->assertEquals('test_database_three', $Player->Armor->ArmorsPlayer->getDataSource()->configKeyName); $players = $Player->find('all', array('recursive' => -1)); $guilds = $Player->Guild->find('all', array('recursive' => -1)); $guildsPlayers = $Player->GuildsPlayer->find('all', array('recursive' => -1)); $armorsPlayers = $Player->ArmorsPlayer->find('all', array('recursive' => -1)); $this->assertEquals(true, count($players) > 1); $this->assertEquals(true, count($guilds) > 1); $this->assertEquals(true, count($guildsPlayers) > 1); $this->assertEquals(true, count($armorsPlayers) > 1); }
/** * Tests that a connection configuration can be deleted in runtime * * @return void */ public function testDrop() { App::build(array('Model/Datasource' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS . 'Datasource' . DS))); ConnectionManager::create('droppable', array('datasource' => 'Test2Source')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEquals(array('datasource' => 'Test2Source'), $connections['droppable']); $this->assertTrue(ConnectionManager::drop('droppable')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertFalse(isset($connections['droppable'])); }
/** * testConnectionData method * * @access public * @return void */ function testConnectionData() { App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), 'datasources' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS . 'datasources' . DS))); $expected = array('filename' => 'test2_source', 'classname' => 'Test2Source', 'parent' => '', 'plugin' => ''); ConnectionManager::create('connection1', array('datasource' => 'Test2')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection1']); ConnectionManager::create('connection2', array('datasource' => 'Test2Source')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection2']); ConnectionManager::create('connection3', array('datasource' => 'TestPlugin.Test')); $connections = ConnectionManager::enumConnectionObjects(); $expected['filename'] = 'test_source'; $expected['classname'] = 'TestSource'; $expected['plugin'] = 'TestPlugin'; $this->assertEqual($expected, $connections['connection3']); ConnectionManager::create('connection4', array('datasource' => 'TestPlugin.TestSource')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection4']); ConnectionManager::create('connection5', array('datasource' => 'Test2Other')); $connections = ConnectionManager::enumConnectionObjects(); $expected['filename'] = 'test2_other_source'; $expected['classname'] = 'Test2OtherSource'; $expected['plugin'] = ''; $this->assertEqual($expected, $connections['connection5']); ConnectionManager::create('connection6', array('datasource' => 'Test2OtherSource')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection6']); ConnectionManager::create('connection7', array('datasource' => 'TestPlugin.TestOther')); $connections = ConnectionManager::enumConnectionObjects(); $expected['filename'] = 'test_other_source'; $expected['classname'] = 'TestOtherSource'; $expected['plugin'] = 'TestPlugin'; $this->assertEqual($expected, $connections['connection7']); ConnectionManager::create('connection8', array('datasource' => 'TestPlugin.TestOtherSource')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection8']); }
/** * Get a list of connection names. * * @return array The list of connection names */ protected function _connectionNamesEnum() { return array_keys(ConnectionManager::enumConnectionObjects()); }
/** * test reading schema with tables from another database. * * @return void */ public function testSchemaReadWithCrossDatabase() { $config = ConnectionManager::enumConnectionObjects(); $this->skipIf(!isset($config['test']) || !isset($config['test2']), 'Primary and secondary test databases not configured, ' . 'skipping cross-database join tests. ' . 'To run these tests, you must define $test and $test2 in your database configuration.'); $db = ConnectionManager::getDataSource('test2'); $fixture = new SchemaCrossDatabaseFixture(); $fixture->create($db); $fixture->insert($db); $read = $this->Schema->read(array('connection' => 'test', 'name' => 'TestApp', 'models' => array('SchemaCrossDatabase', 'SchemaPost'))); $this->assertTrue(isset($read['tables']['posts'])); $this->assertFalse(isset($read['tables']['cross_database']), 'Cross database should not appear'); $this->assertFalse(isset($read['tables']['missing']['cross_database']), 'Cross database should not appear'); $read = $this->Schema->read(array('connection' => 'test2', 'name' => 'TestApp', 'models' => array('SchemaCrossDatabase', 'SchemaPost'))); $this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear'); $this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear'); $this->assertTrue(isset($read['tables']['cross_database'])); $fixture->drop($db); }
/** * Mock a model, maintain fixtures and table association * * @param string $model The model to get a mock for. * @param mixed $methods The list of methods to mock * @param array $config The config data for the mock's constructor. * * @throws MissingModelException * @return Model */ public function getMockForModel($model, $methods = array(), $config = array()) { $config += ClassRegistry::config('Model'); list($plugin, $name) = pluginSplit($model, TRUE); App::uses($name, $plugin . 'Model'); $config = array_merge((array) $config, array('name' => $name)); unset($config['ds']); if (!class_exists($name)) { throw new MissingModelException(array($model)); } $mock = $this->getMock($name, $methods, array($config)); $availableDs = array_keys(ConnectionManager::enumConnectionObjects()); if ($mock->useDbConfig !== 'test' && in_array('test_' . $mock->useDbConfig, $availableDs)) { $mock->setDataSource('test_' . $mock->useDbConfig); } else { $mock->useDbConfig = 'test'; $mock->setDataSource('test'); } ClassRegistry::removeObject($name); ClassRegistry::addObject($name, $mock); return $mock; }
/** * testSchemaReadWithAppModel method * * @access public * @return void */ public function testSchemaReadWithAppModel() { $connections = ConnectionManager::enumConnectionObjects(); ConnectionManager::drop('default'); ConnectionManager::create('default', $connections['test']); try { $read = $this->Schema->read(array('connection' => 'default', 'name' => 'TestApp', 'models' => array('AppModel'))); } catch (MissingTableException $mte) { ConnectionManager::drop('default'); $this->fail($mte->getMessage()); } ConnectionManager::drop('default'); }
<?php require_once ROOT . DS . APP_DIR . DS . 'Plugin' . DS . 'FileStorage' . DS . 'Vendor' . DS . 'AWSsdk' . DS . 'aws-autoloader.php'; App::uses('S3StorageListener', 'FileStorage.Event'); App::uses('FileStorageUtils', 'FileStorage.Lib/Utility'); App::uses('StorageManager', 'FileStorage.Lib'); App::uses('ImageProcessingListener', 'FileStorage.Event'); App::uses('CakeEventManager', 'Event'); App::uses('ClassRegistry', 'Utility'); CakePlugin::load(array('Imagine' => array('bootstrap' => true))); Configure::write('Imagine.salt', 'T!6stub6f=as5e4U#u8u7!ut9wRuphUS'); // Only required if you're *NOT* using composer or another autoloader! spl_autoload_register(__NAMESPACE__ . '\\FileStorageUtils::gaufretteLoader'); // Attach the Image Processing Listener to the global CakeEventManager $listener = new ImageProcessingListener(); CakeEventManager::instance()->attach($listener); Configure::write('Media', array('imageSizes' => array('ImageStorage' => array('large' => array('thumbnail' => array('mode' => 'inbound', 'width' => 800, 'height' => 800)), 'medium' => array('thumbnail' => array('mode' => 'inbound', 'width' => 200, 'height' => 200)), 'small' => array('thumbnail' => array('mode' => 'inbound', 'width' => 80, 'height' => 80)))))); // This is very important! The hashes are needed to calculate the image versions! ClassRegistry::init('FileStorage.ImageStorage')->generateHashes(); use Aws\S3; App::uses('ConnectionManager', 'Model'); $dataSource = ConnectionManager::enumConnectionObjects(); if (isset($dataSource['aws'])) { // Attach the S3 Listener to the global CakeEventManager $listener = new S3StorageListener(); CakeEventManager::instance()->attach($listener); $S3Client = \Aws\S3\S3Client::factory($dataSource['aws']); StorageManager::config('S3Storage', array('adapterOptions' => array($S3Client, 'isby', array(), true), 'adapterClass' => '\\Gaufrette\\Adapter\\AwsS3', 'class' => '\\Gaufrette\\Filesystem')); }
/** * testCreateDataSource method * * @access public * @return void */ function testCreateDataSourceWithIntegrationTests() { $name = 'test_created_connection'; $connections = ConnectionManager::enumConnectionObjects(); $this->assertTrue(count(array_keys($connections) >= 1)); $source = ConnectionManager::getDataSource(key($connections)); $this->assertTrue(is_object($source)); $config = $source->config; $connection = ConnectionManager::create($name, $config); $this->assertTrue(is_object($connection)); $this->assertEqual($name, $connection->configKeyName); $this->assertEqual($name, ConnectionManager::getSourceName($connection)); $source = ConnectionManager::create(null, array()); $this->assertEqual($source, null); $source = ConnectionManager::create('another_test', array()); $this->assertEqual($source, null); $config = array('classname' => 'DboMysql', 'filename' => 'dbo' . DS . 'dbo_mysql'); $source = ConnectionManager::create(null, $config); $this->assertEqual($source, null); }
/** * connections method * * @return void * @access protected */ protected function _connections() { $this->out('Which connection do you want to see?'); $sources =& ConnectionManager::enumConnectionObjects(); $sources = array_keys($sources); foreach ($sources as $i => $source) { $this->out($i + 1 . '. ' . $source); } $this->out($i + 2 . '. * - list all'); $sources[] = '*'; $default = array_search('default', $sources) + 1; $source = ''; while ($source == '') { $source = $this->in(__d('mi', "Enter a number from the list above, or 'q' to exit", true), null, $default); if ($source === 'q') { $this->out(__d('mi', "Exit", true)); $this->_stop(); } if ($source == '' || !is_numeric($source) || $source > count($sources)) { $this->out(__d('mi', 'Error:', true)); $this->out(__d('mi', "The number you selected was not an option. Please try again.", true)); $controller = ''; } } $this->args[] = $sources[$source - 1]; }
/** * Adds the datasource to the connection manager if it's not already there, * which it won't be if you've not added it to your app/config/database.php * file. * * @param $id * @param $table * @param $ds */ public function __construct($id = false, $table = null, $ds = null) { $sources = ConnectionManager::enumConnectionObjects(); if (!isset($sources['twitter'])) { ConnectionManager::create('twitter', array('datasource' => 'Twim.TwimSource')); } parent::__construct($id, $table, $ds); }
/** * Initialize DB connection. * * @return void * @access protected */ function _initDb() { $testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects())); $_prefix = null; if ($testDbAvailable) { // Try for test DB restore_error_handler(); @($db =& ConnectionManager::getDataSource('test')); set_error_handler('simpleTestErrorHandler'); $testDbAvailable = $db->isConnected(); } // Try for default DB if (!$testDbAvailable) { $db =& ConnectionManager::getDataSource('default'); $_prefix = $db->config['prefix']; $db->config['prefix'] = 'test_suite_'; } ConnectionManager::create('test_suite', $db->config); $db->config['prefix'] = $_prefix; // Get db connection $this->db =& ConnectionManager::getDataSource('test_suite'); $this->db->cacheSources = false; ClassRegistry::config(array('ds' => 'test_suite')); }
/** * Sets up the environment for each test method * * @return void * @access public */ public function setUp() { $connections = ConnectionManager::enumConnectionObjects(); if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') { $config = new DATABASE_CONFIG(); $this->_config = $config->test; } elseif (isset($connections['test_mongo'])) { $this->_config = $connections['test_mongo']; } if (!isset($connections['test_mongo'])) { ConnectionManager::create('test_mongo', $this->_config); } $this->Mongo = new MongodbSource($this->_config); $this->Post = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Post', 'ds' => 'test_mongo'), true); $this->MongoArticle = ClassRegistry::init(array('class' => 'MongoArticle', 'alias' => 'MongoArticle', 'ds' => 'test_mongo'), true); $this->mongodb = ConnectionManager::getDataSource($this->Post->useDbConfig); $this->mongodb->connect(); }