getDatabase() public method

Returns the MongoDB database with the given name.
public getDatabase ( string | null $name = null, boolean $refresh = false ) : Database
$name string | null database name, if null default one will be used.
$refresh boolean whether to reestablish the database connection even, if it is found in the cache.
return Database database instance.
Esempio n. 1
0
 /**
  * @depends testGetDatabase
  */
 public function testGetDefaultDatabase()
 {
     $connection = new Connection();
     $connection->dsn = $this->mongoDbConfig['dsn'];
     $connection->defaultDatabaseName = $this->mongoDbConfig['defaultDatabaseName'];
     $database = $connection->getDatabase();
     $this->assertTrue($database instanceof Database, 'Unable to get default database!');
     $connection = new Connection();
     $connection->dsn = $this->mongoDbConfig['dsn'];
     $connection->options = ['db' => $this->mongoDbConfig['defaultDatabaseName']];
     $database = $connection->getDatabase();
     $this->assertTrue($database instanceof Database, 'Unable to determine default database from options!');
     $connection = new Connection();
     $connection->dsn = $this->mongoDbConfig['dsn'] . '/' . $this->mongoDbConfig['defaultDatabaseName'];
     $database = $connection->getDatabase();
     $this->assertTrue($database instanceof Database, 'Unable to determine default database from dsn!');
 }