-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDBTNG_PHPUnit_Framework_TestCase.php
More file actions
40 lines (33 loc) · 1.44 KB
/
Copy pathDBTNG_PHPUnit_Framework_TestCase.php
File metadata and controls
40 lines (33 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class DBTNG_PHPUnit_Framework_TestCase extends PHPUnit_Framework_TestCase {
protected $databasePrefix;
public function __construct() {
parent::__construct();
$settings = realpath(dirname(__FILE__) . '/../settings.php');
require_once $settings;
}
public function setUp() {
$this->databasePrefix = 'dbtngtest' . mt_rand(1000, 1000000);
// Clone the current connection and replace the current prefix.
$connection_info = Database::getConnectionInfo('default');
Database::renameConnection('default', 'dbtng_original_default');
foreach ($connection_info as $target => $value) {
$connection_info[$target]['prefix'] = array(
'default' => $value['prefix']['default'] . $this->databasePrefix,
);
}
Database::addConnectionInfo('default', 'default', $connection_info['default']);
}
public function tearDown() {
// This would be better if it were database specific, but for now we'll
// live with information_schema.
$connection_info = Database::getConnectionInfo('default');
$result = db_query("SELECT table_name FROM information_schema.tables WHERE table_catalog = '" . $connection_info['database'] . "' AND table_schema = 'public'")->fetchAll();
foreach ($result as $row) {
db_drop_table($row->table_name);
}
// Get back to the original connection.
Database::removeConnection('default');
Database::renameConnection('dbtng_original_default', 'default');
}
}