Пример #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\Util\Driver\Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     $sqlite->load($sql);
 }
Пример #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();
 }
Пример #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();
 }
Пример #5
0
 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();
 }
Пример #6
0
 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();
 }