Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
a3bf7021
Commit
a3bf7021
authored
Dec 23, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-138: Support typeMap option for core classes
parent
99635c0b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
15 deletions
+83
-15
Client.php
src/Client.php
+24
-13
Collection.php
src/Collection.php
+10
-0
Database.php
src/Database.php
+11
-0
ClientTest.php
tests/ClientTest.php
+20
-2
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+6
-0
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+12
-0
No files found.
src/Client.php
View file @
a3bf7021
...
@@ -15,6 +15,7 @@ class Client
...
@@ -15,6 +15,7 @@ class Client
{
{
private
$manager
;
private
$manager
;
private
$uri
;
private
$uri
;
private
$typeMap
;
/**
/**
* Constructs a new Client instance.
* Constructs a new Client instance.
...
@@ -23,15 +24,29 @@ class Client
...
@@ -23,15 +24,29 @@ class Client
* cluster of servers. It serves as a gateway for accessing individual
* cluster of servers. It serves as a gateway for accessing individual
* databases and collections.
* databases and collections.
*
*
* Supported driver-specific options:
*
* * typeMap (array): Default type map for cursors and BSON documents.
*
* Other options are documented in MongoDB\Driver\Manager::__construct().
*
* @see http://docs.mongodb.org/manual/reference/connection-string/
* @see http://docs.mongodb.org/manual/reference/connection-string/
* @see http://php.net/manual/en/mongodb-driver-manager.construct.php
* @see http://php.net/manual/en/mongodb.persistence.php#mongodb.persistence.typemaps
* @param string $uri MongoDB connection string
* @param string $uri MongoDB connection string
* @param array $
options
Additional connection string options
* @param array $
uriOptions
Additional connection string options
* @param array $driverOptions Driver-specific options
* @param array $driverOptions Driver-specific options
* @throws InvalidArgumentException
*/
*/
public
function
__construct
(
$uri
=
'mongodb://localhost:27017'
,
array
$
o
ptions
=
[],
array
$driverOptions
=
[])
public
function
__construct
(
$uri
=
'mongodb://localhost:27017'
,
array
$
uriO
ptions
=
[],
array
$driverOptions
=
[])
{
{
$this
->
manager
=
new
Manager
(
$uri
,
$options
,
$driverOptions
);
if
(
isset
(
$driverOptions
[
'typeMap'
])
&&
!
is_array
(
$driverOptions
[
'typeMap'
]))
{
throw
new
InvalidArgumentTypeException
(
'"typeMap" driver option'
,
$driverOptions
[
'typeMap'
],
'array'
);
}
$this
->
manager
=
new
Manager
(
$uri
,
$uriOptions
,
$driverOptions
);
$this
->
uri
=
(
string
)
$uri
;
$this
->
uri
=
(
string
)
$uri
;
$this
->
typeMap
=
isset
(
$driverOptions
[
'typeMap'
])
?
$driverOptions
[
'typeMap'
]
:
null
;
}
}
/**
/**
...
@@ -45,6 +60,7 @@ class Client
...
@@ -45,6 +60,7 @@ class Client
return
[
return
[
'manager'
=>
$this
->
manager
,
'manager'
=>
$this
->
manager
,
'uri'
=>
$this
->
uri
,
'uri'
=>
$this
->
uri
,
'typeMap'
=>
$this
->
typeMap
,
];
];
}
}
...
@@ -97,28 +113,23 @@ class Client
...
@@ -97,28 +113,23 @@ class Client
*/
*/
public
function
selectCollection
(
$databaseName
,
$collectionName
,
array
$options
=
[])
public
function
selectCollection
(
$databaseName
,
$collectionName
,
array
$options
=
[])
{
{
$options
+=
[
'typeMap'
=>
$this
->
typeMap
];
return
new
Collection
(
$this
->
manager
,
$databaseName
.
'.'
.
$collectionName
,
$options
);
return
new
Collection
(
$this
->
manager
,
$databaseName
.
'.'
.
$collectionName
,
$options
);
}
}
/**
/**
* Select a database.
* Select a database.
*
*
* Supported options:
* @see Database::__construct() for supported options
*
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* preference to use for database operations and selected collections.
* Defaults to the Client's read preference.
*
* * writeConcern (MongoDB\Driver\WriteConcern): The default write concern
* to use for database operations and selected collections. Defaults to
* the Client's write concern.
*
* @param string $databaseName Name of the database to select
* @param string $databaseName Name of the database to select
* @param array $options Database constructor options
* @param array $options Database constructor options
* @return Database
* @return Database
*/
*/
public
function
selectDatabase
(
$databaseName
,
array
$options
=
[])
public
function
selectDatabase
(
$databaseName
,
array
$options
=
[])
{
{
$options
+=
[
'typeMap'
=>
$this
->
typeMap
];
return
new
Database
(
$this
->
manager
,
$databaseName
,
$options
);
return
new
Database
(
$this
->
manager
,
$databaseName
,
$options
);
}
}
}
}
src/Collection.php
View file @
a3bf7021
...
@@ -45,6 +45,7 @@ class Collection
...
@@ -45,6 +45,7 @@ class Collection
private
$manager
;
private
$manager
;
private
$readConcern
;
private
$readConcern
;
private
$readPreference
;
private
$readPreference
;
private
$typeMap
;
private
$writeConcern
;
private
$writeConcern
;
/**
/**
...
@@ -62,6 +63,8 @@ class Collection
...
@@ -62,6 +63,8 @@ class Collection
* preference to use for collection operations. Defaults to the Manager's
* preference to use for collection operations. Defaults to the Manager's
* read preference.
* read preference.
*
*
* * typeMap (array): Default type map for cursors and BSON documents.
*
* * writeConcern (MongoDB\Driver\WriteConcern): The default write concern
* * writeConcern (MongoDB\Driver\WriteConcern): The default write concern
* to use for collection operations. Defaults to the Manager's write
* to use for collection operations. Defaults to the Manager's write
* concern.
* concern.
...
@@ -90,6 +93,10 @@ class Collection
...
@@ -90,6 +93,10 @@ class Collection
throw
new
InvalidArgumentTypeException
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
throw
new
InvalidArgumentTypeException
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
}
}
if
(
isset
(
$options
[
'typeMap'
])
&&
!
is_array
(
$options
[
'typeMap'
]))
{
throw
new
InvalidArgumentTypeException
(
'"typeMap" option'
,
$options
[
'typeMap'
],
'array'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
!
$options
[
'writeConcern'
]
instanceof
WriteConcern
)
{
if
(
isset
(
$options
[
'writeConcern'
])
&&
!
$options
[
'writeConcern'
]
instanceof
WriteConcern
)
{
throw
new
InvalidArgumentTypeException
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
throw
new
InvalidArgumentTypeException
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
}
...
@@ -97,6 +104,7 @@ class Collection
...
@@ -97,6 +104,7 @@ class Collection
$this
->
manager
=
$manager
;
$this
->
manager
=
$manager
;
$this
->
readConcern
=
isset
(
$options
[
'readConcern'
])
?
$options
[
'readConcern'
]
:
$this
->
manager
->
getReadConcern
();
$this
->
readConcern
=
isset
(
$options
[
'readConcern'
])
?
$options
[
'readConcern'
]
:
$this
->
manager
->
getReadConcern
();
$this
->
readPreference
=
isset
(
$options
[
'readPreference'
])
?
$options
[
'readPreference'
]
:
$this
->
manager
->
getReadPreference
();
$this
->
readPreference
=
isset
(
$options
[
'readPreference'
])
?
$options
[
'readPreference'
]
:
$this
->
manager
->
getReadPreference
();
$this
->
typeMap
=
isset
(
$options
[
'typeMap'
])
?
$options
[
'typeMap'
]
:
null
;
$this
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
$this
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
}
}
...
@@ -114,6 +122,7 @@ class Collection
...
@@ -114,6 +122,7 @@ class Collection
'manager'
=>
$this
->
manager
,
'manager'
=>
$this
->
manager
,
'readConcern'
=>
$this
->
readConcern
,
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'readPreference'
=>
$this
->
readPreference
,
'typeMap'
=>
$this
->
typeMap
,
'writeConcern'
=>
$this
->
writeConcern
,
'writeConcern'
=>
$this
->
writeConcern
,
];
];
}
}
...
@@ -664,6 +673,7 @@ class Collection
...
@@ -664,6 +673,7 @@ class Collection
$options
+=
[
$options
+=
[
'readConcern'
=>
$this
->
readConcern
,
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'readPreference'
=>
$this
->
readPreference
,
'typeMap'
=>
$this
->
typeMap
,
'writeConcern'
=>
$this
->
writeConcern
,
'writeConcern'
=>
$this
->
writeConcern
,
];
];
...
...
src/Database.php
View file @
a3bf7021
...
@@ -25,6 +25,7 @@ class Database
...
@@ -25,6 +25,7 @@ class Database
private
$manager
;
private
$manager
;
private
$readConcern
;
private
$readConcern
;
private
$readPreference
;
private
$readPreference
;
private
$typeMap
;
private
$writeConcern
;
private
$writeConcern
;
/**
/**
...
@@ -43,6 +44,8 @@ class Database
...
@@ -43,6 +44,8 @@ class Database
* preference to use for database operations and selected collections.
* preference to use for database operations and selected collections.
* Defaults to the Manager's read preference.
* Defaults to the Manager's read preference.
*
*
* * typeMap (array): Default type map for cursors and BSON documents.
*
* * writeConcern (MongoDB\Driver\WriteConcern): The default write concern
* * writeConcern (MongoDB\Driver\WriteConcern): The default write concern
* to use for database operations and selected collections. Defaults to
* to use for database operations and selected collections. Defaults to
* the Manager's write concern.
* the Manager's write concern.
...
@@ -66,6 +69,10 @@ class Database
...
@@ -66,6 +69,10 @@ class Database
throw
new
InvalidArgumentTypeException
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
throw
new
InvalidArgumentTypeException
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
}
}
if
(
isset
(
$options
[
'typeMap'
])
&&
!
is_array
(
$options
[
'typeMap'
]))
{
throw
new
InvalidArgumentTypeException
(
'"typeMap" option'
,
$options
[
'typeMap'
],
'array'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
!
$options
[
'writeConcern'
]
instanceof
WriteConcern
)
{
if
(
isset
(
$options
[
'writeConcern'
])
&&
!
$options
[
'writeConcern'
]
instanceof
WriteConcern
)
{
throw
new
InvalidArgumentTypeException
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
throw
new
InvalidArgumentTypeException
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
}
...
@@ -74,6 +81,7 @@ class Database
...
@@ -74,6 +81,7 @@ class Database
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
readConcern
=
isset
(
$options
[
'readConcern'
])
?
$options
[
'readConcern'
]
:
$this
->
manager
->
getReadConcern
();
$this
->
readConcern
=
isset
(
$options
[
'readConcern'
])
?
$options
[
'readConcern'
]
:
$this
->
manager
->
getReadConcern
();
$this
->
readPreference
=
isset
(
$options
[
'readPreference'
])
?
$options
[
'readPreference'
]
:
$this
->
manager
->
getReadPreference
();
$this
->
readPreference
=
isset
(
$options
[
'readPreference'
])
?
$options
[
'readPreference'
]
:
$this
->
manager
->
getReadPreference
();
$this
->
typeMap
=
isset
(
$options
[
'typeMap'
])
?
$options
[
'typeMap'
]
:
null
;
$this
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
$this
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
}
}
...
@@ -90,6 +98,7 @@ class Database
...
@@ -90,6 +98,7 @@ class Database
'manager'
=>
$this
->
manager
,
'manager'
=>
$this
->
manager
,
'readConcern'
=>
$this
->
readConcern
,
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'readPreference'
=>
$this
->
readPreference
,
'typeMap'
=>
$this
->
typeMap
,
'writeConcern'
=>
$this
->
writeConcern
,
'writeConcern'
=>
$this
->
writeConcern
,
];
];
}
}
...
@@ -211,6 +220,7 @@ class Database
...
@@ -211,6 +220,7 @@ class Database
$options
+=
[
$options
+=
[
'readConcern'
=>
$this
->
readConcern
,
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'readPreference'
=>
$this
->
readPreference
,
'typeMap'
=>
$this
->
typeMap
,
'writeConcern'
=>
$this
->
writeConcern
,
'writeConcern'
=>
$this
->
writeConcern
,
];
];
...
@@ -229,6 +239,7 @@ class Database
...
@@ -229,6 +239,7 @@ class Database
$options
+=
[
$options
+=
[
'readConcern'
=>
$this
->
readConcern
,
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'readPreference'
=>
$this
->
readPreference
,
'typeMap'
=>
$this
->
typeMap
,
'writeConcern'
=>
$this
->
writeConcern
,
'writeConcern'
=>
$this
->
writeConcern
,
];
];
...
...
tests/ClientTest.php
View file @
a3bf7021
...
@@ -36,7 +36,11 @@ class ClientTest extends TestCase
...
@@ -36,7 +36,11 @@ class ClientTest extends TestCase
'w'
=>
WriteConcern
::
MAJORITY
,
'w'
=>
WriteConcern
::
MAJORITY
,
];
];
$client
=
new
Client
(
$this
->
getUri
(),
$uriOptions
);
$driverOptions
=
[
'typeMap'
=>
[
'root'
=>
'array'
],
];
$client
=
new
Client
(
$this
->
getUri
(),
$uriOptions
,
$driverOptions
);
$collection
=
$client
->
selectCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$collection
=
$client
->
selectCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$debug
=
$collection
->
__debugInfo
();
$debug
=
$collection
->
__debugInfo
();
...
@@ -44,6 +48,8 @@ class ClientTest extends TestCase
...
@@ -44,6 +48,8 @@ class ClientTest extends TestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
@@ -53,6 +59,7 @@ class ClientTest extends TestCase
...
@@ -53,6 +59,7 @@ class ClientTest extends TestCase
$collectionOptions
=
[
$collectionOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'typeMap'
=>
[
'root'
=>
'array'
],
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -64,6 +71,8 @@ class ClientTest extends TestCase
...
@@ -64,6 +71,8 @@ class ClientTest extends TestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
@@ -78,7 +87,11 @@ class ClientTest extends TestCase
...
@@ -78,7 +87,11 @@ class ClientTest extends TestCase
'w'
=>
WriteConcern
::
MAJORITY
,
'w'
=>
WriteConcern
::
MAJORITY
,
];
];
$client
=
new
Client
(
$this
->
getUri
(),
$uriOptions
);
$driverOptions
=
[
'typeMap'
=>
[
'root'
=>
'array'
],
];
$client
=
new
Client
(
$this
->
getUri
(),
$uriOptions
,
$driverOptions
);
$database
=
$client
->
selectDatabase
(
$this
->
getDatabaseName
());
$database
=
$client
->
selectDatabase
(
$this
->
getDatabaseName
());
$debug
=
$database
->
__debugInfo
();
$debug
=
$database
->
__debugInfo
();
...
@@ -86,6 +99,8 @@ class ClientTest extends TestCase
...
@@ -86,6 +99,8 @@ class ClientTest extends TestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
@@ -95,6 +110,7 @@ class ClientTest extends TestCase
...
@@ -95,6 +110,7 @@ class ClientTest extends TestCase
$databaseOptions
=
[
$databaseOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'typeMap'
=>
[
'root'
=>
'array'
],
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -106,6 +122,8 @@ class ClientTest extends TestCase
...
@@ -106,6 +122,8 @@ class ClientTest extends TestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
...
tests/Collection/CollectionFunctionalTest.php
View file @
a3bf7021
...
@@ -117,6 +117,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -117,6 +117,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
$collectionOptions
=
[
$collectionOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'typeMap'
=>
[
'root'
=>
'array'
],
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -128,6 +129,8 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -128,6 +129,8 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
@@ -137,6 +140,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -137,6 +140,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
$collectionOptions
=
[
$collectionOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'typeMap'
=>
[
'root'
=>
'array'
],
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -147,6 +151,8 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -147,6 +151,8 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
a3bf7021
...
@@ -106,6 +106,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -106,6 +106,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$databaseOptions
=
[
$databaseOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'typeMap'
=>
[
'root'
=>
'array'
],
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -117,6 +118,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -117,6 +118,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
@@ -126,6 +129,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -126,6 +129,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$collectionOptions
=
[
$collectionOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'typeMap'
=>
[
'root'
=>
'array'
],
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -136,6 +140,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -136,6 +140,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
@@ -145,6 +151,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -145,6 +151,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$databaseOptions
=
[
$databaseOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'typeMap'
=>
[
'root'
=>
'array'
],
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -156,6 +163,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -156,6 +163,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
@@ -165,6 +174,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -165,6 +174,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$databaseOptions
=
[
$databaseOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'typeMap'
=>
[
'root'
=>
'array'
],
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -175,6 +185,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -175,6 +185,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInternalType
(
'array'
,
$debug
[
'typeMap'
]);
$this
->
assertSame
([
'root'
=>
'array'
],
$debug
[
'typeMap'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment