예제 #1
0
 public function setUp()
 {
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     $this->sql = explode("\n", $sql);
     $this->sqlite = Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     $this->sqlite->cleanup();
 }
예제 #2
0
 protected function loadDump()
 {
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     $sql = explode("\n", $sql);
     $sqlite = \Codeception\Lib\Driver\Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     $sqlite->load($sql);
 }
예제 #3
0
 public function setUp()
 {
     try {
         $this->postgres = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
     } catch (\Exception $e) {
         $this->markTestSkipped('Coudn\'t establish connection to database');
     }
     $this->postgres->load(self::$sql);
 }
예제 #4
0
 public static function setUpBeforeClass()
 {
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     self::$sql = explode("\n", $sql);
     try {
         self::$sqlite = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
         self::$sqlite->cleanup();
     } catch (\Exception $e) {
     }
 }
예제 #5
0
 public function setUp()
 {
     $this->testCase = Stub::make('\\Codeception\\TestCase');
     $module = new \Codeception\Module\Dbh(make_container());
     try {
         $driver = Driver::create($this->config['dsn'], $this->config['user'], $this->config['password']);
         $module::$dbh = $driver->getDbh();
     } catch (\PDOException $e) {
         $this->markTestSkipped('Coudn\'t establish connection to database');
         return;
     }
     $this->module = $module;
 }
예제 #6
0
 public function setUp()
 {
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/mysql.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     $this->sql = explode("\n", $sql);
     try {
         $this->mysql = Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     } catch (\Exception $e) {
         $this->markTestSkipped('Coudn\'t establish connection to database');
         return;
     }
     $this->mysql->cleanup();
 }
예제 #7
0
 public function setUp()
 {
     if (!function_exists('pg_connect')) {
         return $this->markTestSkipped("Postgres extensions not loaded");
     }
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/postgres.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     $this->sql = explode("\n", $sql);
     try {
         $this->postgres = Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     } catch (\Exception $e) {
         $this->markTestSkipped('Coudn\'t establish connection to database');
         return;
     }
     $this->postgres->cleanup();
 }
예제 #8
0
 public static function setUpBeforeClass()
 {
     if (!function_exists('pg_connect')) {
         return;
     }
     if (getenv('APPVEYOR')) {
         self::$config['password'] = '******';
     }
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/postgres.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     self::$sql = explode("\n", $sql);
     try {
         self::$postgres = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
         self::$postgres->cleanup();
     } catch (\Exception $e) {
     }
 }
예제 #9
0
파일: Db.php 프로젝트: namnv609/Codeception
 private function connect()
 {
     try {
         $this->driver = Driver::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     } catch (\PDOException $e) {
         $message = $e->getMessage();
         if ($message === 'could not find driver') {
             list($missingDriver, ) = explode(':', $this->config['dsn'], 2);
             $message = "could not find {$missingDriver} driver";
         }
         throw new ModuleException(__CLASS__, $message . ' while creating PDO connection');
     }
     $this->dbh = $this->driver->getDbh();
 }
예제 #10
0
 /**
  * @see MultiDb::amConnectedToDb
  *
  * @param string $connector
  *
  * @throws ModuleException
  * @return \Codeception\Lib\Driver\Db
  */
 private function getDriver($connector)
 {
     if (!(isset($this->drivers[$connector]) && is_object($this->drivers[$connector]))) {
         if (!isset($this->config['connectors'][$connector])) {
             throw new ModuleException(__CLASS__, "The specified connector, {$connector}, does not exist in the configuration");
         }
         $config = $this->config['connectors'][$connector];
         try {
             $this->drivers[$connector] = Driver::create($config['dsn'], $config['user'], $config['password']);
             $this->executeSqlAgainstDriver($this->drivers[$connector]->getDbh(), "SET time_zone = '{$this->timezone}'");
         } catch (\PDOException $e) {
             throw new ModuleException(__CLASS__, $e->getMessage() . ' while creating PDO connection [' . get_class($e) . ']');
         } catch (\Exception $e) {
             throw new ModuleException(__CLASS__, $e->getMessage() . ' while creating PDO connection [' . get_class($e) . ']');
         }
     }
     return $this->drivers[$connector];
 }
예제 #11
0
파일: Db.php 프로젝트: kansey/yii2albom
 public function _initialize()
 {
     if ($this->config['dump'] && ($this->config['cleanup'] or $this->config['populate'])) {
         if (!file_exists(Configuration::projectDir() . $this->config['dump'])) {
             throw new ModuleConfigException(__CLASS__, "\nFile with dump doesn't exist.\n                    Please, check path for sql file: " . $this->config['dump']);
         }
         $sql = file_get_contents(Configuration::projectDir() . $this->config['dump']);
         $sql = preg_replace('%/\\*(?!!\\d+)(?:(?!\\*/).)*\\*/%s', "", $sql);
         if (!empty($sql)) {
             $this->sql = explode("\n", $sql);
         }
     }
     try {
         $this->driver = Driver::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     } catch (\PDOException $e) {
         $message = $e->getMessage();
         if ($message === 'could not find driver') {
             list($missingDriver, ) = explode(':', $this->config['dsn'], 2);
             $message = "could not find {$missingDriver} driver";
         }
         throw new ModuleException(__CLASS__, $message . ' while creating PDO connection');
     }
     $this->dbh = $this->driver->getDbh();
     // starting with loading dump
     if ($this->config['populate']) {
         if ($this->config['cleanup']) {
             $this->cleanup();
         }
         $this->loadDump();
         $this->populated = true;
     }
 }
예제 #12
0
 public function testThrowsExceptionIfInMemoryDatabaseIsUsed()
 {
     $this->setExpectedException('\\Codeception\\Exception\\ModuleException', ':memory: database is not supported');
     Db::create('sqlite::memory:', '', '');
 }