@@ -12,20 +12,29 @@ $manager = new MongoDB\Driver\Manager(URI);
12
12
$ command = new MongoDB \Driver \Command (['ping ' => 1 ]);
13
13
$ manager ->executeCommand (DATABASE_NAME , $ command );
14
14
15
- foreach ($ manager ->getServers () as $ server ) {
16
- $ tags = $ server ->getTags ();
17
- echo "dc: " , array_key_exists ('dc ' , $ tags ) ? $ tags ['dc ' ] : 'not set ' , "\n" ;
18
- echo "ordinal: " , array_key_exists ('ordinal ' , $ tags ) ? $ tags ['ordinal ' ] : 'not set ' , "\n" ;
15
+ function assertSomeServerHasTags (array $ servers , array $ expectedTags ) {
16
+ foreach ($ servers as $ server ) {
17
+ /* Using a non-strict comparison guards against tags being returned in
18
+ * a different order than expected. */
19
+ if ($ expectedTags == $ server ->getTags ()) {
20
+ printf ("Found server with tags: %s \n" , json_encode ($ expectedTags ));
21
+ return ;
22
+ }
23
+ }
24
+
25
+ printf ("No server has tags: %s \n" , json_encode ($ expectedTags ));
19
26
}
20
27
28
+ $ servers = $ manager ->getServers ();
29
+ assertSomeServerHasTags ($ servers , ['dc ' => 'ny ' , 'ordinal ' => 'one ' ]);
30
+ assertSomeServerHasTags ($ servers , ['dc ' => 'pa ' , 'ordinal ' => 'two ' ]);
31
+ assertSomeServerHasTags ($ servers , []);
32
+
21
33
?>
22
34
===DONE===
23
35
<?php exit (0 ); ?>
24
36
--EXPECT--
25
- dc: ny
26
- ordinal: one
27
- dc: pa
28
- ordinal: two
29
- dc: not set
30
- ordinal: not set
37
+ Found server with tags: {"dc":"ny","ordinal":"one"}
38
+ Found server with tags: {"dc":"pa","ordinal":"two"}
39
+ Found server with tags: []
31
40
===DONE===
0 commit comments