Skip to content

Commit 0f848cb

Browse files
committed
Refactor CommandObserver to track all three APM events
1 parent 2a288a0 commit 0f848cb

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
}

0 commit comments

Comments
 (0)