Phalcon\Test\ModelTestCase::setDb PHP Method

setDb() protected method

Sets the database adapter in the DI container
protected setDb ( string $dbType = 'mysql' ) : void
$dbType string Sets the database type for the test
return void
    protected function setDb($dbType = 'mysql')
    {
        $config = $this->config;
        if ($this->di->has('db')) {
            $db = $this->di->get('db');
            $class = 'Phalcon\\Db\\Adapter\\Pdo\\' . ucfirst($dbType);
            if (get_class($db) == $class) {
                return $db;
            }
        }
        // Set the connection to whatever we chose
        $this->di->set('db', function () use($dbType, $config) {
            $params = $config['db'][$dbType];
            $class = 'Phalcon\\Db\\Adapter\\Pdo\\' . ucfirst($dbType);
            $conn = new $class($params);
            return $conn;
        });
    }