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
523ca61e
Commit
523ca61e
authored
Dec 17, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-130: Support readConcern option for Database and Collection
parent
ff9d54c2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
4 deletions
+71
-4
Collection.php
src/Collection.php
+19
-0
Database.php
src/Database.php
+28
-0
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+7
-0
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+17
-4
No files found.
src/Collection.php
View file @
523ca61e
...
@@ -5,6 +5,7 @@ namespace MongoDB;
...
@@ -5,6 +5,7 @@ namespace MongoDB;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\ReadConcern
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
...
@@ -42,6 +43,7 @@ class Collection
...
@@ -42,6 +43,7 @@ class Collection
private
$collectionName
;
private
$collectionName
;
private
$databaseName
;
private
$databaseName
;
private
$manager
;
private
$manager
;
private
$readConcern
;
private
$readPreference
;
private
$readPreference
;
private
$writeConcern
;
private
$writeConcern
;
...
@@ -53,6 +55,9 @@ class Collection
...
@@ -53,6 +55,9 @@ class Collection
*
*
* Supported options:
* Supported options:
*
*
* * readConcern (MongoDB\Driver\ReadConcern): The default read concern to
* use for collection operations. Defaults to the Manager's read concern.
*
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* 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.
...
@@ -77,6 +82,10 @@ class Collection
...
@@ -77,6 +82,10 @@ class Collection
$this
->
databaseName
=
$parts
[
0
];
$this
->
databaseName
=
$parts
[
0
];
$this
->
collectionName
=
$parts
[
1
];
$this
->
collectionName
=
$parts
[
1
];
if
(
isset
(
$options
[
'readConcern'
])
&&
!
$options
[
'readConcern'
]
instanceof
ReadConcern
)
{
throw
new
InvalidArgumentTypeException
(
'"readConcern" option'
,
$options
[
'readConcern'
],
'MongoDB\Driver\ReadConcern'
);
}
if
(
isset
(
$options
[
'readPreference'
])
&&
!
$options
[
'readPreference'
]
instanceof
ReadPreference
)
{
if
(
isset
(
$options
[
'readPreference'
])
&&
!
$options
[
'readPreference'
]
instanceof
ReadPreference
)
{
throw
new
InvalidArgumentTypeException
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
throw
new
InvalidArgumentTypeException
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
}
}
...
@@ -86,6 +95,7 @@ class Collection
...
@@ -86,6 +95,7 @@ class Collection
}
}
$this
->
manager
=
$manager
;
$this
->
manager
=
$manager
;
$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
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
$this
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
}
}
...
@@ -102,6 +112,7 @@ class Collection
...
@@ -102,6 +112,7 @@ class Collection
'collectionName'
=>
$this
->
collectionName
,
'collectionName'
=>
$this
->
collectionName
,
'databaseName'
=>
$this
->
databaseName
,
'databaseName'
=>
$this
->
databaseName
,
'manager'
=>
$this
->
manager
,
'manager'
=>
$this
->
manager
,
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'readPreference'
=>
$this
->
readPreference
,
'writeConcern'
=>
$this
->
writeConcern
,
'writeConcern'
=>
$this
->
writeConcern
,
];
];
...
@@ -621,6 +632,10 @@ class Collection
...
@@ -621,6 +632,10 @@ class Collection
*
*
* Supported options:
* Supported options:
*
*
* * readConcern (MongoDB\Driver\ReadConcern): The default read concern to
* use for collection operations. Defaults to this Collection's read
* concern.
*
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* preference to use for collection operations. Defaults to this
* preference to use for collection operations. Defaults to this
* Collection's read preference.
* Collection's read preference.
...
@@ -634,6 +649,10 @@ class Collection
...
@@ -634,6 +649,10 @@ class Collection
*/
*/
public
function
withOptions
(
array
$options
=
[])
public
function
withOptions
(
array
$options
=
[])
{
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
}
...
...
src/Database.php
View file @
523ca61e
...
@@ -7,6 +7,7 @@ use MongoDB\Driver\Command;
...
@@ -7,6 +7,7 @@ use MongoDB\Driver\Command;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Query
;
use
MongoDB\Driver\Query
;
use
MongoDB\Driver\ReadConcern
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
...
@@ -22,6 +23,7 @@ class Database
...
@@ -22,6 +23,7 @@ class Database
{
{
private
$databaseName
;
private
$databaseName
;
private
$manager
;
private
$manager
;
private
$readConcern
;
private
$readPreference
;
private
$readPreference
;
private
$writeConcern
;
private
$writeConcern
;
...
@@ -33,6 +35,10 @@ class Database
...
@@ -33,6 +35,10 @@ class Database
*
*
* Supported options:
* Supported options:
*
*
* * readConcern (MongoDB\Driver\ReadConcern): The default read concern to
* use for database operations and selected collections. Defaults to the
* Manager's read concern.
*
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* 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.
...
@@ -52,6 +58,10 @@ class Database
...
@@ -52,6 +58,10 @@ class Database
throw
new
InvalidArgumentException
(
'$databaseName is invalid: '
.
$databaseName
);
throw
new
InvalidArgumentException
(
'$databaseName is invalid: '
.
$databaseName
);
}
}
if
(
isset
(
$options
[
'readConcern'
])
&&
!
$options
[
'readConcern'
]
instanceof
ReadConcern
)
{
throw
new
InvalidArgumentTypeException
(
'"readConcern" option'
,
$options
[
'readConcern'
],
'MongoDB\Driver\ReadConcern'
);
}
if
(
isset
(
$options
[
'readPreference'
])
&&
!
$options
[
'readPreference'
]
instanceof
ReadPreference
)
{
if
(
isset
(
$options
[
'readPreference'
])
&&
!
$options
[
'readPreference'
]
instanceof
ReadPreference
)
{
throw
new
InvalidArgumentTypeException
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
throw
new
InvalidArgumentTypeException
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
}
}
...
@@ -62,6 +72,7 @@ class Database
...
@@ -62,6 +72,7 @@ class Database
$this
->
manager
=
$manager
;
$this
->
manager
=
$manager
;
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
databaseName
=
(
string
)
$databaseName
;
$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
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
$this
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
}
}
...
@@ -77,6 +88,7 @@ class Database
...
@@ -77,6 +88,7 @@ class Database
return
[
return
[
'databaseName'
=>
$this
->
databaseName
,
'databaseName'
=>
$this
->
databaseName
,
'manager'
=>
$this
->
manager
,
'manager'
=>
$this
->
manager
,
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'readPreference'
=>
$this
->
readPreference
,
'writeConcern'
=>
$this
->
writeConcern
,
'writeConcern'
=>
$this
->
writeConcern
,
];
];
...
@@ -191,6 +203,10 @@ class Database
...
@@ -191,6 +203,10 @@ class Database
*
*
* Supported options:
* Supported options:
*
*
* * readConcern (MongoDB\Driver\ReadConcern): The default read concern to
* use for collection operations. Defaults to the Database's read
* concern.
*
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* preference to use for collection operations. Defaults to the
* preference to use for collection operations. Defaults to the
* Database's read preference.
* Database's read preference.
...
@@ -205,6 +221,10 @@ class Database
...
@@ -205,6 +221,10 @@ class Database
*/
*/
public
function
selectCollection
(
$collectionName
,
array
$options
=
[])
public
function
selectCollection
(
$collectionName
,
array
$options
=
[])
{
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
}
...
@@ -221,6 +241,10 @@ class Database
...
@@ -221,6 +241,10 @@ class Database
*
*
* Supported options:
* Supported options:
*
*
* * readConcern (MongoDB\Driver\ReadConcern): The default read concern to
* use for database operations and selected collections. Defaults to this
* Database's read concern.
*
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* * readPreference (MongoDB\Driver\ReadPreference): The default read
* preference to use for database operations and selected collections.
* preference to use for database operations and selected collections.
* Defaults to this Database's read preference.
* Defaults to this Database's read preference.
...
@@ -234,6 +258,10 @@ class Database
...
@@ -234,6 +258,10 @@ class Database
*/
*/
public
function
withOptions
(
array
$options
=
[])
public
function
withOptions
(
array
$options
=
[])
{
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
}
...
...
tests/Collection/CollectionFunctionalTest.php
View file @
523ca61e
...
@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Collection;
...
@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Collection;
use
MongoDB\Collection
;
use
MongoDB\Collection
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Driver\ReadConcern
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
...
@@ -114,6 +115,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -114,6 +115,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
public
function
testWithOptionsInheritsReadPreferenceAndWriteConcern
()
public
function
testWithOptionsInheritsReadPreferenceAndWriteConcern
()
{
{
$collectionOptions
=
[
$collectionOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -122,6 +124,8 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -122,6 +124,8 @@ class CollectionFunctionalTest extends FunctionalTestCase
$clone
=
$collection
->
withOptions
();
$clone
=
$collection
->
withOptions
();
$debug
=
$clone
->
__debugInfo
();
$debug
=
$clone
->
__debugInfo
();
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$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
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
...
@@ -131,6 +135,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -131,6 +135,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
public
function
testWithOptionsPassesReadPreferenceAndWriteConcern
()
public
function
testWithOptionsPassesReadPreferenceAndWriteConcern
()
{
{
$collectionOptions
=
[
$collectionOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -138,6 +143,8 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -138,6 +143,8 @@ class CollectionFunctionalTest extends FunctionalTestCase
$clone
=
$this
->
collection
->
withOptions
(
$collectionOptions
);
$clone
=
$this
->
collection
->
withOptions
(
$collectionOptions
);
$debug
=
$clone
->
__debugInfo
();
$debug
=
$clone
->
__debugInfo
();
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$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
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
523ca61e
...
@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Database;
...
@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Database;
use
MongoDB\Database
;
use
MongoDB\Database
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Driver\ReadConcern
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
...
@@ -100,9 +101,10 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -100,9 +101,10 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
}
public
function
testSelectCollectionInherits
ReadPreferenceAndWriteConcern
()
public
function
testSelectCollectionInherits
Options
()
{
{
$databaseOptions
=
[
$databaseOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -111,15 +113,18 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -111,15 +113,18 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$collection
=
$database
->
selectCollection
(
$this
->
getCollectionName
());
$collection
=
$database
->
selectCollection
(
$this
->
getCollectionName
());
$debug
=
$collection
->
__debugInfo
();
$debug
=
$collection
->
__debugInfo
();
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$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
->
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
());
}
}
public
function
testSelectCollectionPasses
ReadPreferenceAndWriteConcern
()
public
function
testSelectCollectionPasses
Options
()
{
{
$collectionOptions
=
[
$collectionOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -127,15 +132,18 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -127,15 +132,18 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$collection
=
$this
->
database
->
selectCollection
(
$this
->
getCollectionName
(),
$collectionOptions
);
$collection
=
$this
->
database
->
selectCollection
(
$this
->
getCollectionName
(),
$collectionOptions
);
$debug
=
$collection
->
__debugInfo
();
$debug
=
$collection
->
__debugInfo
();
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$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
->
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
());
}
}
public
function
testWithOptionsInherits
ReadPreferenceAndWriteConcern
()
public
function
testWithOptionsInherits
Options
()
{
{
$databaseOptions
=
[
$databaseOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -144,15 +152,18 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -144,15 +152,18 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$clone
=
$database
->
withOptions
();
$clone
=
$database
->
withOptions
();
$debug
=
$clone
->
__debugInfo
();
$debug
=
$clone
->
__debugInfo
();
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$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
->
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
());
}
}
public
function
testWithOptionsPasses
ReadPreferenceAndWriteConcern
()
public
function
testWithOptionsPasses
Options
()
{
{
$databaseOptions
=
[
$databaseOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
...
@@ -160,6 +171,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -160,6 +171,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$clone
=
$this
->
database
->
withOptions
(
$databaseOptions
);
$clone
=
$this
->
database
->
withOptions
(
$databaseOptions
);
$debug
=
$clone
->
__debugInfo
();
$debug
=
$clone
->
__debugInfo
();
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$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
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
...
...
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