@@ -8,14 +8,10 @@ MongoDB\Driver\Monitoring\CommandFailedEvent
88<?php
99require_once __DIR__ . "/../utils/basic.inc " ;
1010
11- $ m = create_test_manager ();
12-
1311class MySubscriber implements MongoDB \Driver \Monitoring \CommandSubscriber
1412{
15- public function commandStarted ( \ MongoDB \Driver \Monitoring \CommandStartedEvent $ event ): void
13+ public function commandStarted (MongoDB \Driver \Monitoring \CommandStartedEvent $ event ): void
1614 {
17- echo "started: " , $ event ->getCommandName (), "\n" ;
18-
1915 /* bson_get_monotonic_time() may only have 10-16 millisecond precision
2016 * on Windows. Sleep to ensure that a non-zero value is reported for
2117 * CommandFailedEvent's duration. */
@@ -24,51 +20,51 @@ class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
2420 }
2521 }
2622
27- public function commandSucceeded ( \ MongoDB \Driver \Monitoring \CommandSucceededEvent $ event ): void
23+ public function commandSucceeded (MongoDB \Driver \Monitoring \CommandSucceededEvent $ event ): void
2824 {
2925 }
3026
31- public function commandFailed ( \ MongoDB \Driver \Monitoring \CommandFailedEvent $ event ): void
27+ public function commandFailed (MongoDB \Driver \Monitoring \CommandFailedEvent $ event ): void
3228 {
33- echo "failed: " , $ event ->getCommandName (), "\n" ;
34- echo "- getError() returns an object: " , is_object ( $ event ->getError () ) ? 'yes ' : 'no ' , "\n" ;
35- echo "- getError() returns an MongoDB\Driver\Exception\Exception object: " , $ event ->getError () instanceof MongoDB \Driver \Exception \Exception ? 'yes ' : 'no ' , "\n" ;
36- echo "- getDurationMicros() returns an integer: " , is_integer ( $ event ->getDurationMicros () ) ? 'yes ' : 'no ' , "\n" ;
37- echo "- getDurationMicros() returns > 0: " , $ event ->getDurationMicros () > 0 ? 'yes ' : 'no ' , "\n" ;
38- echo "- getCommandName() returns a string: " , is_string ( $ event ->getCommandName () ) ? 'yes ' : 'no ' , "\n" ;
39- echo "- getCommandName() returns ' " , $ event ->getCommandName (), "' \n" ;
40- echo "- getServer() returns an object: " , is_object ( $ event ->getServer () ) ? 'yes ' : 'no ' , "\n" ;
41- echo "- getServer() returns a Server object: " , $ event ->getServer () instanceof MongoDB \Driver \Server ? 'yes ' : 'no ' , "\n" ;
42- echo "- getOperationId() returns a string: " , is_string ( $ event ->getOperationId () ) ? 'yes ' : 'no ' , "\n" ;
43- echo "- getRequestId() returns a string: " , is_string ( $ event ->getRequestId () ) ? 'yes ' : 'no ' , "\n" ;
29+ var_dump ($ event ->getCommandName ());
30+ var_dump ($ event ->getDatabaseName ());
31+ var_dump ($ event ->getDurationMicros ());
32+ echo "getDurationMicros() returns > 0: " , $ event ->getDurationMicros () > 0 ? 'yes ' : 'no ' , "\n" ;
33+ var_dump ($ event ->getError () instanceof MongoDB \Driver \Exception \Exception);
34+ var_dump ($ event ->getOperationId ());
35+ var_dump ($ event ->getReply ());
36+ var_dump ($ event ->getRequestId ());
37+ var_dump ($ event ->getServer ());
38+
39+ /* Note: getServerConnectionId() and getServiceId() have more stringent
40+ * requirements and are tested separately. */
4441 }
4542}
4643
47- $ subscriber = new MySubscriber ;
44+ $ manager = create_test_manager ();
45+
46+ $ subscriber = new MySubscriber ();
47+ MongoDB \Driver \Monitoring \addSubscriber ($ subscriber );
4848
49- MongoDB \Driver \Monitoring \addSubscriber ( $ subscriber );
49+ $ command = new MongoDB \Driver \Command ([ ' unsupportedCommand ' => 1 ] );
5050
51- $ primary = get_primary_server (URI );
52- $ command = new \MongoDB \Driver \Command ([
53- 'aggregate ' => COLLECTION_NAME ,
54- 'pipeline ' => [['$unsupported ' => 1 ]]
55- ]);
5651try {
57- $ primary ->executeCommand (DATABASE_NAME , $ command );
52+ $ manager ->executeCommand (' admin ' , $ command );
5853} catch (Exception $ e ) {
59- /* Swallow */
6054}
55+
6156?>
62- --EXPECT--
63- started: aggregate
64- failed: aggregate
65- - getError() returns an object: yes
66- - getError() returns an MongoDB\Driver\Exception\Exception object: yes
67- - getDurationMicros() returns an integer: yes
68- - getDurationMicros() returns > 0: yes
69- - getCommandName() returns a string: yes
70- - getCommandName() returns 'aggregate'
71- - getServer() returns an object: yes
72- - getServer() returns a Server object: yes
73- - getOperationId() returns a string: yes
74- - getRequestId() returns a string: yes
57+ --EXPECTF--
58+ string(18) "unsupportedCommand"
59+ string(5) "admin"
60+ int(%d)
61+ getDurationMicros() returns > 0: yes
62+ bool(true)
63+ string(%d) "%d"
64+ object(stdClass)#%d (%d) {
65+ %A
66+ }
67+ string(%d) "%d"
68+ object(MongoDB\Driver\Server)#%d (%d) {
69+ %A
70+ }
0 commit comments