1
1
<?php
2
2
3
+ use MongoDB \Driver \BulkWrite ;
3
4
use MongoDB \Driver \Command ;
4
5
use MongoDB \Driver \Manager ;
5
6
use MongoDB \Driver \ReadPreference ;
6
7
use MongoDB \Driver \Server ;
8
+ use MongoDB \Driver \WriteConcern ;
9
+ use MongoDB \Driver \WriteConcernError ;
10
+ use MongoDB \Driver \WriteError ;
11
+ use MongoDB \Driver \WriteResult ;
7
12
use MongoDB \Driver \Exception \ConnectionException ;
8
13
use MongoDB \Driver \Exception \RuntimeException ;
9
14
@@ -53,7 +58,7 @@ function drop_collection($uri, $databaseName, $collectionName)
53
58
$ server ->executeCommand (
54
59
$ databaseName ,
55
60
$ command ,
56
- [ 'writeConcern ' => new \ MongoDB \ Driver \ WriteConcern ( \ MongoDB \ Driver \ WriteConcern::MAJORITY ) ]
61
+ ['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY ) ]
57
62
);
58
63
} catch (RuntimeException $ e ) {
59
64
if ($ e ->getMessage () !== 'ns not found ' ) {
@@ -162,11 +167,11 @@ function get_server_storage_engine($uri)
162
167
/**
163
168
* Helper to return the version of a specific server.
164
169
*
165
- * @param MongoDB\Driver\ Server $server
170
+ * @param Server $server
166
171
* @return string
167
172
* @throws RuntimeException
168
173
*/
169
- function get_server_version_from_server (MongoDB \ Driver \ Server $ server )
174
+ function get_server_version_from_server (Server $ server )
170
175
{
171
176
$ command = new Command (['buildInfo ' => 1 ]);
172
177
$ cursor = $ server ->executeCommand ('admin ' , $ command );
@@ -432,15 +437,15 @@ function SLOW() {
432
437
}
433
438
}
434
439
435
- function loadFixtures (\ MongoDB \ Driver \ Manager $ manager , $ dbname = DATABASE_NAME , $ collname = COLLECTION_NAME , $ filename = null )
440
+ function loadFixtures (Manager $ manager , $ dbname = DATABASE_NAME , $ collname = COLLECTION_NAME , $ filename = null )
436
441
{
437
442
if (!$ filename ) {
438
443
$ filename = "compress.zlib:// " . __DIR__ . "/ " . "PHONGO-FIXTURES.json.gz " ;
439
444
}
440
445
441
- $ bulk = new MongoDB \ Driver \ BulkWrite (['ordered ' => false ]);
446
+ $ bulk = new BulkWrite (['ordered ' => false ]);
442
447
443
- $ server = $ manager ->selectServer (new MongoDB \ Driver \ ReadPreference (MongoDB \ Driver \ ReadPreference::RP_PRIMARY ));
448
+ $ server = $ manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
444
449
445
450
$ data = file_get_contents ($ filename );
446
451
$ array = json_decode ($ data );
@@ -573,12 +578,13 @@ function throws($function, $exceptionname, $infunction = null) {
573
578
}
574
579
echo "FAILED: Expected $ exceptionname thrown, but no exception thrown! \n" ;
575
580
}
576
- function printServer (MongoDB \Driver \Server $ server )
581
+
582
+ function printServer (Server $ server )
577
583
{
578
584
printf ("server: %s:%d \n" , $ server ->getHost (), $ server ->getPort ());
579
585
}
580
586
581
- function printWriteResult (MongoDB \ Driver \ WriteResult $ result , $ details = true )
587
+ function printWriteResult (WriteResult $ result , $ details = true )
582
588
{
583
589
printServer ($ result ->getServer ());
584
590
@@ -601,7 +607,7 @@ function printWriteResult(MongoDB\Driver\WriteResult $result, $details = true)
601
607
}
602
608
}
603
609
604
- function printWriteConcernError (MongoDB \ Driver \ WriteConcernError $ error = null , $ details )
610
+ function printWriteConcernError (WriteConcernError $ error = null , $ details )
605
611
{
606
612
if ($ error ) {
607
613
/* This stuff is generated by the server, no need for us to test it */
@@ -617,7 +623,7 @@ function printWriteConcernError(MongoDB\Driver\WriteConcernError $error = null,
617
623
}
618
624
}
619
625
620
- function printWriteError (MongoDB \ Driver \ WriteError $ error )
626
+ function printWriteError (WriteError $ error )
621
627
{
622
628
var_dump ($ error );
623
629
printf ("writeError[%d].message: %s \n" , $ error ->getIndex (), $ error ->getMessage ());
@@ -646,7 +652,7 @@ function def($arr) {
646
652
}
647
653
}
648
654
649
- function configureFailPoint (MongoDB \ Driver \ Manager $ manager , $ failPoint , $ mode , array $ data = [])
655
+ function configureFailPoint (Manager $ manager , $ failPoint , $ mode , array $ data = [])
650
656
{
651
657
$ doc = array (
652
658
'configureFailPoint ' => $ failPoint ,
@@ -656,11 +662,11 @@ function configureFailPoint(MongoDB\Driver\Manager $manager, $failPoint, $mode,
656
662
$ doc ['data ' ] = $ data ;
657
663
}
658
664
659
- $ cmd = new MongoDB \ Driver \ Command ($ doc );
665
+ $ cmd = new Command ($ doc );
660
666
$ manager ->executeCommand ('admin ' , $ cmd );
661
667
}
662
668
663
- function failMaxTimeMS (MongoDB \ Driver \ Manager $ manager )
669
+ function failMaxTimeMS (Manager $ manager )
664
670
{
665
671
configureFailPoint ($ manager , 'maxTimeAlwaysTimeOut ' , [ 'times ' => 1 ]);
666
672
}
@@ -694,7 +700,7 @@ function fromJSON($var) {
694
700
695
701
/* Note: this fail point may terminate the mongod process, so you may want to
696
702
* use this in conjunction with a throwaway server. */
697
- function failGetMore (MongoDB \ Driver \ Manager $ manager )
703
+ function failGetMore (Manager $ manager )
698
704
{
699
705
/* We need to do version detection here */
700
706
$ primary = $ manager ->selectServer (new ReadPreference ('primary ' ));
0 commit comments