File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ CHANGELOG
2
+ =========
3
+
4
+ 1.18.0 (unreleased)
5
+ -------------------
6
+
7
+ * Add ` addSubscriber ` and ` removeSubscriber ` methods to the ` Client ` class to ease dependency injection configuration
8
+
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 \BulkWrite ;
7
+ use MongoDB \Driver \Command ;
7
8
use MongoDB \Driver \Manager ;
9
+ use MongoDB \Driver \Monitoring \CommandSubscriber ;
8
10
use MongoDB \Driver \Session ;
9
11
use MongoDB \Model \DatabaseInfo ;
10
12
use MongoDB \Model \DatabaseInfoIterator ;
@@ -119,4 +121,20 @@ public function testStartSession(): void
119
121
{
120
122
$ this ->assertInstanceOf (Session::class, $ this ->client ->startSession ());
121
123
}
124
+
125
+ public function testAddAndRemoveSubscriber (): void
126
+ {
127
+ $ client = new Client (static ::getUri ());
128
+
129
+ $ addedSubscriber = $ this ->createMock (CommandSubscriber::class);
130
+ $ addedSubscriber ->expects ($ this ->once ())->method ('commandStarted ' );
131
+ $ client ->addSubscriber ($ addedSubscriber );
132
+
133
+ $ removedSubscriber = $ this ->createMock (CommandSubscriber::class);
134
+ $ removedSubscriber ->expects ($ this ->never ())->method ('commandStarted ' );
135
+ $ client ->addSubscriber ($ removedSubscriber );
136
+ $ client ->removeSubscriber ($ removedSubscriber );
137
+
138
+ $ client ->getManager ()->executeCommand ('admin ' , new Command (['ping ' => 1 ]));
139
+ }
122
140
}
You can’t perform that action at this time.
0 commit comments