public function testDead() { $this->object->drop(); $this->object->insert(array('x' => 1)); $cursor = $this->object->find(); $this->assertFalse($cursor->dead()); $cursor->next(); $this->assertTrue($cursor->dead()); }
public function testExplainReset() { $this->object->insert(array("x" => "abc"), array('safe' => true)); $cursor = $this->object->find(); $qp = $cursor->explain(); $info = $cursor->info(); $this->assertTrue(!array_key_exists('$explain', $info['query'])); $this->assertTrue(array_key_exists('$query', $info['query'])); $doc = $cursor->getNext(); $this->assertEquals('abc', $doc['x'], json_encode($doc)); }
public function testExceptionHost() { $host = ""; $this->object->insert(array("_id" => 1), array("safe" => true)); try { $this->object->insert(array("_id" => 1), array("safe" => true)); } catch (MongoCursorException $e) { $host = $e->getHost(); } $this->assertEquals("localhost:27017", $host); }
public function testTimeout3() { for ($i = 0; $i < 10000; $i++) { $this->object->insert(array("name" => "joe" . $i, "interests" => array(rand(), rand(), rand()))); } $cmd = $this->object->db->selectCollection('$cmd'); $query = 'r = 0; cursor = db.c.find(); while (cursor.hasNext()) { x = cursor.next(); for (i=0; i<200; i++) { if (x.name == "joe"+i) { r++; } } } return r;'; $count = 0; for ($i = 0; $i < 3; $i++) { $cursor = $cmd->find(array('$eval' => $query))->limit(-1)->timeout(500); try { $x = $cursor->getNext(); $this->assertFalse(true, json_encode($x)); } catch (MongoCursorTimeoutException $e) { $count++; } } $this->assertEquals(3, $count); $x = $this->object->findOne(); $this->assertNotNull($x); $this->assertTrue(array_key_exists('name', $x), json_encode($x)); $this->assertTrue(array_key_exists('interests', $x), json_encode($x)); }