Exemplo n.º 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();
 }
Exemplo n.º 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\Util\Driver\Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     $sqlite->load($sql);
 }
Exemplo n.º 3
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();
 }
Exemplo n.º 4
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();
 }
Exemplo n.º 5
0
 public function _initialize()
 {
     if ($this->config['dump'] && ($this->config['cleanup'] or $this->config['populate'])) {
         if (!file_exists(getcwd() . DIRECTORY_SEPARATOR . $this->config['dump'])) {
             throw new \Codeception\Exception\ModuleConfig(__CLASS__, "\n                    File with dump deesn't exist.\n\n                    Please, check path for sql file: " . $this->config['dump']);
         }
         $sql = file_get_contents(getcwd() . DIRECTORY_SEPARATOR . $this->config['dump']);
         $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
         $this->sql = explode("\n", $sql);
     }
     try {
         $this->driver = Driver::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     } catch (\PDOException $e) {
         throw new \Codeception\Exception\Module(__CLASS__, $e->getMessage() . ' while creating PDO connection');
     }
     // starting with loading dump
     if ($this->config['populate']) {
         $this->cleanup();
         $this->loadDump();
     }
 }
Exemplo n.º 6
0
 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);
         $this->sql = explode("\n", $sql);
     }
     try {
         $this->driver = Driver::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     } catch (\PDOException $e) {
         throw new ModuleException(__CLASS__, $e->getMessage() . ' while creating PDO connection');
     }
     $this->dbh = $this->driver->getDbh();
     // starting with loading dump
     if ($this->config['populate']) {
         $this->cleanup();
         $this->loadDump();
         $this->populated = true;
     }
 }