/**
  * @return \MongoDB\Collection
  */
 private function createCollectionObject()
 {
     $options = ['readPreference' => $this->readPreference, 'writeConcern' => $this->writeConcern];
     if ($this->collection === null) {
         $this->collection = $this->db->getDb()->selectCollection($this->name, $options);
     } else {
         $this->collection = $this->collection->withOptions($options);
     }
 }
 public function testWithOptionsInheritsReadPreferenceAndWriteConcern()
 {
     $collectionOptions = ['readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
     $collection = new Collection($this->manager, $this->getNamespace(), $collectionOptions);
     $clone = $collection->withOptions();
     $debug = $clone->__debugInfo();
     $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());
 }
 public function testWithOptionsInheritsReadPreferenceAndWriteConcern()
 {
     $collectionOptions = ['readConcern' => new ReadConcern(ReadConcern::LOCAL), 'readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), 'typeMap' => ['root' => 'array'], 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
     $collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $collectionOptions);
     $clone = $collection->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->assertInternalType('array', $debug['typeMap']);
     $this->assertSame(['root' => 'array'], $debug['typeMap']);
     $this->assertInstanceOf('MongoDB\\Driver\\WriteConcern', $debug['writeConcern']);
     $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
 }