public function tearDown() { if ($this->db instanceof \MongoDB) { $this->db->drop(); } parent::tearDown(); }
public function tearDown() { $this->database->dropCollection('testCollection'); $this->database->drop(); if (Mongo::getInstance()) { Mongo::getInstance()->destroy(); } }
public function testCreateCollection() { $ns = $this->object->selectCollection('system.namespaces'); $this->object->drop('z'); $this->object->drop('zz'); $this->object->drop('zzz'); $this->object->createCollection('z'); $obj = $ns->findOne(array('name' => 'phpunit.z')); $this->assertNotNull($obj); // even though we're only setting this to 100, it allocates 1 extent, // so we can fit 4096, not 100, bytes of data in the collection. $c = $this->object->createCollection('zz', true, 100); $obj = $ns->findOne(array('name' => 'phpunit.zz')); $this->assertNotNull($obj); for($i=0;$i<100;$i++) { $c->insert(array('x' => $i)); } $this->assertLessThan(100, $c->count()); $c = $this->object->createCollection('zzz', true, 1000, 5); $obj = $ns->findOne(array('name' => 'phpunit.zzz')); $this->assertNotNull($obj); for($i=0;$i<10;$i++) { $c->insert(array('x' => $i)); } $this->assertEquals(5, $c->count()); }
/** * Drop the database * * @return boolean */ public function drop() { $ok = $this->db->drop(); if (1 == (int) $ok['ok']) { return true; } return false; }
/** * Drops a database */ public function dropDb() { $this->mongo->drop(); return; if (!isset($this->_db)) { $this->_db = $this->_mongo(); } $this->_db->dropDB($this->mongo); }
/** * {@inheritdoc} */ public function flush($all = false) { if (true === $all) { $res = $this->db->drop(); return (bool) $res['ok']; } // $res = $this->collection->drop(); $regex = new \MongoRegex('/^' . $this->mapKey('') . '/'); $res = $this->collection->remove(array('key' => $regex)); return (bool) $res['ok']; }
/** * Drop database * * @param string $database * @return bool|array */ public function drop_db($database) { if (!empty($database)) { try { return $this->_database->drop(); } catch (\Exception $e) { $this->_last_error = $e; } } return false; }
/** * Wrapper method for MongoDB::drop(). * * This method will dispatch preDropDatabase and postDropDatabase events. * * @see http://php.net/manual/en/mongodb.drop.php * @return array */ public function drop() { if ($this->eventManager->hasListeners(Events::preDropDatabase)) { $this->eventManager->dispatchEvent(Events::preDropDatabase, new EventArgs($this)); } $result = $this->mongoDB->drop(); if ($this->eventManager->hasListeners(Events::postDropDatabase)) { $this->eventManager->dispatchEvent(Events::postDropDatabase, new EventArgs($this)); } return $result; }
public function testCreateCollection() { $ns = $this->object->selectCollection('system.namespaces'); $this->object->drop('z'); $this->object->drop('zz'); $this->object->drop('zzz'); $this->object->createCollection('z'); $obj = $ns->findOne(array('name' => 'phpunit.z')); $this->assertNotNull($obj); $c = $this->object->createCollection('zz', true, 100); $obj = $ns->findOne(array('name' => 'phpunit.zz')); $this->assertNotNull($obj); for ($i = 0; $i < 10; $i++) { $c->insert(array('x' => $i)); } $this->assertLessThan(10, $c->count()); $c = $this->object->createCollection('zzz', true, 1000, 5); $obj = $ns->findOne(array('name' => 'phpunit.zzz')); $this->assertNotNull($obj); for ($i = 0; $i < 10; $i++) { $c->insert(array('x' => $i)); } $this->assertEquals(5, $c->count()); }
/** * drop. */ public function drop() { $this->time->start(); $return = parent::drop(); $time = $this->time->stop(); $this->log(array('type' => 'drop', 'time' => $time)); return $return; }
/** * Drop the current DB. * @since v1.0 */ public function dropDb() { $this->_mongoDb->drop(); }
/** * Intercept native call to re-enable profiler * @return int **/ function drop() { $out = parent::drop(); $this->setprofilinglevel(2); return $out; }
/** * @return void */ public function tearDown() { if (isset($this->database)) { $this->database->drop(); } }
public function testDrop() { $r = $this->object->drop(); $this->assertEquals(true, (bool) $r['ok'], json_encode($r)); }
public function removeMongoDb(\MongoDB $db) { $db->drop(); }
function m2() { $this->set('title', 'M2 Mapper'); $this->expect(is_null($this->get('ERROR')), 'No errors expected at this point', 'ERROR variable is set: ' . $this->get('ERROR.text')); $this->expect(extension_loaded('mongo'), 'MongoDB extension available', 'MongoDB extension is not active - unable to continue'); if (extension_loaded('mongo')) { $this->set('QUIET', TRUE); try { $db = new MongoDB(new Mongo('mongodb://*****:*****@product->_id}}', 'M2 MongoID sync issue'); $this->expect($product->item == 111 && $product->description == 'Coca Cola' && $product->quantity == 4, 'M2 saved - database update succeeded', 'Database update failed'); $product->copyTo('POST'); $this->expect($this->get('POST.item') == 111 && $this->get('POST.description') == 'Coca Cola' && $this->get('POST.quantity') == 4, 'M2 properties copied to framework variable', 'Unable to copy M2 properties to framework variable'); $_POST['description'] = 'Pepsi'; $product->copyFrom('POST'); $this->expect($product->item == 111 && $product->description == 'Pepsi' && $product->quantity == 4, 'M2 properties populated by framework variable', 'Unable to fill M2 properties with contents of framework variable'); $this->set('POST.item', 999); $this->set('POST.description', 'Pepsi'); $this->set('POST.quantity', 11); $product->copyFrom('POST', 'item|quantity'); $this->expect($product->item == 999 && $product->description == 'Pepsi' && $product->quantity == 11, 'M2 properties populated by selected fields in framework variable', 'Unable to fill M2 properties with contents of framework variable'); $product->reset(); $this->expect($product->dry(), 'M2 reset completed', 'M2 should be dry'); $product->item = 222; $product->description = 'Mobile Phone'; $product->quantity = 9; $this->expect(!$product->dry(), 'M2 rehydrated manually', 'M2 should hydrated by now'); $product->save(); $this->expect(isset($product->_id), 'MongoID for new object assigned: ' . $product->_id, 'M2 MongoID sync issue'); $this->expect(!$product->dry(), 'M2 expected to remain hydrated', 'M2 should not be dry'); $product->load(array('item' => 111)); $this->expect(is_object($product->_id) && $product->_id == $id, 'MongoID of first object correct: ' . $product->_id, 'M2 MongoID sync issue'); $this->expect($product->item == 111 && $product->description == 'Coca Cola' && $product->quantity == 4, 'First record still there', 'First record is missing'); $product->load(array('item' => 222)); $this->expect($product->item == 222 && $product->description == 'Mobile Phone' && $product->quantity == 9, 'Second record found', 'Second record is missing'); $product->load(array('item' => 111)); $product->erase(); $product->load(array('item' => 111)); $this->expect($product->dry(), 'First record deleted', 'First record still exists'); $product->load(array('item' => 222)); $this->expect($product->item == 222 && $product->description == 'Mobile Phone' && $product->quantity == 9, 'Second record still there', 'Second record is missing'); $product->reset(); $product->item = 111; $product->description = 'Lots of dough'; $product->quantity = 666; $product->save(); $product->load(array('quantity' => array('$gt' => 0)), array('item' => TRUE)); $this->expect($product->found() == 2, 'New record added - multirecord criteria specified for loading', 'New record was not added'); $product->skip(1); $this->expect(!$product->dry(), 'One more record expected to be retrieved', 'M2 is dry'); $this->expect($product->item == 222 && $product->description == 'Mobile Phone' && $product->quantity == 9, 'Forward navigation', 'Forward navigation failed'); $product->skip(-1); $this->expect($product->item == 111 && $product->description == 'Lots of dough' && $product->quantity == 666, 'Backward navigation', 'Backward navigation failed'); $product->skip(-1); $this->expect($product->dry(), 'M2 is dry when navigating before the start of the record set', 'Navigation failure'); $this->set('QUIET', TRUE); $product->skip(-1); $this->expect(!is_null($this->get('ERROR')), 'Navigating past dry state triggers an error', 'Navigation error handling issue'); $this->set('QUIET', FALSE); $this->clear('ERROR'); $product->load(array('quantity' => array('$gt' => 0)), array('item' => TRUE)); $product->skip(2); $this->expect($product->dry(), 'M2 is dry when navigating beyond the end of the record set', 'Navigation failure'); $this->set('QUIET', TRUE); $product->skip(); $this->expect(!is_null($this->get('ERROR')), 'Navigating past dry state triggers an error', 'Navigation error handling issue'); $this->set('QUIET', FALSE); $this->clear('ERROR'); } } echo $this->render('basic/results.htm'); }
public function tearDown() { if ($this->db !== null) { $this->db->drop(); } }