/** * Purge ConnectionManager configs. * * @return void */ public static function tearDownAfterClass() { foreach (self::$datasources as $ds => $configs) { \Cake\Datasource\ConnectionManager::drop($ds); } \Cake\Utility\Security::salt(''); }
/** * Tests the junction passes the source connection name on. * * @return void */ public function testJunctionConnection() { $mock = $this->getMockBuilder('Cake\\Database\\Connection')->setMethods(['driver'])->setConstructorArgs(['name' => 'other_source'])->getMock(); ConnectionManager::config('other_source', $mock); $this->article->connection(ConnectionManager::get('other_source')); $assoc = new BelongsToMany('Test', ['sourceTable' => $this->article, 'targetTable' => $this->tag]); $junction = $assoc->junction(); $this->assertSame($mock, $junction->connection()); ConnectionManager::drop('other_source'); }
public function tearDown() { ConnectionManager::drop('twitter'); StreamWrapper::restoreWrapper('https'); }
/** * Tests that a connection configuration can be deleted in runtime * * @return void */ public function testDrop() { ConnectionManager::config('test_variant', ['className' => __NAMESPACE__ . '\\FakeConnection', 'database' => ':memory:']); $result = ConnectionManager::configured(); $this->assertContains('test_variant', $result); $this->assertTrue(ConnectionManager::drop('test_variant')); $result = ConnectionManager::configured(); $this->assertNotContains('test_variant', $result); $this->assertFalse(ConnectionManager::drop('probably_does_not_exist'), 'Should return false on failure.'); }
<?php /** * Test runner bootstrap. * * Add additional configuration/setup your application needs when running * unit tests in this file. */ use Cake\Datasource\ConnectionManager; require 'test-app/config/bootstrap.php'; if (!getenv('db_dsn')) { putenv('db_dsn=sqlite:///:memory:'); } ConnectionManager::drop('test'); ConnectionManager::config('test', ['url' => getenv('db_dsn')]);
/** * Generates a new connection to DB. * * @return \Cake\Database\Connection|bool A connection object, or false on * failure. On failure error messages are automatically set */ public function getConn() { if (!$this->config('connection.className')) { $this->error(__d('installer', 'Database engine cannot be empty.')); return false; } try { ConnectionManager::drop('installation'); ConnectionManager::config('installation', $this->config('connection')); $conn = ConnectionManager::get('installation'); $conn->connect(); return $conn; } catch (\Exception $ex) { $this->error(__d('installer', 'Unable to connect to database, please check your information. Details: {0}', '<p>' . $ex->getMessage() . '</p>')); return false; } }
/** * Removes all tables in current installation DB. * * @return void */ protected function _dropTables() { // drop all tables ConnectionManager::drop('installation'); ConnectionManager::config('installation', $this->_getConn()); $db = ConnectionManager::get('installation'); $db->connect(); $tables = $db->schemaCollection()->listTables(); foreach ($tables as $table) { $Table = TableRegistry::get($table, ['connection' => $db]); $schema = $Table->schema(); $sql = $schema->dropSql($db); foreach ($sql as $stmt) { $db->execute($stmt)->closeCursor(); } } unset($db); ConnectionManager::drop('installation'); }
public function tearDown() { ConnectionManager::drop('twitter'); }