Пример #1
0
 /**
  * getOptions
  *
  * @return  array
  */
 public static function getOptions()
 {
     // Only use mysql to test
     $dsn = DsnResolver::getDsn('mysql');
     $options = array('host' => $dsn['host'], 'user' => $dsn['user'], 'password' => $dsn['pass']);
     return $options;
 }
Пример #2
0
 /**
  * setUpBeforeClass
  *
  * @throws \LogicException
  * @return  void
  */
 public static function setUpBeforeClass()
 {
     if (!static::$driver) {
         throw new \LogicException('static::$driver variable is empty.');
     }
     static::$dsn = $dsn = DsnResolver::getDsn(static::$driver);
     if (!$dsn) {
         return;
     }
     static::$dbname = $dbname = isset($dsn['dbname']) ? $dsn['dbname'] : null;
     if (!$dbname) {
         throw new \LogicException(sprintf('No dbname in %s DSN', static::$driver));
     }
     // Id db exists, return.
     if (static::$dbo) {
         static::$dbo->select($dbname);
         return;
     }
     // Use factory create dbo, only create once and will be singleton.
     $db = self::$dbo = DatabaseFactory::getDbo(static::$driver, array('host' => isset($dsn['host']) ? $dsn['host'] : null, 'user' => isset($dsn['user']) ? $dsn['user'] : null, 'password' => isset($dsn['pass']) ? $dsn['pass'] : null, 'port' => isset($dsn['port']) ? $dsn['port'] : null, 'prefix' => isset($dsn['prefix']) ? $dsn['prefix'] : null));
     $db->getDatabase($dbname)->create(true);
     $db->select($dbname);
     $queries = file_get_contents(__DIR__ . '/Stub/' . static::$driver . '.sql');
     $queries = $db->splitSql($queries);
     foreach ($queries as $query) {
         $query = trim($query);
         if ($query) {
             $db->setQuery($query)->execute();
         }
     }
 }
Пример #3
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $dsn = DsnResolver::getDsn('mysql');
     if ($dsn) {
         $this->pdo = new \PDO('mysql:host=localhost;', $dsn['user'], $dsn['pass']);
     }
     $this->instance = new MysqlQuery($this->pdo);
 }