Пример #1
0
 /**
  * @dataProvider unknown_settings_provider
  * @expectedException PHPUnit_Framework_Error
  */
 public function test_constructor_with_unknown_settings($settings)
 {
     $db = new AnewtDatabaseConnectionPostgreSQL($settings);
     $db->connect();
 }
Пример #2
0
 /**
  * Setup a new database connection.
  *
  * This stores the connection configuration in the database pool.
  * See the AnewtDatabaseConnection (and subclasses) documentation for the
  * description of the settings array.
  *
  * \param $settings
  *   An associative array with connection settings. At least the \c type
  *   key must be provided to specify the database connection type. See
  *   AnewtDatabaseConnection for the possible values.
  * \param $id
  *   The connection id to use for this connection (optional, defaults to
  *   <code>default</code>)
  *
  * \see AnewtDatabaseConnection
  */
 public static function setup_connection($settings, $id = 'default')
 {
     assert('is_assoc_array($settings)');
     assert('array_has_key($settings, "type"); // "type" key must be present in database settings array');
     assert('is_string($id)');
     /* A connection can be setup only once */
     if (array_key_exists($id, AnewtDatabase::$connections)) {
         throw new AnewtDatabaseException('Connection "%s" has been setup already.', $id);
     }
     /* Create an AnewtDatabaseConnection instance */
     $connection_type = $settings['type'];
     switch ($connection_type) {
         case 'sqlite':
             anewt_include('database.new/backend-sqlite');
             // FIXME: module name
             $connection = new AnewtDatabaseConnectionSQLite($settings);
             break;
         case 'mysql':
             anewt_include('database.new/backend-mysql');
             // FIXME: module name
             $connection = new AnewtDatabaseConnectionMySQL($settings);
             break;
         case 'mysql-old':
             anewt_include('database.new/backend-mysql-old');
             // FIXME: module name
             $connection = new AnewtDatabaseConnectionMySQLOld($settings);
             break;
         case 'postgresql':
             anewt_include('database.new/backend-postgresql');
             // FIXME: module name
             $connection = new AnewtDatabaseConnectionPostgreSQL($settings);
             break;
         default:
             throw new AnewtDatabaseException('Database type "%s" is not supported', $connection_type);
             break;
     }
     /* Connect by default, unless instructed not to */
     if (array_get_bool($settings, 'autoconnect', true)) {
         $connection->connect();
     }
     /* Store the connection instance */
     AnewtDatabase::$connections[$id] = $connection;
 }