@@ -8,14 +8,10 @@ MongoDB\Driver\Monitoring\CommandFailedEvent
8
8
<?php
9
9
require_once __DIR__ . "/../utils/basic.inc " ;
10
10
11
- $ m = create_test_manager ();
12
-
13
11
class MySubscriber implements MongoDB \Driver \Monitoring \CommandSubscriber
14
12
{
15
- public function commandStarted ( \ MongoDB \Driver \Monitoring \CommandStartedEvent $ event ): void
13
+ public function commandStarted (MongoDB \Driver \Monitoring \CommandStartedEvent $ event ): void
16
14
{
17
- echo "started: " , $ event ->getCommandName (), "\n" ;
18
-
19
15
/* bson_get_monotonic_time() may only have 10-16 millisecond precision
20
16
* on Windows. Sleep to ensure that a non-zero value is reported for
21
17
* CommandFailedEvent's duration. */
@@ -24,51 +20,51 @@ class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
24
20
}
25
21
}
26
22
27
- public function commandSucceeded ( \ MongoDB \Driver \Monitoring \CommandSucceededEvent $ event ): void
23
+ public function commandSucceeded (MongoDB \Driver \Monitoring \CommandSucceededEvent $ event ): void
28
24
{
29
25
}
30
26
31
- public function commandFailed ( \ MongoDB \Driver \Monitoring \CommandFailedEvent $ event ): void
27
+ public function commandFailed (MongoDB \Driver \Monitoring \CommandFailedEvent $ event ): void
32
28
{
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. */
44
41
}
45
42
}
46
43
47
- $ subscriber = new MySubscriber ;
44
+ $ manager = create_test_manager ();
45
+
46
+ $ subscriber = new MySubscriber ();
47
+ MongoDB \Driver \Monitoring \addSubscriber ($ subscriber );
48
48
49
- MongoDB \Driver \Monitoring \addSubscriber ( $ subscriber );
49
+ $ command = new MongoDB \Driver \Command ([ ' unsupportedCommand ' => 1 ] );
50
50
51
- $ primary = get_primary_server (URI );
52
- $ command = new \MongoDB \Driver \Command ([
53
- 'aggregate ' => COLLECTION_NAME ,
54
- 'pipeline ' => [['$unsupported ' => 1 ]]
55
- ]);
56
51
try {
57
- $ primary ->executeCommand (DATABASE_NAME , $ command );
52
+ $ manager ->executeCommand (' admin ' , $ command );
58
53
} catch (Exception $ e ) {
59
- /* Swallow */
60
54
}
55
+
61
56
?>
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