Skip to content

Commit a4740e8

Browse files
authored
PHPC-1989: Fix missing fields in CommandSucceededEvent debug output (#1266)
* PHPC-1989: Fix missing fields in CommandSucceededEvent debug output Add debug output tests for APM event classes. * Rename tests for APM event classes
1 parent f9fe7ef commit a4740e8

16 files changed

+174
-2
lines changed

src/MongoDB/Monitoring/CommandSucceededEvent.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(phongo_compat_
248248
sprintf(operation_id, "%" PRIu64, intern->operation_id);
249249
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
250250

251-
if (php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
251+
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
252252
zval_ptr_dtor(&reply_state.zchild);
253253
goto done;
254254
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
--TEST--
2+
MongoDB\Driver\Monitoring\CommandFailedEvent debug output
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_live(); ?>
6+
--FILE--
7+
<?php
8+
require_once __DIR__ . "/../utils/basic.inc";
9+
10+
class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
11+
{
12+
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event)
13+
{
14+
}
15+
16+
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event)
17+
{
18+
}
19+
20+
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event)
21+
{
22+
var_dump($event);
23+
}
24+
}
25+
26+
$manager = create_test_manager();
27+
$manager->addSubscriber(new MySubscriber);
28+
29+
$command = new MongoDB\Driver\Command([
30+
'aggregate' => COLLECTION_NAME,
31+
'pipeline' => [['$unsupported' => 1]],
32+
]);
33+
34+
/* Note: Although executeCommand() throws a CommandException, CommandFailedEvent
35+
* will report a ServerException for its "error" property (PHPC-1990) */
36+
throws(function() use ($manager, $command) {
37+
$manager->executeCommand(DATABASE_NAME, $command);
38+
}, MongoDB\Driver\Exception\CommandException::class);
39+
40+
?>
41+
===DONE===
42+
<?php exit(0); ?>
43+
--EXPECTF--
44+
object(MongoDB\Driver\Monitoring\CommandFailedEvent)#%d (%d) {
45+
["commandName"]=>
46+
string(9) "aggregate"
47+
["durationMicros"]=>
48+
int(%d)
49+
["error"]=>
50+
object(MongoDB\Driver\Exception\ServerException)#%d (%d) {%A
51+
}
52+
["operationId"]=>
53+
string(%d) "%d"
54+
["reply"]=>
55+
object(stdClass)#%d (%d) {%A
56+
}
57+
["requestId"]=>
58+
string(%d) "%d"
59+
["server"]=>
60+
object(MongoDB\Driver\Server)#%d (%d) {%A
61+
}
62+
["serviceId"]=>
63+
%r(NULL|object\(MongoDB\\BSON\\ObjectId\).*)%r
64+
}
65+
OK: Got MongoDB\Driver\Exception\CommandException
66+
===DONE===

tests/apm/monitoring-commandFailed-003.phpt renamed to tests/apm/commandFailedEvent-getReply-001.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
MongoDB\Driver\Monitoring\CommandFailedEvent
2+
MongoDB\Driver\Monitoring\CommandFailedEvent::getReply()
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_live(); ?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
MongoDB\Driver\Monitoring\CommandStartedEvent debug output
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_live(); ?>
6+
--FILE--
7+
<?php
8+
require_once __DIR__ . "/../utils/basic.inc";
9+
10+
class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
11+
{
12+
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event)
13+
{
14+
var_dump($event);
15+
}
16+
17+
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event)
18+
{
19+
}
20+
21+
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event)
22+
{
23+
}
24+
}
25+
26+
$manager = create_test_manager();
27+
$manager->addSubscriber(new MySubscriber);
28+
29+
$manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
30+
31+
?>
32+
===DONE===
33+
<?php exit(0); ?>
34+
--EXPECTF--
35+
object(MongoDB\Driver\Monitoring\CommandStartedEvent)#%d (%d) {
36+
["command"]=>
37+
object(stdClass)#%d (%d) {%A
38+
}
39+
["commandName"]=>
40+
string(4) "ping"
41+
["databaseName"]=>
42+
string(%d) "%s"
43+
["operationId"]=>
44+
string(%d) "%d"
45+
["requestId"]=>
46+
string(%d) "%d"
47+
["server"]=>
48+
object(MongoDB\Driver\Server)#%d (%d) {%A
49+
}
50+
["serviceId"]=>
51+
%r(NULL|object\(MongoDB\\BSON\\ObjectId\).*)%r
52+
}
53+
===DONE===
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
MongoDB\Driver\Monitoring\CommandSucceededEvent debug output
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_live(); ?>
6+
--FILE--
7+
<?php
8+
require_once __DIR__ . "/../utils/basic.inc";
9+
10+
class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
11+
{
12+
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event)
13+
{
14+
}
15+
16+
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event)
17+
{
18+
var_dump($event);
19+
}
20+
21+
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event)
22+
{
23+
}
24+
}
25+
26+
$manager = create_test_manager();
27+
$manager->addSubscriber(new MySubscriber);
28+
29+
$manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
30+
31+
?>
32+
===DONE===
33+
<?php exit(0); ?>
34+
--EXPECTF--
35+
object(MongoDB\Driver\Monitoring\CommandSucceededEvent)#%d (%d) {
36+
["commandName"]=>
37+
string(4) "ping"
38+
["durationMicros"]=>
39+
int(%d)
40+
["operationId"]=>
41+
string(%d) "%d"
42+
["reply"]=>
43+
object(stdClass)#%d (%d) {%A
44+
}
45+
["requestId"]=>
46+
string(%d) "%d"
47+
["server"]=>
48+
object(MongoDB\Driver\Server)#%d (%d) {%A
49+
}
50+
["serviceId"]=>
51+
%r(NULL|object\(MongoDB\\BSON\\ObjectId\).*)%r
52+
}
53+
===DONE===

0 commit comments

Comments
 (0)