Esempio n. 1
0
 public function testMongolog()
 {
     $config = ['database' => 'reach_testing', 'host' => 'localhost', 'port' => 27017, 'syslog' => ['class' => '\\Reach\\Mongo\\Log'], 'logger' => ['class' => '\\Reach\\Mongo\\Logger']];
     ConnectionManager::registerConnection($config, 'mongolog');
     $connection = ConnectionManager::getConnection('mongolog');
     $connection->getCollection('test')->insert(['name' => 'John']);
 }
Esempio n. 2
0
 protected function classSetUp()
 {
     $config = ['database' => 'reach_testing', 'host' => 'localhost', 'port' => 27017, 'options' => ['connect' => true, 'socketTimeoutMS' => 60000]];
     ConnectionManager::registerConnection($config);
     /** @var Connection _connection */
     $this->_connection = ConnectionManager::getConnection();
     TestSchema::getCollection()->drop();
     TestSchema::getCollection()->addIndexes([['object.type', 'object.rnd', 'created']]);
     $this->_memory = memory_get_usage(true);
 }
 public function testConnectionOld()
 {
     $config = ['database' => 'reach_testing', 'host' => 'localhost', 'port' => 27017, 'options' => ['connect' => true, 'socketTimeoutMS' => 60000]];
     ConnectionManager::registerConnection($config);
     $connection = ConnectionManager::getConnection();
     $this->assertInstanceOf('\\Reach\\Mongo\\Connection', $connection);
     $this->assertTrue(method_exists($connection, 'getDb'));
     $this->assertInstanceOf('\\MongoDB', $connection->getDb());
     $config2 = ['database' => 'reach_testing2'];
     Container::register('another', $config2, '\\Reach\\Mongo\\Connection');
     $connection2 = Container::get('another');
     $this->assertInstanceOf('\\Reach\\Mongo\\Connection', $connection2);
     $this->assertEquals('reach_testing2', $connection2->getDbName());
     $connection = ConnectionManager::getConnection();
     $this->assertInstanceOf('\\Reach\\Mongo\\Connection', $connection);
     $this->assertEquals('reach_testing', $connection->getDbName());
 }
Esempio n. 4
0
 /**
  * @return Connection
  */
 public static function getConnection($connection_name = null)
 {
     return ConnectionManager::getConnection($connection_name);
 }
Esempio n. 5
0
 /**
  * @param string $name
  */
 public function register($name = null)
 {
     ConnectionManager::registerConnection($this->_config, $name);
 }
Esempio n. 6
0
 /**
  * @param null $connection_name
  * @return Connection
  */
 public static function getConnection($connection_name = null)
 {
     $connection_name = $connection_name ?: Connection::$default_connection_name;
     return ConnectionManager::getConnection($connection_name);
 }