diff options
author | wei <> | 2006-12-17 22:20:50 +0000 |
---|---|---|
committer | wei <> | 2006-12-17 22:20:50 +0000 |
commit | 2570226fbac3e26b1e94896b50d1db4bc1aa3308 (patch) | |
tree | 421108ccbdc0ef021e6af4fa35b1d6bcbc352b37 /demos/time-tracker/tests/unit/BaseTestCase.php | |
parent | ddc0de38f64e5834ce04f0407a8416172b596655 (diff) |
Add TDataSourceConfig, TSqlMapConfig, TActiveRecordConfig
Diffstat (limited to 'demos/time-tracker/tests/unit/BaseTestCase.php')
-rw-r--r-- | demos/time-tracker/tests/unit/BaseTestCase.php | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/demos/time-tracker/tests/unit/BaseTestCase.php b/demos/time-tracker/tests/unit/BaseTestCase.php index 549229e3..7e4520f8 100644 --- a/demos/time-tracker/tests/unit/BaseTestCase.php +++ b/demos/time-tracker/tests/unit/BaseTestCase.php @@ -6,44 +6,49 @@ Prado::using('Application.App_Code.Dao.*'); class BaseTestCase extends UnitTestCase
{
protected $sqlmap;
-
+
function setup()
{
$app = Prado::getApplication();
- $this->sqlmap = $app->getModule('daos')->getConnection();
+ $this->sqlmap = $app->getModule('daos')->getClient();
}
-
-
+
+
function flushDatabase()
{
- $conn = $this->sqlmap->openConnection();
- switch(strtolower($conn->getProvider()->getDriver()))
+ $conn = $this->sqlmap->getDbConnection();
+ $find = 'sqlite:protected';
+ if(is_int(strpos($conn->getConnectionString(),$find)))
+ $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString);
+ $conn->setActive(false);
+ $conn->setActive(true);
+ switch(strtolower($conn->getDriverName()))
{
case 'mysql':
return $this->flushMySQLDatabase();
case 'sqlite':
- return $this->flushSQLiteDatabase();
- }
+ return $this->flushSQLiteDatabase();
+ }
}
-
+
function flushSQLiteDatabase()
{
- $conn = $this->sqlmap->openConnection();
- $file = $conn->getProvider()->getHost();
+ $conn = $this->sqlmap->getDbConnection();
+ $file = str_replace('sqlite:','',$conn->getConnectionString());
$backup = $file.'.bak';
copy($backup, $file);
}
-
+
function flushMySQLDatabase()
{
- $conn = $this->sqlmap->openConnection();
+ $conn = $this->sqlmap->getDbConnection();
$file = Prado::getPathOfNamespace('Application.App_Data.mysql-reset','.sql');
if(is_file($file))
$this->runScript($conn, $file);
else
throw new Exception('unable to find script file '.$file);
}
-
+
protected function runScript($connection, $script)
{
$sql = file_get_contents($script);
|