/** * set up environment with yii application and migrate up db */ public function setUp() { $basePath = dirname(__FILE__) . '/tmp'; if (!file_exists($basePath)) { mkdir($basePath, 0777, true); } if (!file_exists($basePath . '/runtime')) { mkdir($basePath . '/runtime', 0777, true); } // create webapp if (\Yii::app() === null) { \Yii::createWebApplication(array('basePath' => $basePath)); } \CActiveRecord::$db = null; if (!isset($_ENV['DB']) || $_ENV['DB'] == 'sqlite') { if (!$this->dbFile) { $this->dbFile = $basePath . '/test.' . uniqid(time()) . '.db'; } \Yii::app()->setComponent('db', new \CDbConnection('sqlite:' . $this->dbFile)); } elseif ($_ENV['DB'] == 'mysql') { \Yii::app()->setComponent('db', new \CDbConnection('mysql:dbname=test;host=localhost', 'root')); } elseif ($_ENV['DB'] == 'pgsql') { \Yii::app()->setComponent('db', new \CDbConnection('pqsql:dbname=test;host=localhost', 'postgres')); } else { throw new \Exception('Unknown db. Only sqlite, mysql and pgsql are valid.'); } // create db $this->migration = new EActiveRecordRelationBehaviorTestMigration(); $this->migration->dbConnection = \Yii::app()->db; $this->migration->up(); }
/** * set up environment with yii application and migrate up db */ public function setUp() { $basePath = dirname(__FILE__) . '/tmp'; if (!file_exists($basePath)) { mkdir($basePath, 0777, true); } if (!file_exists($basePath . '/runtime')) { mkdir($basePath . '/runtime', 0777, true); } if (!$this->db) { $this->db = $basePath . '/test.' . uniqid(time()) . '.db'; } // create webapp if (\Yii::app() === null) { \Yii::createWebApplication(array('basePath' => $basePath)); } \CActiveRecord::$db = null; \Yii::app()->setComponent('db', new \CDbConnection('sqlite:' . $this->db)); // create db $this->migration = new EActiveRecordRelationBehaviorTestMigration(); $this->migration->dbConnection = \Yii::app()->db; $this->migration->up(); }