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(); }
protected function proceedSeeInDatabase($table, $criteria) { $query = "select count(*) from `%s` where %s"; $params = array(); foreach ($criteria as $k => $v) { $params[] = "`{$k}` = ? "; } $params = implode('AND ', $params); $query = sprintf($query, $table, $params); $this->debugSection('Query', $query, $params); $sth = $this->driver->getDbh()->prepare($query); if (!$sth) { \PHPUnit_Framework_Assert::fail("Query '{$query}' can't be executed."); } $sth->execute(array_values($criteria)); return $sth->fetchColumn(); }
protected function proceedSeeInDatabase($table, $column, $criteria) { $query = $this->driver->select($column, $table, $criteria); $this->debugSection('Query', $query, json_encode($criteria)); $sth = $this->driver->getDbh()->prepare($query); if (!$sth) { \PHPUnit_Framework_Assert::fail("Query '{$query}' can't be executed."); } $sth->execute(array_values($criteria)); return $sth->fetchColumn(); }