33namespace MongoDB \Tests ;
44
55use MongoDB \Client ;
6+ use MongoDB \Codec \Encoder ;
67use MongoDB \Driver \ClientEncryption ;
78use MongoDB \Driver \Exception \InvalidArgumentException as DriverInvalidArgumentException ;
89use MongoDB \Driver \ReadConcern ;
@@ -45,6 +46,10 @@ public function provideInvalidConstructorDriverOptions()
4546 {
4647 $ options = [];
4748
49+ foreach ($ this ->getInvalidObjectValues () as $ value ) {
50+ $ options [][] = ['builderEncoder ' => $ value ];
51+ }
52+
4853 foreach ($ this ->getInvalidArrayValues (true ) as $ value ) {
4954 $ options [][] = ['typeMap ' => $ value ];
5055 }
@@ -85,13 +90,15 @@ public function testSelectCollectionInheritsOptions(): void
8590 ];
8691
8792 $ driverOptions = [
93+ 'builderEncoder ' => $ builderEncoder = $ this ->createMock (Encoder::class),
8894 'typeMap ' => ['root ' => 'array ' ],
8995 ];
9096
9197 $ client = new Client (static ::getUri (), $ uriOptions , $ driverOptions );
9298 $ collection = $ client ->selectCollection ($ this ->getDatabaseName (), $ this ->getCollectionName ());
9399 $ debug = $ collection ->__debugInfo ();
94100
101+ $ this ->assertSame ($ builderEncoder , $ debug ['builderEncoder ' ]);
95102 $ this ->assertInstanceOf (ReadConcern::class, $ debug ['readConcern ' ]);
96103 $ this ->assertSame (ReadConcern::LOCAL , $ debug ['readConcern ' ]->getLevel ());
97104 $ this ->assertInstanceOf (ReadPreference::class, $ debug ['readPreference ' ]);
@@ -105,6 +112,7 @@ public function testSelectCollectionInheritsOptions(): void
105112 public function testSelectCollectionPassesOptions (): void
106113 {
107114 $ collectionOptions = [
115+ 'builderEncoder ' => $ builderEncoder = $ this ->createMock (Encoder::class),
108116 'readConcern ' => new ReadConcern (ReadConcern::LOCAL ),
109117 'readPreference ' => new ReadPreference (ReadPreference::SECONDARY_PREFERRED ),
110118 'typeMap ' => ['root ' => 'array ' ],
@@ -115,6 +123,7 @@ public function testSelectCollectionPassesOptions(): void
115123 $ collection = $ client ->selectCollection ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ collectionOptions );
116124 $ debug = $ collection ->__debugInfo ();
117125
126+ $ this ->assertSame ($ builderEncoder , $ debug ['builderEncoder ' ]);
118127 $ this ->assertInstanceOf (ReadConcern::class, $ debug ['readConcern ' ]);
119128 $ this ->assertSame (ReadConcern::LOCAL , $ debug ['readConcern ' ]->getLevel ());
120129 $ this ->assertInstanceOf (ReadPreference::class, $ debug ['readPreference ' ]);
@@ -129,11 +138,19 @@ public function testGetSelectsDatabaseAndInheritsOptions(): void
129138 {
130139 $ uriOptions = ['w ' => WriteConcern::MAJORITY ];
131140
132- $ client = new Client (static ::getUri (), $ uriOptions );
141+ $ driverOptions = [
142+ 'builderEncoder ' => $ builderEncoder = $ this ->createMock (Encoder::class),
143+ 'typeMap ' => ['root ' => 'array ' ],
144+ ];
145+
146+ $ client = new Client (static ::getUri (), $ uriOptions , $ driverOptions );
133147 $ database = $ client ->{$ this ->getDatabaseName ()};
134148 $ debug = $ database ->__debugInfo ();
135149
150+ $ this ->assertSame ($ builderEncoder , $ debug ['builderEncoder ' ]);
136151 $ this ->assertSame ($ this ->getDatabaseName (), $ debug ['databaseName ' ]);
152+ $ this ->assertIsArray ($ debug ['typeMap ' ]);
153+ $ this ->assertSame (['root ' => 'array ' ], $ debug ['typeMap ' ]);
137154 $ this ->assertInstanceOf (WriteConcern::class, $ debug ['writeConcern ' ]);
138155 $ this ->assertSame (WriteConcern::MAJORITY , $ debug ['writeConcern ' ]->getW ());
139156 }
@@ -147,13 +164,15 @@ public function testSelectDatabaseInheritsOptions(): void
147164 ];
148165
149166 $ driverOptions = [
167+ 'builderEncoder ' => $ builderEncoder = $ this ->createMock (Encoder::class),
150168 'typeMap ' => ['root ' => 'array ' ],
151169 ];
152170
153171 $ client = new Client (static ::getUri (), $ uriOptions , $ driverOptions );
154172 $ database = $ client ->selectDatabase ($ this ->getDatabaseName ());
155173 $ debug = $ database ->__debugInfo ();
156174
175+ $ this ->assertSame ($ builderEncoder , $ debug ['builderEncoder ' ]);
157176 $ this ->assertInstanceOf (ReadConcern::class, $ debug ['readConcern ' ]);
158177 $ this ->assertSame (ReadConcern::LOCAL , $ debug ['readConcern ' ]->getLevel ());
159178 $ this ->assertInstanceOf (ReadPreference::class, $ debug ['readPreference ' ]);
@@ -167,6 +186,7 @@ public function testSelectDatabaseInheritsOptions(): void
167186 public function testSelectDatabasePassesOptions (): void
168187 {
169188 $ databaseOptions = [
189+ 'builderEncoder ' => $ builderEncoder = $ this ->createMock (Encoder::class),
170190 'readConcern ' => new ReadConcern (ReadConcern::LOCAL ),
171191 'readPreference ' => new ReadPreference (ReadPreference::SECONDARY_PREFERRED ),
172192 'typeMap ' => ['root ' => 'array ' ],
0 commit comments