/** * setUpBeforeClass * * @throws \LogicException * @return void */ public static function setUpBeforeClass() { if (!static::$driver) { throw new \LogicException('static::$driver variable is empty.'); } static::$dsn = $dsn = TestDsnResolver::getDsn(static::$driver); if (!$dsn) { static::markTestSkipped('DSN of driver ' . static::$driver . ' not available'); } 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; } try { // 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)); } catch (\RangeException $e) { static::markTestSkipped($e->getMessage()); return; } $database = $db->getDatabase($dbname); if (static::$debug) { $database->drop(true); } $database->create(true); $db->select($dbname); $queries = file_get_contents(__DIR__ . '/Stub/' . static::$driver . '.sql'); DatabaseHelper::batchQuery($db, $queries); }
/** * 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(); } } }
public static function configure(array $db_config) { static::$dsn = "mysql:host=" . $db_config['host'] . ";dbname=" . $db_config['name']; static::$user = $db_config['user']; static::$pass = $db_config['pass']; static::$configured = true; }
public static function tearDownAfterClass() { static::$dsn = null; static::$dbh = null; }
/** * Set the dsn value * * @param string $dsn The dsn value * * @static */ public static function setDsn(string $dsn) { static::$dsn = $dsn; }
public static function setDsn(array $dsn) { static::$dsn = $dsn; }