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((object)array('name' => 'phpunit.z')); $this->assertNotNull($obj); $c = $this->object->createCollection('zz', true, 100); $obj = $ns->findOne((object)array('name' => 'phpunit.zz')); $this->assertNotNull($obj); for($i=0;$i<100;$i++) { $c->insert((object)array('x' => $i)); } $this->assertLessThan(100, $c->count()); $c = $this->object->createCollection('zzz', true, 1000, 5); $obj = $ns->findOne((object)array('name' => 'phpunit.zzz')); $this->assertNotNull($obj); for($i=0;$i<10;$i++) { $c->insert((object)array('x' => $i)); } $this->assertEquals(5, $c->count()); }
public function testEnsureIndex() { $this->object->ensureIndex('foo'); $idx = $this->object->db->selectCollection('system.indexes'); $index = $idx->findOne((object) array('name' => 'foo_1')); $this->assertNotNull($index); $this->assertEquals($index['key']['foo'], 1); $this->assertEquals($index['name'], 'foo_1'); // get rid of indexes $this->object->drop(); $this->object->ensureIndex((object) array('bar' => -1)); $index = $idx->findOne((object) array('name' => 'bar_-1')); $this->assertNotNull($index); $this->assertEquals($index['key']['bar'], -1); $this->assertEquals($index['ns'], 'phpunit.c'); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ public function setUp() { $m = new Mongo(); $this->object = $m->selectCollection('foo', 'bar'); $this->object->drop(); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ public function setUp() { $this->object = $this->sharedFixture->selectCollection('foo', 'bar'); $this->object->drop(); }