public function testConstruct() { $m = new Mongo("localhost:27017,localhost:27018", false); $m->pairConnect(); $c = $m->selectCollection("phpunit", "test"); $c->insert(array("foo", "bar")); $left = new Mongo("localhost:27017"); $left->selectCollection("foo", "bar")->insert(array('x' => 1)); $lerr = $left->lastError(); $right = new Mongo("localhost:27018"); $right->selectCollection("foo", "bar")->insert(array('x' => 1)); $rerr = $right->lastError(); }
/** * @expectedException PHPUnit_Framework_Error */ public function testForceError() { $m = new Mongo(); $m->forceError(); $err = $m->lastError(); $this->assertNotNull($err['err']); $this->assertEquals($err['n'], 0); $this->assertEquals((bool)$err['ok'], true); }
$people[array_rand($people)][$factorName] = true; } } return $people; } // Density.csv says how many people are within each tract of land $handle = fopen('density.csv', 'r'); while (($data = fgetcsv($handle)) !== FALSE) { $populations[substr($data[1], 13)] = (int) $data[2]; } // This XML file contains data about the shapes of these tracts $tracts = simplexml_load_file('2010gztract_13.kml'); $pplcnt = 0; foreach ($tracts->Document->Placemark as $PUMA) { // Not great XML design on their part, using regex to pull out the tract ID to match the two datasets preg_match('/\\<td\\>(.+)\\<\\/td\\>/', $PUMA->description[0], $matches); $population = $populations[$matches[1]]; // Space-separated list of coordinates within XML object $polyline = explode(' ', $PUMA->Polygon[0]->outerBoundaryIs[0]->LinearRing[0]->coordinates); // Remove the last element which is a " " array_pop($polyline); if (count($polyline) > 1) { $people = insertNeighborhood($population, $polyline); $database->weatherhack->people->batchInsert($people); $pplcnt = $pplcnt + count($people); echo "inserted {$pplcnt}... "; usleep(100); } } var_dump($database->lastError());