open() public method

It does nothing if a MongoDB connection has already been established.
public open ( )
Exemplo n.º 1
0
 public function testOpenClose()
 {
     $connection = $this->getConnection(false, false);
     $this->assertFalse($connection->isActive);
     $this->assertEquals(null, $connection->mongoClient);
     $connection->open();
     $this->assertTrue($connection->isActive);
     $this->assertTrue(is_object($connection->mongoClient));
     $connection->close();
     $this->assertFalse($connection->isActive);
     $this->assertEquals(null, $connection->mongoClient);
     $connection = new Connection();
     $connection->dsn = 'unknown::memory:';
     $this->setExpectedException('yii\\mongodb\\Exception');
     $connection->open();
 }
Exemplo n.º 2
0
 /**
  * @param  boolean                 $reset whether to clean up the test database
  * @param  boolean                 $open  whether to open test database
  * @return \yii\mongodb\Connection
  */
 public function getConnection($reset = false, $open = true)
 {
     if (!$reset && $this->mongodb) {
         return $this->mongodb;
     }
     $db = new Connection();
     $db->dsn = $this->mongoDbConfig['dsn'];
     $db->defaultDatabaseName = $this->mongoDbConfig['defaultDatabaseName'];
     if (isset($this->mongoDbConfig['options'])) {
         $db->options = $this->mongoDbConfig['options'];
     }
     if ($open) {
         $db->open();
     }
     $this->mongodb = $db;
     return $db;
 }