/** * @return \MongoDB\Database */ private function createDatabaseObject() { $options = ['readPreference' => $this->readPreference, 'writeConcern' => $this->writeConcern]; if ($this->db === null) { $this->db = $this->connection->getClient()->selectDatabase($this->name, $options); } else { $this->db = $this->db->withOptions($options); } }
public function testWithOptionsInheritsOptions() { $databaseOptions = ['readConcern' => new ReadConcern(ReadConcern::LOCAL), 'readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]; $database = new Database($this->manager, $this->getDatabaseName(), $databaseOptions); $clone = $database->withOptions(); $debug = $clone->__debugInfo(); $this->assertInstanceOf('MongoDB\\Driver\\ReadConcern', $debug['readConcern']); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertInstanceOf('MongoDB\\Driver\\ReadPreference', $debug['readPreference']); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertInstanceOf('MongoDB\\Driver\\WriteConcern', $debug['writeConcern']); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); }