Ejemplo n.º 1
0
 public function testOptions()
 {
     $env = 'myenv';
     $options = array('connection' => array('options' => array('w' => 2)));
     MongoDB::setConfigBlock($env, $options);
     $i = MongoDB::instance($env);
     $instanceOptions = $i->config($env);
     $this->assertEquals($options['connection']['options'], $instanceOptions['connection']['options']);
 }
 public function register(Application $app)
 {
     $app['mongodm'] = $app->share(function () use($app) {
         if (isset($app['mongodm.blocks']) && is_array($app['mongodm.blocks'])) {
             foreach ($app['mongodm.blocks'] as $block => $config) {
                 MongoDB::setConfigBlock($block, array('connection' => array('hostnames' => isset($config['host']) ? $config['host'] : 'localhost', 'database' => isset($config['db']) ? $config['db'] : 'test', 'options' => isset($config['options']) ? $config['options'] : array())));
             }
         } else {
             MongoDB::setConfigBlock('default', array('connection' => array('hostnames' => isset($app['mongodm.host']) ? $app['mongodm.host'] : 'localhost', 'database' => isset($app['mongodm.db']) ? $app['mongodm.db'] : 'test', 'options' => isset($app['mongodm.options']) ? $app['mongodm.options'] : array())));
         }
         return MongoDB::instance();
     });
 }
Ejemplo n.º 3
0
 public static function setUpBeforeClass()
 {
     MongoDB::setConfigBlock('testing', array('connection' => array('hostnames' => 'localhost', 'database' => 'test_db')));
     self::$db = MongoDB::instance('testing');
     self::$db->connect();
     if (!self::$phactory) {
         if (!self::$db->getDB() instanceof \MongoDB) {
             throw new \Exception('Could not connect to MongoDB');
         }
         self::$phactory = new Phactory(self::$db->getDB());
         self::$phactory->reset();
     }
     //set up Phactory db connection
     self::$phactory->reset();
 }
Ejemplo n.º 4
0
 /**
  * Get current database name
  *
  * @return string
  */
 protected function dbName()
 {
     $dbName = "default";
     $config = $this::$config;
     $configs = MongoDB::config($config);
     if ($configs) {
         $dbName = $configs['connection']['database'];
     }
     return $dbName;
 }