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(); }
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); }
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(); }
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(); }
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(); } }
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; } }