File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 23
23
use MongoDB \Driver \Exception \InvalidArgumentException as DriverInvalidArgumentException ;
24
24
use MongoDB \Driver \Exception \RuntimeException as DriverRuntimeException ;
25
25
use MongoDB \Driver \Manager ;
26
+ use MongoDB \Driver \Monitoring \Subscriber ;
26
27
use MongoDB \Driver \ReadConcern ;
27
28
use MongoDB \Driver \ReadPreference ;
28
29
use MongoDB \Driver \Session ;
@@ -163,6 +164,16 @@ public function __toString()
163
164
return $ this ->uri ;
164
165
}
165
166
167
+ /**
168
+ * Registers a monitoring event subscriber with this Client's Manager
169
+ *
170
+ * @see Manager::addSubscriber()
171
+ */
172
+ final public function addSubscriber (Subscriber $ subscriber ): void
173
+ {
174
+ $ this ->manager ->addSubscriber ($ subscriber );
175
+ }
176
+
166
177
/**
167
178
* Returns a ClientEncryption instance for explicit encryption and decryption
168
179
*
@@ -296,6 +307,16 @@ public function listDatabases(array $options = [])
296
307
return $ operation ->execute ($ server );
297
308
}
298
309
310
+ /**
311
+ * Unregisters a monitoring event subscriber with this Client's Manager
312
+ *
313
+ * @see Manager::removeSubscriber()
314
+ */
315
+ final public function removeSubscriber (Subscriber $ subscriber ): void
316
+ {
317
+ $ this ->manager ->removeSubscriber ($ subscriber );
318
+ }
319
+
299
320
/**
300
321
* Select a collection.
301
322
*
Original file line number Diff line number Diff line change 4
4
5
5
use MongoDB \Client ;
6
6
use MongoDB \Driver \ClientEncryption ;
7
+ use MongoDB \Driver \Command ;
7
8
use MongoDB \Driver \Exception \InvalidArgumentException as DriverInvalidArgumentException ;
9
+ use MongoDB \Driver \Monitoring \CommandSubscriber ;
8
10
use MongoDB \Driver \ReadConcern ;
9
11
use MongoDB \Driver \ReadPreference ;
10
12
use MongoDB \Driver \WriteConcern ;
@@ -237,4 +239,20 @@ public function testCreateClientEncryptionWithInvalidKeyVaultClient(): void
237
239
238
240
$ client ->createClientEncryption (['keyVaultClient ' => 'foo ' ]);
239
241
}
242
+
243
+ public function testAddAndRemoveSubscriber (): void
244
+ {
245
+ $ client = new Client (static ::getUri ());
246
+
247
+ $ addedSubscriber = $ this ->createMock (CommandSubscriber::class);
248
+ $ addedSubscriber ->expects ($ this ->once ())->method ('commandStarted ' );
249
+ $ client ->addSubscriber ($ addedSubscriber );
250
+
251
+ $ removedSubscriber = $ this ->createMock (CommandSubscriber::class);
252
+ $ removedSubscriber ->expects ($ this ->never ())->method ('commandStarted ' );
253
+ $ client ->addSubscriber ($ removedSubscriber );
254
+ $ client ->removeSubscriber ($ removedSubscriber );
255
+
256
+ $ client ->getManager ()->executeCommand ('admin ' , new Command (['ping ' => 1 ]));
257
+ }
240
258
}
You can’t perform that action at this time.
0 commit comments