/** * @param $mongoId */ public function assertMongoId($mongoId) { if (is_string($mongoId)) { $mongoId = new \MongoId($mongoId); } $this->assertTrue($mongoId instanceof \MongoId); $this->assertNotNull($mongoId->getPID()); $this->assertNotNull($mongoId->getTimestamp()); $this->assertNotNull($mongoId->getInc()); $this->assertNotNull($mongoId->getHostname()); $this->assertEquals(24, strlen($mongoId->{'$id'})); }
public function testGetHostname() { if (preg_match('/5\\.[12]\\..+/', phpversion())) { $this->markTestSkipped("No gethostname() 5.1 or 5.2"); return; } $host1 = gethostname(); $host2 = MongoId::getHostname(); $this->assertEquals($host1, $host2); }
<?php MongoId::getHostname(); MongoId::__toString(); MongoId::getTimestamp(); MongoId::isValid(); MongoId::__set_state(); MongoId::getInc(); MongoId::getPID(); $collection->save(array("ts" => new MongoDate())); $start = new MongoDate(strtotime("2010-01-15 00:00:00")); $end = new MongoDate(strtotime("2010-01-30 00:00:00")); $collection->find(array("ts" => array('$gt' => $start, '$lte' => $end))); $search = "V"; $where = array('name' => array(' $regex' => new MongoRegex("/^{$search}/"))); $cursor = $collection->find($where); $where = array('name' => array('$regex' => new MongoRegex("/^{$search}/i"))); $profile = array("username" => 'foobity', "pic" => new MongoBinData(file_get_contents("gravatar.jpg"), MongoBinData::GENERIC)); $connection->save($profile); $people = $db->people; $addresses = $db->addresses; $myAddress = array("line 1" => '12 main sreet', 'line 2' => null, 'city' => 'beijing', 'state' => "vermont", 'country' => 'china'); $addresses->insert($myAddress); $me = array('name' => 'fred', 'address' => $myAddress['_id']); $people->insert($me);