Skip to content

Commit 91c8d21

Browse files
committed
Refactor CommandObserver to track all three APM events
1 parent 66b4a91 commit 91c8d21

25 files changed

+98
-92
lines changed

tests/Collection/CollectionFunctionalTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ function() {
123123
]
124124
);
125125
},
126-
function(stdClass $command) {
126+
function(array $event) {
127+
$command = $event['started']->getCommand();
127128
$this->assertObjectHasAttribute('lsid', $command);
128129
$this->assertObjectHasAttribute('maxTimeMS', $command);
129130
$this->assertObjectHasAttribute('writeConcern', $command);

tests/CommandObserver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ public function observe(callable $execution, callable $commandCallback)
3838

3939
public function commandStarted(CommandStartedEvent $event)
4040
{
41-
$this->commands[] = $event->getCommand();
41+
$this->commands[$event->getRequestId()]['started'] = $event;
4242
}
4343

4444
public function commandSucceeded(CommandSucceededEvent $event)
4545
{
46+
$this->commands[$event->getRequestId()]['succeeded'] = $event;
4647
}
4748

4849
public function commandFailed(CommandFailedEvent $event)
4950
{
51+
$this->commands[$event->getRequestId()]['failed'] = $event;
5052
}
5153
}

tests/GridFS/ReadableStreamFunctionalTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ function() use ($stream, $offset, $length, $expectedBytes) {
221221
$stream->seek($offset);
222222
$this->assertSame($expectedBytes, $stream->readBytes($length));
223223
},
224-
function(stdClass $command) use (&$commands) {
225-
$commands[] = key((array) $command);
224+
function(array $event) use (&$commands) {
225+
$commands[] = $event['started']->getCommandName();
226226
}
227227
);
228228

@@ -257,8 +257,8 @@ function() use ($stream, $offset, $length, $expectedBytes) {
257257
$stream->seek($offset);
258258
$this->assertSame($expectedBytes, $stream->readBytes($length));
259259
},
260-
function(stdClass $command) use (&$commands) {
261-
$commands[] = key((array) $command);
260+
function(array $event) use (&$commands) {
261+
$commands[] = $event['started']->getCommandName();
262262
}
263263
);
264264

@@ -291,8 +291,8 @@ function() use ($stream, $offset, $length, $expectedBytes) {
291291
$stream->seek($offset);
292292
$this->assertSame($expectedBytes, $stream->readBytes($length));
293293
},
294-
function(stdClass $command) use (&$commands) {
295-
$commands[] = key((array) $command);
294+
function(array $event) use (&$commands) {
295+
$commands[] = $event['started']->getCommandName();
296296
}
297297
);
298298

tests/Operation/AggregateFunctionalTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ function() {
2828

2929
$operation->execute($this->getPrimaryServer());
3030
},
31-
function(stdClass $command) {
32-
$this->assertSame(1, $command->aggregate);
31+
function(array $event) {
32+
$this->assertSame(1, $event['started']->getCommand()->aggregate);
3333
}
3434
);
3535
}
@@ -47,8 +47,8 @@ function() {
4747

4848
$operation->execute($this->getPrimaryServer());
4949
},
50-
function(stdClass $command) {
51-
$this->assertObjectNotHasAttribute('readConcern', $command);
50+
function(array $event) {
51+
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
5252
}
5353
);
5454
}
@@ -66,8 +66,8 @@ function() {
6666

6767
$operation->execute($this->getPrimaryServer());
6868
},
69-
function(stdClass $command) {
70-
$this->assertObjectNotHasAttribute('writeConcern', $command);
69+
function(array $event) {
70+
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
7171
}
7272
);
7373
}
@@ -112,8 +112,8 @@ function() {
112112

113113
$operation->execute($this->getPrimaryServer());
114114
},
115-
function(stdClass $command) {
116-
$this->assertObjectHasAttribute('lsid', $command);
115+
function(array $event) {
116+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
117117
}
118118
);
119119
}
@@ -185,8 +185,8 @@ function() use ($pipeline, $options) {
185185
$this->assertCount(1, $results);
186186
$this->assertObjectHasAttribute('stages', current($results));
187187
},
188-
function(stdClass $command) {
189-
$this->assertObjectNotHasAttribute('writeConcern', $command);
188+
function(array $event) {
189+
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
190190
}
191191
);
192192

tests/Operation/BulkWriteFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ function() {
299299

300300
$operation->execute($this->getPrimaryServer());
301301
},
302-
function(stdClass $command) {
303-
$this->assertObjectHasAttribute('lsid', $command);
302+
function(array $event) {
303+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
304304
}
305305
);
306306
}

tests/Operation/CountFunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function() {
2323

2424
$operation->execute($this->getPrimaryServer());
2525
},
26-
function(stdClass $command) {
27-
$this->assertObjectNotHasAttribute('readConcern', $command);
26+
function(array $event) {
27+
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
2828
}
2929
);
3030
}
@@ -87,8 +87,8 @@ function() {
8787

8888
$operation->execute($this->getPrimaryServer());
8989
},
90-
function(stdClass $command) {
91-
$this->assertObjectHasAttribute('lsid', $command);
90+
function(array $event) {
91+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
9292
}
9393
);
9494
}

tests/Operation/CreateCollectionFunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function() {
2020

2121
$operation->execute($this->getPrimaryServer());
2222
},
23-
function(stdClass $command) {
24-
$this->assertObjectNotHasAttribute('writeConcern', $command);
23+
function(array $event) {
24+
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
2525
}
2626
);
2727
}
@@ -42,8 +42,8 @@ function() {
4242

4343
$operation->execute($this->getPrimaryServer());
4444
},
45-
function(stdClass $command) {
46-
$this->assertObjectHasAttribute('lsid', $command);
45+
function(array $event) {
46+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
4747
}
4848
);
4949
}

tests/Operation/CreateIndexesFunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ function() {
140140

141141
$operation->execute($this->getPrimaryServer());
142142
},
143-
function(stdClass $command) {
144-
$this->assertObjectNotHasAttribute('writeConcern', $command);
143+
function(array $event) {
144+
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
145145
}
146146
);
147147
}
@@ -163,8 +163,8 @@ function() {
163163

164164
$operation->execute($this->getPrimaryServer());
165165
},
166-
function(stdClass $command) {
167-
$this->assertObjectHasAttribute('lsid', $command);
166+
function(array $event) {
167+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
168168
}
169169
);
170170
}

tests/Operation/DatabaseCommandFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ function() {
2424

2525
$operation->execute($this->getPrimaryServer());
2626
},
27-
function(stdClass $command) {
28-
$this->assertObjectHasAttribute('lsid', $command);
27+
function(array $event) {
28+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
2929
}
3030
);
3131
}

tests/Operation/DeleteFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ function() {
7979

8080
$operation->execute($this->getPrimaryServer());
8181
},
82-
function(stdClass $command) {
83-
$this->assertObjectHasAttribute('lsid', $command);
82+
function(array $event) {
83+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
8484
}
8585
);
8686
}

tests/Operation/DistinctFunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function() {
2222

2323
$operation->execute($this->getPrimaryServer());
2424
},
25-
function(stdClass $command) {
26-
$this->assertObjectNotHasAttribute('readConcern', $command);
25+
function(array $event) {
26+
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
2727
}
2828
);
2929
}
@@ -46,8 +46,8 @@ function() {
4646

4747
$operation->execute($this->getPrimaryServer());
4848
},
49-
function(stdClass $command) {
50-
$this->assertObjectHasAttribute('lsid', $command);
49+
function(array $event) {
50+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
5151
}
5252
);
5353
}

tests/Operation/DropCollectionFunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function() {
2222

2323
$operation->execute($this->getPrimaryServer());
2424
},
25-
function(stdClass $command) {
26-
$this->assertObjectNotHasAttribute('writeConcern', $command);
25+
function(array $event) {
26+
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
2727
}
2828
);
2929
}
@@ -69,8 +69,8 @@ function() {
6969

7070
$operation->execute($this->getPrimaryServer());
7171
},
72-
function(stdClass $command) {
73-
$this->assertObjectHasAttribute('lsid', $command);
72+
function(array $event) {
73+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
7474
}
7575
);
7676
}

tests/Operation/DropDatabaseFunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function() {
2222

2323
$operation->execute($this->getPrimaryServer());
2424
},
25-
function(stdClass $command) {
26-
$this->assertObjectNotHasAttribute('writeConcern', $command);
25+
function(array $event) {
26+
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
2727
}
2828
);
2929
}
@@ -73,8 +73,8 @@ function() {
7373

7474
$operation->execute($this->getPrimaryServer());
7575
},
76-
function(stdClass $command) {
77-
$this->assertObjectHasAttribute('lsid', $command);
76+
function(array $event) {
77+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
7878
}
7979
);
8080
}

tests/Operation/DropIndexesFunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ function() {
2828

2929
$operation->execute($this->getPrimaryServer());
3030
},
31-
function(stdClass $command) {
32-
$this->assertObjectNotHasAttribute('writeConcern', $command);
31+
function(array $event) {
32+
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
3333
}
3434
);
3535
}
@@ -137,8 +137,8 @@ function() {
137137

138138
$operation->execute($this->getPrimaryServer());
139139
},
140-
function(stdClass $command) {
141-
$this->assertObjectHasAttribute('lsid', $command);
140+
function(array $event) {
141+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
142142
}
143143
);
144144
}

tests/Operation/ExplainFunctionalTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ function() use ($operation) {
182182
$explainOperation = new Explain($this->getDatabaseName(), $operation, ['typeMap' => ['root' => 'array', 'document' => 'array']]);
183183
$explainOperation->execute($this->getPrimaryServer());
184184
},
185-
function(stdClass $command) {
185+
function(array $event) {
186+
$command = $event['started']->getCommand();
186187
$this->assertObjectNotHasAttribute('maxAwaitTimeMS', $command->explain);
187188
$this->assertObjectHasAttribute('tailable', $command->explain);
188189
$this->assertObjectHasAttribute('awaitData', $command->explain);
@@ -206,7 +207,8 @@ function() use ($operation) {
206207
$explainOperation = new Explain($this->getDatabaseName(), $operation, ['typeMap' => ['root' => 'array', 'document' => 'array']]);
207208
$explainOperation->execute($this->getPrimaryServer());
208209
},
209-
function(stdClass $command) {
210+
function(array $event) {
211+
$command = $event['started']->getCommand();
210212
$this->assertObjectHasAttribute('sort', $command->explain);
211213
$this->assertObjectNotHasAttribute('modifiers', $command->explain);
212214
}

tests/Operation/FindAndModifyFunctionalTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function() use ($server) {
3030

3131
$operation->execute($server);
3232
},
33-
function(stdClass $command) {
34-
$this->assertObjectNotHasAttribute('readConcern', $command);
33+
function(array $event) {
34+
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
3535
}
3636
);
3737
}
@@ -48,8 +48,8 @@ function() {
4848

4949
$operation->execute($this->getPrimaryServer());
5050
},
51-
function(stdClass $command) {
52-
$this->assertObjectNotHasAttribute('writeConcern', $command);
51+
function(array $event) {
52+
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
5353
}
5454
);
5555
}
@@ -70,8 +70,8 @@ function() {
7070

7171
$operation->execute($this->getPrimaryServer());
7272
},
73-
function(stdClass $command) {
74-
$this->assertObjectHasAttribute('lsid', $command);
73+
function(array $event) {
74+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
7575
}
7676
);
7777
}

tests/Operation/FindFunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ function() {
2525

2626
$operation->execute($this->getPrimaryServer());
2727
},
28-
function(stdClass $command) {
29-
$this->assertObjectNotHasAttribute('readConcern', $command);
28+
function(array $event) {
29+
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
3030
}
3131
);
3232
}
@@ -99,8 +99,8 @@ function() {
9999

100100
$operation->execute($this->getPrimaryServer());
101101
},
102-
function(stdClass $command) {
103-
$this->assertObjectHasAttribute('lsid', $command);
102+
function(array $event) {
103+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
104104
}
105105
);
106106
}

tests/Operation/InsertManyFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ function() {
7070

7171
$operation->execute($this->getPrimaryServer());
7272
},
73-
function(stdClass $command) {
74-
$this->assertObjectHasAttribute('lsid', $command);
73+
function(array $event) {
74+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
7575
}
7676
);
7777
}

tests/Operation/InsertOneFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ function() {
8585

8686
$operation->execute($this->getPrimaryServer());
8787
},
88-
function(stdClass $command) {
89-
$this->assertObjectHasAttribute('lsid', $command);
88+
function(array $event) {
89+
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
9090
}
9191
);
9292
}

0 commit comments

Comments
 (0)