Example #1
0
 /**
  * @return \MongoCollection
  */
 private function getCollection()
 {
     if (!$this->collection) {
         $class = MongoCache::getMongoClass();
         $mongo = new $class(sprintf('mongodb://%s', implode(',', $this->servers)));
         $this->collection = $mongo->selectDB($this->databaseName)->selectCollection($this->collectionName);
     }
     return $this->collection;
 }
Example #2
0
 public function setUp()
 {
     $class = MongoCache::getMongoClass();
     if (!class_exists($class, true)) {
         $this->markTestSkipped('Mongo is not installed');
     }
     $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     // setup the default timeout (avoid max execution time)
     socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 1, 'usec' => 0));
     $result = @socket_connect($socket, '127.0.0.1', 27017);
     socket_close($socket);
     if (!$result) {
         $this->markTestSkipped('MongoDB is not running');
     }
     $mongo = new $class('mongodb://127.0.0.1:27017');
     $mongo->selectDB('sonata_counter_test')->selectCollection('counter')->remove(array());
 }