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
4043b265
Commit
4043b265
authored
Nov 01, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shorthand array syntax
parent
303de406
Hide whitespace changes
Inline
Side-by-side
Showing
70 changed files
with
857 additions
and
874 deletions
+857
-874
Client.php
src/Client.php
+2
-2
Collection.php
src/Collection.php
+19
-19
Database.php
src/Database.php
+2
-2
CollectionInfo.php
src/Model/CollectionInfo.php
+1
-1
Aggregate.php
src/Operation/Aggregate.php
+6
-6
BulkWrite.php
src/Operation/BulkWrite.php
+8
-10
Count.php
src/Operation/Count.php
+3
-5
CreateCollection.php
src/Operation/CreateCollection.php
+4
-4
CreateIndexes.php
src/Operation/CreateIndexes.php
+3
-3
Delete.php
src/Operation/Delete.php
+2
-2
DeleteMany.php
src/Operation/DeleteMany.php
+1
-1
DeleteOne.php
src/Operation/DeleteOne.php
+1
-1
Distinct.php
src/Operation/Distinct.php
+3
-3
DropCollection.php
src/Operation/DropCollection.php
+1
-1
DropDatabase.php
src/Operation/DropDatabase.php
+1
-1
DropIndexes.php
src/Operation/DropIndexes.php
+2
-2
Find.php
src/Operation/Find.php
+4
-4
FindAndModify.php
src/Operation/FindAndModify.php
+4
-6
FindOne.php
src/Operation/FindOne.php
+2
-2
FindOneAndDelete.php
src/Operation/FindOneAndDelete.php
+2
-5
FindOneAndReplace.php
src/Operation/FindOneAndReplace.php
+4
-7
FindOneAndUpdate.php
src/Operation/FindOneAndUpdate.php
+4
-7
InsertMany.php
src/Operation/InsertMany.php
+3
-5
InsertOne.php
src/Operation/InsertOne.php
+1
-1
ListCollections.php
src/Operation/ListCollections.php
+7
-7
ListDatabases.php
src/Operation/ListDatabases.php
+3
-3
ListIndexes.php
src/Operation/ListIndexes.php
+7
-7
ReplaceOne.php
src/Operation/ReplaceOne.php
+2
-2
Update.php
src/Operation/Update.php
+5
-5
UpdateMany.php
src/Operation/UpdateMany.php
+2
-2
UpdateOne.php
src/Operation/UpdateOne.php
+2
-2
BulkWriteFunctionalTest.php
tests/Collection/BulkWriteFunctionalTest.php
+69
-69
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+15
-15
AggregateFunctionalTest.php
tests/Collection/CrudSpec/AggregateFunctionalTest.php
+18
-18
CountFunctionalTest.php
tests/Collection/CrudSpec/CountFunctionalTest.php
+3
-3
DeleteManyFunctionalTest.php
tests/Collection/CrudSpec/DeleteManyFunctionalTest.php
+10
-10
DeleteOneFunctionalTest.php
tests/Collection/CrudSpec/DeleteOneFunctionalTest.php
+16
-16
DistinctFunctionalTest.php
tests/Collection/CrudSpec/DistinctFunctionalTest.php
+3
-3
FindFunctionalTest.php
tests/Collection/CrudSpec/FindFunctionalTest.php
+21
-21
FindOneAndDeleteFunctionalTest.php
tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php
+30
-30
FindOneAndReplaceFunctionalTest.php
...s/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php
+96
-96
FindOneAndUpdateFunctionalTest.php
tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php
+96
-96
FunctionalTestCase.php
tests/Collection/CrudSpec/FunctionalTestCase.php
+2
-2
InsertManyFunctionalTest.php
tests/Collection/CrudSpec/InsertManyFunctionalTest.php
+10
-10
InsertOneFunctionalTest.php
tests/Collection/CrudSpec/InsertOneFunctionalTest.php
+5
-5
ReplaceOneFunctionalTest.php
tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php
+39
-39
UpdateManyFunctionalTest.php
tests/Collection/CrudSpec/UpdateManyFunctionalTest.php
+30
-30
UpdateOneFunctionalTest.php
tests/Collection/CrudSpec/UpdateOneFunctionalTest.php
+30
-30
IndexManagementFunctionalTest.php
tests/Collection/IndexManagementFunctionalTest.php
+18
-18
CollectionManagementFunctionalTest.php
tests/Database/CollectionManagementFunctionalTest.php
+3
-3
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+4
-4
FunctionalTestCase.php
tests/FunctionalTestCase.php
+4
-4
CollectionInfoTest.php
tests/Model/CollectionInfoTest.php
+11
-11
DatabaseInfoTest.php
tests/Model/DatabaseInfoTest.php
+6
-6
IndexInfoTest.php
tests/Model/IndexInfoTest.php
+19
-19
IndexInputTest.php
tests/Model/IndexInputTest.php
+20
-20
AggregateTest.php
tests/Operation/AggregateTest.php
+11
-11
BulkWriteTest.php
tests/Operation/BulkWriteTest.php
+89
-89
CountTest.php
tests/Operation/CountTest.php
+8
-8
DeleteTest.php
tests/Operation/DeleteTest.php
+5
-5
DistinctTest.php
tests/Operation/DistinctTest.php
+4
-4
FindTest.php
tests/Operation/FindTest.php
+16
-16
InsertManyTest.php
tests/Operation/InsertManyTest.php
+7
-7
InsertOneTest.php
tests/Operation/InsertOneTest.php
+3
-3
ReplaceOneTest.php
tests/Operation/ReplaceOneTest.php
+3
-3
TestCase.php
tests/Operation/TestCase.php
+8
-8
UpdateManyTest.php
tests/Operation/UpdateManyTest.php
+3
-3
UpdateOneTest.php
tests/Operation/UpdateOneTest.php
+3
-3
UpdateTest.php
tests/Operation/UpdateTest.php
+7
-7
PedantryTest.php
tests/PedantryTest.php
+1
-1
No files found.
src/Client.php
View file @
4043b265
...
...
@@ -27,7 +27,7 @@ class Client
* @param array $options Additional connection string options
* @param array $driverOptions Driver-specific options
*/
public
function
__construct
(
$uri
,
array
$options
=
array
(),
array
$driverOptions
=
array
()
)
public
function
__construct
(
$uri
,
array
$options
=
[],
array
$driverOptions
=
[]
)
{
$this
->
manager
=
new
Manager
(
$uri
,
$options
,
$driverOptions
);
}
...
...
@@ -52,7 +52,7 @@ class Client
* @see ListDatabases::__construct() for supported options
* @return DatabaseInfoIterator
*/
public
function
listDatabases
(
array
$options
=
array
()
)
public
function
listDatabases
(
array
$options
=
[]
)
{
$operation
=
new
ListDatabases
(
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
...
src/Collection.php
View file @
4043b265
...
...
@@ -93,7 +93,7 @@ class Collection
* @param array $options Command options
* @return Traversable
*/
public
function
aggregate
(
array
$pipeline
,
array
$options
=
array
()
)
public
function
aggregate
(
array
$pipeline
,
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
...
...
@@ -117,7 +117,7 @@ class Collection
* @param array $options Command options
* @return BulkWriteResult
*/
public
function
bulkWrite
(
array
$operations
,
array
$options
=
array
()
)
public
function
bulkWrite
(
array
$operations
,
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'writeConcern'
]))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
...
...
@@ -137,7 +137,7 @@ class Collection
* @param array $options Command options
* @return integer
*/
public
function
count
(
$filter
=
array
(),
array
$options
=
array
()
)
public
function
count
(
$filter
=
[],
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
...
...
@@ -158,9 +158,9 @@ class Collection
* @param array $options Index options
* @return string The name of the created index
*/
public
function
createIndex
(
$key
,
array
$options
=
array
()
)
public
function
createIndex
(
$key
,
array
$options
=
[]
)
{
return
current
(
$this
->
createIndexes
(
array
(
array
(
'key'
=>
$key
)
+
$options
)
));
return
current
(
$this
->
createIndexes
(
[[
'key'
=>
$key
]
+
$options
]
));
}
/**
...
...
@@ -203,7 +203,7 @@ class Collection
* @param array $options Command options
* @return DeleteResult
*/
public
function
deleteMany
(
$filter
,
array
$options
=
array
()
)
public
function
deleteMany
(
$filter
,
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'writeConcern'
]))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
...
...
@@ -224,7 +224,7 @@ class Collection
* @param array $options Command options
* @return DeleteResult
*/
public
function
deleteOne
(
$filter
,
array
$options
=
array
()
)
public
function
deleteOne
(
$filter
,
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'writeConcern'
]))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
...
...
@@ -245,7 +245,7 @@ class Collection
* @param array $options Command options
* @return mixed[]
*/
public
function
distinct
(
$fieldName
,
$filter
=
array
(),
array
$options
=
array
()
)
public
function
distinct
(
$fieldName
,
$filter
=
[],
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
...
...
@@ -313,7 +313,7 @@ class Collection
* @param array $options Additional options
* @return Cursor
*/
public
function
find
(
$filter
=
array
(),
array
$options
=
array
()
)
public
function
find
(
$filter
=
[],
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
...
...
@@ -334,7 +334,7 @@ class Collection
* @param array $options Additional options
* @return object|null
*/
public
function
findOne
(
$filter
=
array
(),
array
$options
=
array
()
)
public
function
findOne
(
$filter
=
[],
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
...
...
@@ -357,7 +357,7 @@ class Collection
* @param array $options Command options
* @return object|null
*/
public
function
findOneAndDelete
(
$filter
,
array
$options
=
array
()
)
public
function
findOneAndDelete
(
$filter
,
array
$options
=
[]
)
{
$operation
=
new
FindOneAndDelete
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
...
@@ -380,7 +380,7 @@ class Collection
* @param array $options Command options
* @return object|null
*/
public
function
findOneAndReplace
(
$filter
,
$replacement
,
array
$options
=
array
()
)
public
function
findOneAndReplace
(
$filter
,
$replacement
,
array
$options
=
[]
)
{
$operation
=
new
FindOneAndReplace
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$replacement
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
...
@@ -403,7 +403,7 @@ class Collection
* @param array $options Command options
* @return object|null
*/
public
function
findOneAndUpdate
(
$filter
,
$update
,
array
$options
=
array
()
)
public
function
findOneAndUpdate
(
$filter
,
$update
,
array
$options
=
[]
)
{
$operation
=
new
FindOneAndUpdate
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$update
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
...
@@ -451,7 +451,7 @@ class Collection
* @param array $options Command options
* @return InsertManyResult
*/
public
function
insertMany
(
array
$documents
,
array
$options
=
array
()
)
public
function
insertMany
(
array
$documents
,
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'writeConcern'
]))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
...
...
@@ -472,7 +472,7 @@ class Collection
* @param array $options Command options
* @return InsertOneResult
*/
public
function
insertOne
(
$document
,
array
$options
=
array
()
)
public
function
insertOne
(
$document
,
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'writeConcern'
]))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
...
...
@@ -490,7 +490,7 @@ class Collection
* @see ListIndexes::__construct() for supported options
* @return IndexInfoIterator
*/
public
function
listIndexes
(
array
$options
=
array
()
)
public
function
listIndexes
(
array
$options
=
[]
)
{
$operation
=
new
ListIndexes
(
$this
->
databaseName
,
$this
->
collectionName
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
...
@@ -508,7 +508,7 @@ class Collection
* @param array $options Command options
* @return UpdateResult
*/
public
function
replaceOne
(
$filter
,
$replacement
,
array
$options
=
array
()
)
public
function
replaceOne
(
$filter
,
$replacement
,
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'writeConcern'
]))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
...
...
@@ -530,7 +530,7 @@ class Collection
* @param array $options Command options
* @return UpdateResult
*/
public
function
updateMany
(
$filter
,
$update
,
array
$options
=
array
()
)
public
function
updateMany
(
$filter
,
$update
,
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'writeConcern'
]))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
...
...
@@ -552,7 +552,7 @@ class Collection
* @param array $options Command options
* @return UpdateResult
*/
public
function
updateOne
(
$filter
,
$update
,
array
$options
=
array
()
)
public
function
updateOne
(
$filter
,
$update
,
array
$options
=
[]
)
{
if
(
!
isset
(
$options
[
'writeConcern'
]))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
...
...
src/Database.php
View file @
4043b265
...
...
@@ -66,7 +66,7 @@ class Database
* @param array $options
* @return object Command result document
*/
public
function
createCollection
(
$collectionName
,
array
$options
=
array
()
)
public
function
createCollection
(
$collectionName
,
array
$options
=
[]
)
{
$operation
=
new
CreateCollection
(
$this
->
databaseName
,
$collectionName
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
...
@@ -118,7 +118,7 @@ class Database
* @param array $options
* @return CollectionInfoIterator
*/
public
function
listCollections
(
array
$options
=
array
()
)
public
function
listCollections
(
array
$options
=
[]
)
{
$operation
=
new
ListCollections
(
$this
->
databaseName
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
...
src/Model/CollectionInfo.php
View file @
4043b265
...
...
@@ -75,7 +75,7 @@ class CollectionInfo
*/
public
function
getOptions
()
{
return
isset
(
$this
->
info
[
'options'
])
?
(
array
)
$this
->
info
[
'options'
]
:
array
()
;
return
isset
(
$this
->
info
[
'options'
])
?
(
array
)
$this
->
info
[
'options'
]
:
[]
;
}
/**
...
...
src/Operation/Aggregate.php
View file @
4043b265
...
...
@@ -60,7 +60,7 @@ class Aggregate implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$pipeline
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$pipeline
,
array
$options
=
[]
)
{
if
(
empty
(
$pipeline
))
{
throw
new
InvalidArgumentException
(
'$pipeline is empty'
);
...
...
@@ -80,10 +80,10 @@ class Aggregate implements Executable
$expectedIndex
+=
1
;
}
$options
+=
array
(
$options
+=
[
'allowDiskUse'
=>
false
,
'useCursor'
=>
true
,
)
;
]
;
if
(
!
is_bool
(
$options
[
'allowDiskUse'
]))
{
throw
new
InvalidArgumentTypeException
(
'"allowDiskUse" option'
,
$options
[
'allowDiskUse'
],
'boolean'
);
...
...
@@ -156,10 +156,10 @@ class Aggregate implements Executable
*/
private
function
createCommand
(
Server
$server
,
$isCursorSupported
)
{
$cmd
=
array
(
$cmd
=
[
'aggregate'
=>
$this
->
collectionName
,
'pipeline'
=>
$this
->
pipeline
,
)
;
]
;
// Servers < 2.6 do not support any command options
if
(
!
$isCursorSupported
)
{
...
...
@@ -174,7 +174,7 @@ class Aggregate implements Executable
if
(
$this
->
options
[
'useCursor'
])
{
$cmd
[
'cursor'
]
=
isset
(
$this
->
options
[
"batchSize"
])
?
array
(
'batchSize'
=>
$this
->
options
[
"batchSize"
])
?
[
'batchSize'
=>
$this
->
options
[
"batchSize"
]]
:
new
stdClass
;
}
...
...
src/Operation/BulkWrite.php
View file @
4043b265
...
...
@@ -66,7 +66,7 @@ class BulkWrite implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$operations
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$operations
,
array
$options
=
[]
)
{
if
(
empty
(
$operations
))
{
throw
new
InvalidArgumentException
(
'$operations is empty'
);
...
...
@@ -104,7 +104,7 @@ class BulkWrite implements Executable
case
self
::
DELETE_MANY
:
case
self
::
DELETE_ONE
:
$operations
[
$i
][
$type
][
1
]
=
array
(
'limit'
=>
(
$type
===
self
::
DELETE_ONE
?
1
:
0
))
;
$operations
[
$i
][
$type
][
1
]
=
[
'limit'
=>
(
$type
===
self
::
DELETE_ONE
?
1
:
0
)]
;
break
;
...
...
@@ -122,7 +122,7 @@ class BulkWrite implements Executable
}
if
(
!
isset
(
$args
[
2
]))
{
$args
[
2
]
=
array
()
;
$args
[
2
]
=
[]
;
}
if
(
!
is_array
(
$args
[
2
]))
{
...
...
@@ -130,7 +130,7 @@ class BulkWrite implements Executable
}
$args
[
2
][
'multi'
]
=
false
;
$args
[
2
]
+=
array
(
'upsert'
=>
false
)
;
$args
[
2
]
+=
[
'upsert'
=>
false
]
;
if
(
!
is_bool
(
$args
[
2
][
'upsert'
]))
{
throw
new
InvalidArgumentTypeException
(
sprintf
(
'$operations[%d]["%s"][2]["upsert"]'
,
$i
,
$type
),
$args
[
2
][
'upsert'
],
'boolean'
);
...
...
@@ -155,7 +155,7 @@ class BulkWrite implements Executable
}
if
(
!
isset
(
$args
[
2
]))
{
$args
[
2
]
=
array
()
;
$args
[
2
]
=
[]
;
}
if
(
!
is_array
(
$args
[
2
]))
{
...
...
@@ -163,7 +163,7 @@ class BulkWrite implements Executable
}
$args
[
2
][
'multi'
]
=
(
$type
===
self
::
UPDATE_MANY
);
$args
[
2
]
+=
array
(
'upsert'
=>
false
)
;
$args
[
2
]
+=
[
'upsert'
=>
false
]
;
if
(
!
is_bool
(
$args
[
2
][
'upsert'
]))
{
throw
new
InvalidArgumentTypeException
(
sprintf
(
'$operations[%d]["%s"][2]["upsert"]'
,
$i
,
$type
),
$args
[
2
][
'upsert'
],
'boolean'
);
...
...
@@ -180,9 +180,7 @@ class BulkWrite implements Executable
$expectedIndex
+=
1
;
}
$options
+=
array
(
'ordered'
=>
true
,
);
$options
+=
[
'ordered'
=>
true
];
if
(
!
is_bool
(
$options
[
'ordered'
]))
{
throw
new
InvalidArgumentTypeException
(
'"ordered" option'
,
$options
[
'ordered'
],
'boolean'
);
...
...
@@ -208,7 +206,7 @@ class BulkWrite implements Executable
public
function
execute
(
Server
$server
)
{
$bulk
=
new
Bulk
([
'ordered'
=>
$this
->
options
[
'ordered'
]]);
$insertedIds
=
array
()
;
$insertedIds
=
[]
;
foreach
(
$this
->
operations
as
$i
=>
$operation
)
{
$type
=
key
(
$operation
);
...
...
src/Operation/Count.php
View file @
4043b265
...
...
@@ -48,7 +48,7 @@ class Count implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
=
array
(),
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
=
[],
array
$options
=
[]
)
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
...
...
@@ -119,15 +119,13 @@ class Count implements Executable
*/
private
function
createCommand
()
{
$cmd
=
array
(
'count'
=>
$this
->
collectionName
,
);
$cmd
=
[
'count'
=>
$this
->
collectionName
];
if
(
!
empty
(
$this
->
filter
))
{
$cmd
[
'query'
]
=
(
object
)
$this
->
filter
;
}
foreach
(
array
(
'hint'
,
'limit'
,
'maxTimeMS'
,
'skip'
)
as
$option
)
{
foreach
(
[
'hint'
,
'limit'
,
'maxTimeMS'
,
'skip'
]
as
$option
)
{
if
(
isset
(
$this
->
options
[
$option
]))
{
$cmd
[
$option
]
=
$this
->
options
[
$option
];
}
...
...
src/Operation/CreateCollection.php
View file @
4043b265
...
...
@@ -23,7 +23,7 @@ class CreateCollection implements Executable
private
$databaseName
;
private
$collectionName
;
private
$options
=
array
()
;
private
$options
=
[]
;
/**
* Constructs a create command.
...
...
@@ -57,7 +57,7 @@ class CreateCollection implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$options
=
[]
)
{
if
(
isset
(
$options
[
'autoIndexId'
])
&&
!
is_bool
(
$options
[
'autoIndexId'
]))
{
throw
new
InvalidArgumentTypeException
(
'"autoIndexId" option'
,
$options
[
'autoIndexId'
],
'boolean'
);
...
...
@@ -118,9 +118,9 @@ class CreateCollection implements Executable
*/
private
function
createCommand
()
{
$cmd
=
array
(
'create'
=>
$this
->
collectionName
)
;
$cmd
=
[
'create'
=>
$this
->
collectionName
]
;
foreach
(
array
(
'autoIndexId'
,
'capped'
,
'flags'
,
'max'
,
'maxTimeMS'
,
'size'
)
as
$option
)
{
foreach
(
[
'autoIndexId'
,
'capped'
,
'flags'
,
'max'
,
'maxTimeMS'
,
'size'
]
as
$option
)
{
if
(
isset
(
$this
->
options
[
$option
]))
{
$cmd
[
$option
]
=
$this
->
options
[
$option
];
}
...
...
src/Operation/CreateIndexes.php
View file @
4043b265
...
...
@@ -24,7 +24,7 @@ class CreateIndexes implements Executable
private
$databaseName
;
private
$collectionName
;
private
$indexes
=
array
()
;
private
$indexes
=
[]
;
/**
* Constructs a createIndexes command.
...
...
@@ -85,10 +85,10 @@ class CreateIndexes implements Executable
*/
private
function
executeCommand
(
Server
$server
)
{
$command
=
new
Command
(
array
(
$command
=
new
Command
(
[
'createIndexes'
=>
$this
->
collectionName
,
'indexes'
=>
$this
->
indexes
,
)
);
]
);
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$command
);
$result
=
current
(
$cursor
->
toArray
());
...
...
src/Operation/Delete.php
View file @
4043b265
...
...
@@ -42,7 +42,7 @@ class Delete implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$limit
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$limit
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
...
...
@@ -73,7 +73,7 @@ class Delete implements Executable
public
function
execute
(
Server
$server
)
{
$bulk
=
new
Bulk
();
$bulk
->
delete
(
$this
->
filter
,
array
(
'limit'
=>
$this
->
limit
)
);
$bulk
->
delete
(
$this
->
filter
,
[
'limit'
=>
$this
->
limit
]
);
$writeConcern
=
isset
(
$this
->
options
[
'writeConcern'
])
?
$this
->
options
[
'writeConcern'
]
:
null
;
$writeResult
=
$server
->
executeBulkWrite
(
$this
->
databaseName
.
'.'
.
$this
->
collectionName
,
$bulk
,
$writeConcern
);
...
...
src/Operation/DeleteMany.php
View file @
4043b265
...
...
@@ -30,7 +30,7 @@ class DeleteMany implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
[]
)
{
$this
->
delete
=
new
Delete
(
$databaseName
,
$collectionName
,
$filter
,
0
,
$options
);
}
...
...
src/Operation/DeleteOne.php
View file @
4043b265
...
...
@@ -30,7 +30,7 @@ class DeleteOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
[]
)
{
$this
->
delete
=
new
Delete
(
$databaseName
,
$collectionName
,
$filter
,
1
,
$options
);
}
...
...
src/Operation/Distinct.php
View file @
4043b265
...
...
@@ -42,7 +42,7 @@ class Distinct implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$fieldName
,
$filter
=
array
(),
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$fieldName
,
$filter
=
[],
array
$options
=
[]
)
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
...
...
@@ -95,10 +95,10 @@ class Distinct implements Executable
*/
private
function
createCommand
()
{
$cmd
=
array
(
$cmd
=
[
'distinct'
=>
$this
->
collectionName
,
'key'
=>
$this
->
fieldName
,
)
;
]
;
if
(
!
empty
(
$this
->
filter
))
{
$cmd
[
'query'
]
=
(
object
)
$this
->
filter
;
...
...
src/Operation/DropCollection.php
View file @
4043b265
...
...
@@ -43,7 +43,7 @@ class DropCollection implements Executable
public
function
execute
(
Server
$server
)
{
try
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'drop'
=>
$this
->
collectionName
)
));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
[
'drop'
=>
$this
->
collectionName
]
));
}
catch
(
DriverRuntimeException
$e
)
{
/* The server may return an error if the collection does not exist.
* Check for an error message (unfortunately, there isn't a code)
...
...
src/Operation/DropDatabase.php
View file @
4043b265
...
...
@@ -38,7 +38,7 @@ class DropDatabase implements Executable
*/
public
function
execute
(
Server
$server
)
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'dropDatabase'
=>
1
)
));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
[
'dropDatabase'
=>
1
]
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
...
...
src/Operation/DropIndexes.php
View file @
4043b265
...
...
@@ -50,10 +50,10 @@ class DropIndexes implements Executable
*/
public
function
execute
(
Server
$server
)
{
$cmd
=
array
(
$cmd
=
[
'dropIndexes'
=>
$this
->
collectionName
,
'index'
=>
$this
->
indexName
,
)
;
]
;
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
$cmd
));
$result
=
current
(
$cursor
->
toArray
());
...
...
src/Operation/Find.php
View file @
4043b265
...
...
@@ -79,7 +79,7 @@ class Find implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
...
...
@@ -172,7 +172,7 @@ class Find implements Executable
*/
private
function
createQuery
()
{
$options
=
array
()
;
$options
=
[]
;
if
(
!
empty
(
$this
->
options
[
'allowPartialResults'
]))
{
$options
[
'partial'
]
=
true
;
...
...
@@ -188,13 +188,13 @@ class Find implements Executable
}
}
foreach
(
array
(
'batchSize'
,
'limit'
,
'skip'
,
'sort'
,
'noCursorTimeout'
,
'oplogReplay'
,
'projection'
)
as
$option
)
{
foreach
(
[
'batchSize'
,
'limit'
,
'skip'
,
'sort'
,
'noCursorTimeout'
,
'oplogReplay'
,
'projection'
]
as
$option
)
{
if
(
isset
(
$this
->
options
[
$option
]))
{
$options
[
$option
]
=
$this
->
options
[
$option
];
}
}
$modifiers
=
empty
(
$this
->
options
[
'modifiers'
])
?
array
()
:
(
array
)
$this
->
options
[
'modifiers'
];
$modifiers
=
empty
(
$this
->
options
[
'modifiers'
])
?
[]
:
(
array
)
$this
->
options
[
'modifiers'
];
if
(
isset
(
$options
[
'comment'
]))
{
$modifiers
[
'$comment'
]
=
$options
[
'comment'
];
...
...
src/Operation/FindAndModify.php
View file @
4043b265
...
...
@@ -61,11 +61,11 @@ class FindAndModify implements Executable
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$options
)
{
$options
+=
array
(
$options
+=
[
'new'
=>
false
,
'remove'
=>
false
,
'upsert'
=>
false
,
)
;
]
;
if
(
isset
(
$options
[
'fields'
])
&&
!
is_array
(
$options
[
'fields'
])
&&
!
is_object
(
$options
[
'fields'
]))
{
throw
new
InvalidArgumentTypeException
(
'"fields" option'
,
$options
[
'fields'
],
'array or object'
);
...
...
@@ -153,9 +153,7 @@ class FindAndModify implements Executable
*/
private
function
createCommand
()
{
$cmd
=
array
(
'findAndModify'
=>
$this
->
collectionName
,
);
$cmd
=
[
'findAndModify'
=>
$this
->
collectionName
];
if
(
$this
->
options
[
'remove'
])
{
$cmd
[
'remove'
]
=
true
;
...
...
@@ -164,7 +162,7 @@ class FindAndModify implements Executable
$cmd
[
'upsert'
]
=
$this
->
options
[
'upsert'
];
}
foreach
(
array
(
'fields'
,
'query'
,
'sort'
,
'update'
)
as
$option
)
{
foreach
(
[
'fields'
,
'query'
,
'sort'
,
'update'
]
as
$option
)
{
if
(
isset
(
$this
->
options
[
$option
]))
{
$cmd
[
$option
]
=
(
object
)
$this
->
options
[
$option
];
}
...
...
src/Operation/FindOne.php
View file @
4043b265
...
...
@@ -52,7 +52,7 @@ class FindOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
[]
)
{
if
(
isset
(
$options
[
'typeMap'
])
&&
!
is_array
(
$options
[
'typeMap'
]))
{
throw
new
InvalidArgumentTypeException
(
'"typeMap" option'
,
$options
[
'typeMap'
],
'array'
);
...
...
@@ -62,7 +62,7 @@ class FindOne implements Executable
$databaseName
,
$collectionName
,
$filter
,
array
(
'limit'
=>
-
1
)
+
$options
[
'limit'
=>
-
1
]
+
$options
);
$this
->
options
=
$options
;
...
...
src/Operation/FindOneAndDelete.php
View file @
4043b265
...
...
@@ -38,7 +38,7 @@ class FindOneAndDelete implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
...
...
@@ -57,10 +57,7 @@ class FindOneAndDelete implements Executable
$this
->
findAndModify
=
new
FindAndModify
(
$databaseName
,
$collectionName
,
array
(
'query'
=>
$filter
,
'remove'
=>
true
,
)
+
$options
[
'query'
=>
$filter
,
'remove'
=>
true
]
+
$options
);
}
...
...
src/Operation/FindOneAndReplace.php
View file @
4043b265
...
...
@@ -49,7 +49,7 @@ class FindOneAndReplace implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$replacement
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$replacement
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
...
...
@@ -63,10 +63,10 @@ class FindOneAndReplace implements Executable
throw
new
InvalidArgumentException
(
'First key in $replacement argument is an update operator'
);
}
$options
+=
array
(
$options
+=
[
'returnDocument'
=>
self
::
RETURN_DOCUMENT_BEFORE
,
'upsert'
=>
false
,
)
;
]
;
if
(
isset
(
$options
[
'projection'
])
&&
!
is_array
(
$options
[
'projection'
])
&&
!
is_object
(
$options
[
'projection'
]))
{
throw
new
InvalidArgumentTypeException
(
'"projection" option'
,
$options
[
'projection'
],
'array or object'
);
...
...
@@ -92,10 +92,7 @@ class FindOneAndReplace implements Executable
$this
->
findAndModify
=
new
FindAndModify
(
$databaseName
,
$collectionName
,
array
(
'query'
=>
$filter
,
'update'
=>
$replacement
,
)
+
$options
[
'query'
=>
$filter
,
'update'
=>
$replacement
]
+
$options
);
}
...
...
src/Operation/FindOneAndUpdate.php
View file @
4043b265
...
...
@@ -49,7 +49,7 @@ class FindOneAndUpdate implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$update
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$update
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
...
...
@@ -63,10 +63,10 @@ class FindOneAndUpdate implements Executable
throw
new
InvalidArgumentException
(
'First key in $update argument is not an update operator'
);
}
$options
+=
array
(
$options
+=
[
'returnDocument'
=>
self
::
RETURN_DOCUMENT_BEFORE
,
'upsert'
=>
false
,
)
;
]
;
if
(
isset
(
$options
[
'projection'
])
&&
!
is_array
(
$options
[
'projection'
])
&&
!
is_object
(
$options
[
'projection'
]))
{
throw
new
InvalidArgumentTypeException
(
'"projection" option'
,
$options
[
'projection'
],
'array or object'
);
...
...
@@ -92,10 +92,7 @@ class FindOneAndUpdate implements Executable
$this
->
findAndModify
=
new
FindAndModify
(
$databaseName
,
$collectionName
,
array
(
'query'
=>
$filter
,
'update'
=>
$update
,
)
+
$options
[
'query'
=>
$filter
,
'update'
=>
$update
]
+
$options
);
}
...
...
src/Operation/InsertMany.php
View file @
4043b265
...
...
@@ -40,7 +40,7 @@ class InsertMany implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$documents
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$documents
,
array
$options
=
[]
)
{
if
(
empty
(
$documents
))
{
throw
new
InvalidArgumentException
(
'$documents is empty'
);
...
...
@@ -60,9 +60,7 @@ class InsertMany implements Executable
$expectedIndex
+=
1
;
}
$options
+=
array
(
'ordered'
=>
true
,
);
$options
+=
[
'ordered'
=>
true
];
if
(
!
is_bool
(
$options
[
'ordered'
]))
{
throw
new
InvalidArgumentTypeException
(
'"ordered" option'
,
$options
[
'ordered'
],
'boolean'
);
...
...
@@ -88,7 +86,7 @@ class InsertMany implements Executable
public
function
execute
(
Server
$server
)
{
$bulk
=
new
Bulk
([
'ordered'
=>
$this
->
options
[
'ordered'
]]);
$insertedIds
=
array
()
;
$insertedIds
=
[]
;
foreach
(
$this
->
documents
as
$i
=>
$document
)
{
$insertedId
=
$bulk
->
insert
(
$document
);
...
...
src/Operation/InsertOne.php
View file @
4043b265
...
...
@@ -35,7 +35,7 @@ class InsertOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$document
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$document
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$document
)
&&
!
is_object
(
$document
))
{
throw
new
InvalidArgumentTypeException
(
'$document'
,
$document
,
'array or object'
);
...
...
src/Operation/ListCollections.php
View file @
4043b265
...
...
@@ -37,7 +37,7 @@ class ListCollections implements Executable
* @param string $databaseName Database name
* @param array $options Command options
*/
public
function
__construct
(
$databaseName
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
array
$options
=
[]
)
{
if
(
isset
(
$options
[
'filter'
])
&&
!
is_array
(
$options
[
'filter'
])
&&
!
is_object
(
$options
[
'filter'
]))
{
throw
new
InvalidArgumentTypeException
(
'"filter" option'
,
$options
[
'filter'
],
'array or object'
);
...
...
@@ -74,7 +74,7 @@ class ListCollections implements Executable
*/
private
function
executeCommand
(
Server
$server
)
{
$cmd
=
array
(
'listCollections'
=>
1
)
;
$cmd
=
[
'listCollections'
=>
1
]
;
if
(
!
empty
(
$this
->
options
[
'filter'
]))
{
$cmd
[
'filter'
]
=
(
object
)
$this
->
options
[
'filter'
];
...
...
@@ -85,7 +85,7 @@ class ListCollections implements Executable
}
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
$cmd
));
$cursor
->
setTypeMap
(
array
(
'root'
=>
'array'
,
'document'
=>
'array'
)
);
$cursor
->
setTypeMap
(
[
'root'
=>
'array'
,
'document'
=>
'array'
]
);
return
new
CollectionInfoCommandIterator
(
$cursor
);
}
...
...
@@ -100,7 +100,7 @@ class ListCollections implements Executable
*/
private
function
executeLegacy
(
Server
$server
)
{
$filter
=
empty
(
$this
->
options
[
'filter'
])
?
array
()
:
(
array
)
$this
->
options
[
'filter'
];
$filter
=
empty
(
$this
->
options
[
'filter'
])
?
[]
:
(
array
)
$this
->
options
[
'filter'
];
if
(
array_key_exists
(
'name'
,
$filter
))
{
if
(
!
is_string
(
$filter
[
'name'
]))
{
...
...
@@ -111,11 +111,11 @@ class ListCollections implements Executable
}
$options
=
isset
(
$this
->
options
[
'maxTimeMS'
])
?
array
(
'modifiers'
=>
array
(
'$maxTimeMS'
=>
$this
->
options
[
'maxTimeMS'
]))
:
array
()
;
?
[
'modifiers'
=>
[
'$maxTimeMS'
=>
$this
->
options
[
'maxTimeMS'
]]]
:
[]
;
$cursor
=
$server
->
executeQuery
(
$this
->
databaseName
.
'.system.namespaces'
,
new
Query
(
$filter
,
$options
));
$cursor
->
setTypeMap
(
array
(
'root'
=>
'array'
,
'document'
=>
'array'
)
);
$cursor
->
setTypeMap
(
[
'root'
=>
'array'
,
'document'
=>
'array'
]
);
return
new
CollectionInfoLegacyIterator
(
$cursor
);
}
...
...
src/Operation/ListDatabases.php
View file @
4043b265
...
...
@@ -30,7 +30,7 @@ class ListDatabases implements Executable
*
* @param array $options Command options
*/
public
function
__construct
(
array
$options
=
array
()
)
public
function
__construct
(
array
$options
=
[]
)
{
if
(
isset
(
$options
[
'maxTimeMS'
])
&&
!
is_integer
(
$options
[
'maxTimeMS'
]))
{
throw
new
InvalidArgumentTypeException
(
'"maxTimeMS" option'
,
$options
[
'maxTimeMS'
],
'integer'
);
...
...
@@ -48,14 +48,14 @@ class ListDatabases implements Executable
*/
public
function
execute
(
Server
$server
)
{
$cmd
=
array
(
'listDatabases'
=>
1
)
;
$cmd
=
[
'listDatabases'
=>
1
]
;
if
(
isset
(
$this
->
options
[
'maxTimeMS'
]))
{
$cmd
[
'maxTimeMS'
]
=
$this
->
options
[
'maxTimeMS'
];
}
$cursor
=
$server
->
executeCommand
(
'admin'
,
new
Command
(
$cmd
));
$cursor
->
setTypeMap
(
array
(
'root'
=>
'array'
,
'document'
=>
'array'
)
);
$cursor
->
setTypeMap
(
[
'root'
=>
'array'
,
'document'
=>
'array'
]
);
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
...
...
src/Operation/ListIndexes.php
View file @
4043b265
...
...
@@ -39,7 +39,7 @@ class ListIndexes implements Executable
* @param string $collectionName Collection name
* @param array $options Command options
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$options
=
[]
)
{
if
(
isset
(
$options
[
'maxTimeMS'
])
&&
!
is_integer
(
$options
[
'maxTimeMS'
]))
{
throw
new
InvalidArgumentTypeException
(
'"maxTimeMS" option'
,
$options
[
'maxTimeMS'
],
'integer'
);
...
...
@@ -73,7 +73,7 @@ class ListIndexes implements Executable
*/
private
function
executeCommand
(
Server
$server
)
{
$cmd
=
array
(
'listIndexes'
=>
$this
->
collectionName
)
;
$cmd
=
[
'listIndexes'
=>
$this
->
collectionName
]
;
if
(
isset
(
$this
->
options
[
'maxTimeMS'
]))
{
$cmd
[
'maxTimeMS'
]
=
$this
->
options
[
'maxTimeMS'
];
...
...
@@ -93,7 +93,7 @@ class ListIndexes implements Executable
throw
$e
;
}
$cursor
->
setTypeMap
(
array
(
'root'
=>
'array'
,
'document'
=>
'array'
)
);
$cursor
->
setTypeMap
(
[
'root'
=>
'array'
,
'document'
=>
'array'
]
);
return
new
IndexInfoIteratorIterator
(
$cursor
);
}
...
...
@@ -107,14 +107,14 @@ class ListIndexes implements Executable
*/
private
function
executeLegacy
(
Server
$server
)
{
$filter
=
array
(
'ns'
=>
$this
->
databaseName
.
'.'
.
$this
->
collectionName
)
;
$filter
=
[
'ns'
=>
$this
->
databaseName
.
'.'
.
$this
->
collectionName
]
;
$options
=
isset
(
$this
->
options
[
'maxTimeMS'
])
?
array
(
'modifiers'
=>
array
(
'$maxTimeMS'
=>
$this
->
options
[
'maxTimeMS'
]))
:
array
()
;
?
[
'modifiers'
=>
[
'$maxTimeMS'
=>
$this
->
options
[
'maxTimeMS'
]]]
:
[]
;
$cursor
=
$server
->
executeQuery
(
$this
->
databaseName
.
'.system.indexes'
,
new
Query
(
$filter
,
$options
));
$cursor
->
setTypeMap
(
array
(
'root'
=>
'array'
,
'document'
=>
'array'
)
);
$cursor
->
setTypeMap
(
[
'root'
=>
'array'
,
'document'
=>
'array'
]
);
return
new
IndexInfoIteratorIterator
(
$cursor
);
}
...
...
src/Operation/ReplaceOne.php
View file @
4043b265
...
...
@@ -35,7 +35,7 @@ class ReplaceOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$replacement
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$replacement
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$replacement
)
&&
!
is_object
(
$replacement
))
{
throw
new
InvalidArgumentTypeException
(
'$replacement'
,
$replacement
,
'array or object'
);
...
...
@@ -50,7 +50,7 @@ class ReplaceOne implements Executable
$collectionName
,
$filter
,
$replacement
,
array
(
'multi'
=>
false
)
+
$options
[
'multi'
=>
false
]
+
$options
);
}
...
...
src/Operation/Update.php
View file @
4043b265
...
...
@@ -48,7 +48,7 @@ class Update implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$update
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$update
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
...
...
@@ -58,10 +58,10 @@ class Update implements Executable
throw
new
InvalidArgumentTypeException
(
'$update'
,
$filter
,
'array or object'
);
}
$options
+=
array
(
$options
+=
[
'multi'
=>
false
,
'upsert'
=>
false
,
)
;
]
;
if
(
!
is_bool
(
$options
[
'multi'
]))
{
throw
new
InvalidArgumentTypeException
(
'"multi" option'
,
$options
[
'multi'
],
'boolean'
);
...
...
@@ -95,10 +95,10 @@ class Update implements Executable
*/
public
function
execute
(
Server
$server
)
{
$options
=
array
(
$options
=
[
'multi'
=>
$this
->
options
[
'multi'
],
'upsert'
=>
$this
->
options
[
'upsert'
],
)
;
]
;
$bulk
=
new
Bulk
();
$bulk
->
update
(
$this
->
filter
,
$this
->
update
,
$options
);
...
...
src/Operation/UpdateMany.php
View file @
4043b265
...
...
@@ -35,7 +35,7 @@ class UpdateMany implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$update
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$update
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$update
)
&&
!
is_object
(
$update
))
{
throw
new
InvalidArgumentTypeException
(
'$update'
,
$update
,
'array or object'
);
...
...
@@ -50,7 +50,7 @@ class UpdateMany implements Executable
$collectionName
,
$filter
,
$update
,
array
(
'multi'
=>
true
)
+
$options
[
'multi'
=>
true
]
+
$options
);
}
...
...
src/Operation/UpdateOne.php
View file @
4043b265
...
...
@@ -35,7 +35,7 @@ class UpdateOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$update
,
array
$options
=
array
()
)
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
,
$update
,
array
$options
=
[]
)
{
if
(
!
is_array
(
$update
)
&&
!
is_object
(
$update
))
{
throw
new
InvalidArgumentTypeException
(
'$update'
,
$update
,
'array or object'
);
...
...
@@ -50,7 +50,7 @@ class UpdateOne implements Executable
$collectionName
,
$filter
,
$update
,
array
(
'multi'
=>
false
)
+
$options
[
'multi'
=>
false
]
+
$options
);
}
...
...
tests/Collection/BulkWriteFunctionalTest.php
View file @
4043b265
...
...
@@ -17,10 +17,10 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
public
function
testInserts
()
{
$ops
=
array
(
array
(
'insertOne'
=>
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)))
,
array
(
'insertOne'
=>
array
(
array
(
'x'
=>
22
)))
,
)
;
$ops
=
[
[
'insertOne'
=>
[[
'_id'
=>
1
,
'x'
=>
11
]]]
,
[
'insertOne'
=>
[[
'x'
=>
22
]]]
,
]
;
$result
=
$this
->
collection
->
bulkWrite
(
$ops
);
$this
->
assertInstanceOf
(
'MongoDB\BulkWriteResult'
,
$result
);
...
...
@@ -30,10 +30,10 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
1
,
$insertedIds
[
0
]);
$this
->
assertInstanceOf
(
'MongoDB\BSON\ObjectId'
,
$insertedIds
[
1
]);
$expected
=
array
(
array
(
'_id'
=>
$insertedIds
[
0
],
'x'
=>
11
)
,
array
(
'_id'
=>
$insertedIds
[
1
],
'x'
=>
22
)
,
)
;
$expected
=
[
[
'_id'
=>
$insertedIds
[
0
],
'x'
=>
11
]
,
[
'_id'
=>
$insertedIds
[
1
],
'x'
=>
22
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
@@ -42,13 +42,13 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
{
$this
->
createFixtures
(
4
);
$ops
=
array
(
array
(
'updateOne'
=>
array
(
array
(
'_id'
=>
2
),
array
(
'$inc'
=>
array
(
'x'
=>
1
))))
,
array
(
'updateMany'
=>
array
(
array
(
'_id'
=>
array
(
'$gt'
=>
2
)),
array
(
'$inc'
=>
array
(
'x'
=>
-
1
))))
,
array
(
'updateOne'
=>
array
(
array
(
'_id'
=>
5
),
array
(
'$set'
=>
array
(
'x'
=>
55
)),
array
(
'upsert'
=>
true
)))
,
array
(
'updateOne'
=>
array
(
array
(
'x'
=>
66
),
array
(
'$set'
=>
array
(
'x'
=>
66
)),
array
(
'upsert'
=>
true
)))
,
array
(
'updateMany'
=>
array
(
array
(
'x'
=>
array
(
'$gt'
=>
50
)),
array
(
'$inc'
=>
array
(
'x'
=>
1
))))
,
)
;
$ops
=
[
[
'updateOne'
=>
[[
'_id'
=>
2
],
[
'$inc'
=>
[
'x'
=>
1
]]]]
,
[
'updateMany'
=>
[[
'_id'
=>
[
'$gt'
=>
2
]],
[
'$inc'
=>
[
'x'
=>
-
1
]]]]
,
[
'updateOne'
=>
[[
'_id'
=>
5
],
[
'$set'
=>
[
'x'
=>
55
]],
[
'upsert'
=>
true
]]]
,
[
'updateOne'
=>
[[
'x'
=>
66
],
[
'$set'
=>
[
'x'
=>
66
]],
[
'upsert'
=>
true
]]]
,
[
'updateMany'
=>
[[
'x'
=>
[
'$gt'
=>
50
]],
[
'$inc'
=>
[
'x'
=>
1
]]]]
,
]
;
$result
=
$this
->
collection
->
bulkWrite
(
$ops
);
$this
->
assertInstanceOf
(
'MongoDB\BulkWriteResult'
,
$result
);
...
...
@@ -60,14 +60,14 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
5
,
$upsertedIds
[
2
]);
$this
->
assertInstanceOf
(
'MongoDB\BSON\ObjectId'
,
$upsertedIds
[
3
]);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
23
)
,
array
(
'_id'
=>
3
,
'x'
=>
32
)
,
array
(
'_id'
=>
4
,
'x'
=>
43
)
,
array
(
'_id'
=>
5
,
'x'
=>
56
)
,
array
(
'_id'
=>
$upsertedIds
[
3
],
'x'
=>
67
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
23
]
,
[
'_id'
=>
3
,
'x'
=>
32
]
,
[
'_id'
=>
4
,
'x'
=>
43
]
,
[
'_id'
=>
5
,
'x'
=>
56
]
,
[
'_id'
=>
$upsertedIds
[
3
],
'x'
=>
67
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
@@ -76,18 +76,18 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
{
$this
->
createFixtures
(
4
);
$ops
=
array
(
array
(
'deleteOne'
=>
array
(
array
(
'_id'
=>
1
)))
,
array
(
'deleteMany'
=>
array
(
array
(
'_id'
=>
array
(
'$gt'
=>
2
))))
,
)
;
$ops
=
[
[
'deleteOne'
=>
[[
'_id'
=>
1
]]]
,
[
'deleteMany'
=>
[[
'_id'
=>
[
'$gt'
=>
2
]]]]
,
]
;
$result
=
$this
->
collection
->
bulkWrite
(
$ops
);
$this
->
assertInstanceOf
(
'MongoDB\BulkWriteResult'
,
$result
);
$this
->
assertSame
(
3
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
)
;
$expected
=
[
[
'_id'
=>
2
,
'x'
=>
22
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
@@ -96,32 +96,32 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
{
$this
->
createFixtures
(
3
);
$ops
=
array
(
array
(
'updateOne'
=>
array
(
array
(
'_id'
=>
array
(
'$gt'
=>
1
)),
array
(
'$inc'
=>
array
(
'x'
=>
1
))))
,
array
(
'updateMany'
=>
array
(
array
(
'_id'
=>
array
(
'$gt'
=>
1
)),
array
(
'$inc'
=>
array
(
'x'
=>
1
))))
,
array
(
'insertOne'
=>
array
(
array
(
'_id'
=>
4
,
'x'
=>
44
)))
,
array
(
'deleteMany'
=>
array
(
array
(
'x'
=>
array
(
'$nin'
=>
array
(
24
,
34
)))))
,
array
(
'replaceOne'
=>
array
(
array
(
'_id'
=>
4
),
array
(
'_id'
=>
4
,
'x'
=>
44
),
array
(
'upsert'
=>
true
)))
,
)
;
$ops
=
[
[
'updateOne'
=>
[[
'_id'
=>
[
'$gt'
=>
1
]],
[
'$inc'
=>
[
'x'
=>
1
]]]]
,
[
'updateMany'
=>
[[
'_id'
=>
[
'$gt'
=>
1
]],
[
'$inc'
=>
[
'x'
=>
1
]]]]
,
[
'insertOne'
=>
[[
'_id'
=>
4
,
'x'
=>
44
]]]
,
[
'deleteMany'
=>
[[
'x'
=>
[
'$nin'
=>
[
24
,
34
]]]]]
,
[
'replaceOne'
=>
[[
'_id'
=>
4
],
[
'_id'
=>
4
,
'x'
=>
44
],
[
'upsert'
=>
true
]]]
,
]
;
$result
=
$this
->
collection
->
bulkWrite
(
$ops
);
$this
->
assertInstanceOf
(
'MongoDB\BulkWriteResult'
,
$result
);
$this
->
assertSame
(
1
,
$result
->
getInsertedCount
());
$this
->
assertSame
(
array
(
2
=>
4
)
,
$result
->
getInsertedIds
());
$this
->
assertSame
(
[
2
=>
4
]
,
$result
->
getInsertedIds
());
$this
->
assertSame
(
3
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
3
,
$result
->
getModifiedCount
());
$this
->
assertSame
(
1
,
$result
->
getUpsertedCount
());
$this
->
assertSame
(
array
(
4
=>
4
)
,
$result
->
getUpsertedIds
());
$this
->
assertSame
(
[
4
=>
4
]
,
$result
->
getUpsertedIds
());
$this
->
assertSame
(
2
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
2
,
'x'
=>
24
)
,
array
(
'_id'
=>
3
,
'x'
=>
34
)
,
array
(
'_id'
=>
4
,
'x'
=>
44
)
,
)
;
$expected
=
[
[
'_id'
=>
2
,
'x'
=>
24
]
,
[
'_id'
=>
3
,
'x'
=>
34
]
,
[
'_id'
=>
4
,
'x'
=>
44
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
@@ -132,9 +132,9 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
*/
public
function
testUnknownOperation
()
{
$this
->
collection
->
bulkWrite
(
array
(
array
(
'foo'
=>
array
(
array
(
'_id'
=>
1
)))
,
)
);
$this
->
collection
->
bulkWrite
(
[
[
'foo'
=>
[[
'_id'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -149,17 +149,17 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
public
function
provideOpsWithMissingArguments
()
{
return
array
(
array
(
array
(
array
(
'insertOne'
=>
array
())))
,
array
(
array
(
array
(
'updateOne'
=>
array
())))
,
array
(
array
(
array
(
'updateOne'
=>
array
(
array
(
'_id'
=>
1
)))))
,
array
(
array
(
array
(
'updateMany'
=>
array
())))
,
array
(
array
(
array
(
'updateMany'
=>
array
(
array
(
'_id'
=>
1
)))))
,
array
(
array
(
array
(
'replaceOne'
=>
array
())))
,
array
(
array
(
array
(
'replaceOne'
=>
array
(
array
(
'_id'
=>
1
)))))
,
array
(
array
(
array
(
'deleteOne'
=>
array
())))
,
array
(
array
(
array
(
'deleteMany'
=>
array
())))
,
)
;
return
[
[[[
'insertOne'
=>
[]]]]
,
[[[
'updateOne'
=>
[]]]]
,
[[[
'updateOne'
=>
[[
'_id'
=>
1
]]]]]
,
[[[
'updateMany'
=>
[]]]]
,
[[[
'updateMany'
=>
[[
'_id'
=>
1
]]]]]
,
[[[
'replaceOne'
=>
[]]]]
,
[[[
'replaceOne'
=>
[[
'_id'
=>
1
]]]]]
,
[[[
'deleteOne'
=>
[]]]]
,
[[[
'deleteMany'
=>
[]]]]
,
]
;
}
/**
...
...
@@ -168,9 +168,9 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
*/
public
function
testUpdateOneRequiresUpdateOperators
()
{
$this
->
collection
->
bulkWrite
(
array
(
array
(
'updateOne'
=>
array
(
array
(
'_id'
=>
1
),
array
(
'x'
=>
1
)))
,
)
);
$this
->
collection
->
bulkWrite
(
[
[
'updateOne'
=>
[[
'_id'
=>
1
],
[
'x'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -179,9 +179,9 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
*/
public
function
testUpdateManyRequiresUpdateOperators
()
{
$this
->
collection
->
bulkWrite
(
array
(
array
(
'updateMany'
=>
array
(
array
(
'_id'
=>
array
(
'$gt'
=>
1
)),
array
(
'x'
=>
1
)))
,
)
);
$this
->
collection
->
bulkWrite
(
[
[
'updateMany'
=>
[[
'_id'
=>
[
'$gt'
=>
1
]],
[
'x'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -190,9 +190,9 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
*/
public
function
testReplaceOneRequiresReplacementDocument
()
{
$this
->
collection
->
bulkWrite
(
array
(
array
(
'replaceOne'
=>
array
(
array
(
'_id'
=>
1
),
array
(
'$inc'
=>
array
(
'x'
=>
1
))))
,
)
);
$this
->
collection
->
bulkWrite
(
[
[
'replaceOne'
=>
[[
'_id'
=>
1
],
[
'$inc'
=>
[
'x'
=>
1
]]]]
,
]
);
}
/**
...
...
@@ -205,10 +205,10 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
$bulkWrite
=
new
BulkWrite
([
'ordered'
=>
true
]);
for
(
$i
=
1
;
$i
<=
$n
;
$i
++
)
{
$bulkWrite
->
insert
(
array
(
$bulkWrite
->
insert
(
[
'_id'
=>
$i
,
'x'
=>
(
integer
)
(
$i
.
$i
),
)
);
]
);
}
$result
=
$this
->
manager
->
executeBulkWrite
(
$this
->
getNamespace
(),
$bulkWrite
);
...
...
tests/Collection/CollectionFunctionalTest.php
View file @
4043b265
...
...
@@ -22,13 +22,13 @@ class CollectionFunctionalTest extends FunctionalTestCase
public
function
provideInvalidNamespaceValues
()
{
return
array
(
array
(
null
)
,
array
(
''
)
,
array
(
'db_collection'
)
,
array
(
'db'
)
,
array
(
'.collection'
)
,
)
;
return
[
[
null
]
,
[
''
]
,
[
'db_collection'
]
,
[
'db'
]
,
[
'.collection'
]
,
]
;
}
public
function
testToString
()
...
...
@@ -53,7 +53,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
public
function
testDrop
()
{
$writeResult
=
$this
->
collection
->
insertOne
(
array
(
'x'
=>
1
)
);
$writeResult
=
$this
->
collection
->
insertOne
(
[
'x'
=>
1
]
);
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$commandResult
=
$this
->
collection
->
drop
();
...
...
@@ -65,13 +65,13 @@ class CollectionFunctionalTest extends FunctionalTestCase
{
$this
->
createFixtures
(
5
);
$filter
=
array
(
'_id'
=>
array
(
'$lt'
=>
5
))
;
$options
=
array
(
$filter
=
[
'_id'
=>
[
'$lt'
=>
5
]]
;
$options
=
[
'skip'
=>
1
,
'sort'
=>
array
(
'x'
=>
-
1
)
,
)
;
'sort'
=>
[
'x'
=>
-
1
]
,
]
;
$expected
=
(
object
)
array
(
'_id'
=>
3
,
'x'
=>
33
)
;
$expected
=
(
object
)
[
'_id'
=>
3
,
'x'
=>
33
]
;
$this
->
assertEquals
(
$expected
,
$this
->
collection
->
findOne
(
$filter
,
$options
));
}
...
...
@@ -86,10 +86,10 @@ class CollectionFunctionalTest extends FunctionalTestCase
$bulkWrite
=
new
BulkWrite
([
'ordered'
=>
true
]);
for
(
$i
=
1
;
$i
<=
$n
;
$i
++
)
{
$bulkWrite
->
insert
(
array
(
$bulkWrite
->
insert
(
[
'_id'
=>
$i
,
'x'
=>
(
integer
)
(
$i
.
$i
),
)
);
]
);
}
$result
=
$this
->
manager
->
executeBulkWrite
(
$this
->
getNamespace
(),
$bulkWrite
);
...
...
tests/Collection/CrudSpec/AggregateFunctionalTest.php
View file @
4043b265
...
...
@@ -25,17 +25,17 @@ class AggregateFunctionalTest extends FunctionalTestCase
public
function
testAggregateWithMultipleStages
()
{
$cursor
=
$this
->
collection
->
aggregate
(
array
(
array
(
'$sort'
=>
array
(
'x'
=>
1
))
,
array
(
'$match'
=>
array
(
'_id'
=>
array
(
'$gt'
=>
1
)))
,
)
,
array
(
'batchSize'
=>
2
)
[
[
'$sort'
=>
[
'x'
=>
1
]]
,
[
'$match'
=>
[
'_id'
=>
[
'$gt'
=>
1
]]]
,
]
,
[
'batchSize'
=>
2
]
);
$expected
=
array
(
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$cursor
);
}
...
...
@@ -53,17 +53,17 @@ class AggregateFunctionalTest extends FunctionalTestCase
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
collection
->
aggregate
(
array
(
array
(
'$sort'
=>
array
(
'x'
=>
1
))
,
array
(
'$match'
=>
array
(
'_id'
=>
array
(
'$gt'
=>
1
)))
,
array
(
'$out'
=>
$outputCollection
->
getCollectionName
())
,
)
[
[
'$sort'
=>
[
'x'
=>
1
]]
,
[
'$match'
=>
[
'_id'
=>
[
'$gt'
=>
1
]]]
,
[
'$out'
=>
$outputCollection
->
getCollectionName
()]
,
]
);
$expected
=
array
(
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$outputCollection
->
find
());
...
...
tests/Collection/CrudSpec/CountFunctionalTest.php
View file @
4043b265
...
...
@@ -23,15 +23,15 @@ class CountFunctionalTest extends FunctionalTestCase
public
function
testCountWithFilter
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$this
->
assertSame
(
2
,
$this
->
collection
->
count
(
$filter
));
}
public
function
testCountWithSkipAndLimit
()
{
$filter
=
array
()
;
$options
=
array
(
'skip'
=>
1
,
'limit'
=>
3
)
;
$filter
=
[]
;
$options
=
[
'skip'
=>
1
,
'limit'
=>
3
]
;
$this
->
assertSame
(
2
,
$this
->
collection
->
count
(
$filter
,
$options
));
}
...
...
tests/Collection/CrudSpec/DeleteManyFunctionalTest.php
View file @
4043b265
...
...
@@ -18,30 +18,30 @@ class DeleteManyFunctionalTest extends FunctionalTestCase
public
function
testDeleteManyWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$result
=
$this
->
collection
->
deleteMany
(
$filter
);
$this
->
assertSame
(
2
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testDeleteManyWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$filter
=
[
'_id'
=>
4
]
;
$result
=
$this
->
collection
->
deleteMany
(
$filter
);
$this
->
assertSame
(
0
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/CrudSpec/DeleteOneFunctionalTest.php
View file @
4043b265
...
...
@@ -18,46 +18,46 @@ class DeleteOneFunctionalTest extends FunctionalTestCase
public
function
testDeleteOneWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$result
=
$this
->
collection
->
deleteOne
(
$filter
);
$this
->
assertSame
(
1
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testDeleteOneWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
2
)
;
$filter
=
[
'_id'
=>
2
]
;
$result
=
$this
->
collection
->
deleteOne
(
$filter
);
$this
->
assertSame
(
1
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testDeleteOneWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$filter
=
[
'_id'
=>
4
]
;
$result
=
$this
->
collection
->
deleteOne
(
$filter
);
$this
->
assertSame
(
0
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/CrudSpec/DistinctFunctionalTest.php
View file @
4043b265
...
...
@@ -18,13 +18,13 @@ class DistinctFunctionalTest extends FunctionalTestCase
public
function
testDistinctWithoutFilter
()
{
$this
->
assertSame
(
array
(
11
,
22
,
33
)
,
$this
->
collection
->
distinct
(
'x'
));
$this
->
assertSame
(
[
11
,
22
,
33
]
,
$this
->
collection
->
distinct
(
'x'
));
}
public
function
testDistinctWithFilter
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$this
->
assertSame
(
array
(
22
,
33
)
,
$this
->
collection
->
distinct
(
'x'
,
$filter
));
$this
->
assertSame
(
[
22
,
33
]
,
$this
->
collection
->
distinct
(
'x'
,
$filter
));
}
}
tests/Collection/CrudSpec/FindFunctionalTest.php
View file @
4043b265
...
...
@@ -18,46 +18,46 @@ class FindFunctionalTest extends FunctionalTestCase
public
function
testFindWithFilter
()
{
$filter
=
array
(
'_id'
=>
1
)
;
$filter
=
[
'_id'
=>
1
]
;
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
(
$filter
));
}
public
function
testFindWithFilterSortSkipAndLimit
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
2
))
;
$options
=
array
(
'sort'
=>
array
(
'_id'
=>
1
)
,
$filter
=
[
'_id'
=>
[
'$gt'
=>
2
]]
;
$options
=
[
'sort'
=>
[
'_id'
=>
1
]
,
'skip'
=>
2
,
'limit'
=>
2
,
)
;
]
;
$expected
=
array
(
array
(
'_id'
=>
5
,
'x'
=>
55
)
,
)
;
$expected
=
[
[
'_id'
=>
5
,
'x'
=>
55
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
(
$filter
,
$options
));
}
public
function
testFindWithLimitSortAndBatchSize
()
{
$filter
=
array
()
;
$options
=
array
(
'sort'
=>
array
(
'_id'
=>
1
)
,
$filter
=
[]
;
$options
=
[
'sort'
=>
[
'_id'
=>
1
]
,
'limit'
=>
4
,
'batchSize'
=>
2
,
)
;
]
;
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
array
(
'_id'
=>
4
,
'x'
=>
44
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
[
'_id'
=>
4
,
'x'
=>
44
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
(
$filter
,
$options
));
}
...
...
tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php
View file @
4043b265
...
...
@@ -18,58 +18,58 @@ class FindOneAndDeleteFunctionalTest extends FunctionalTestCase
public
function
testFindOneAndDeleteWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
)
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
]
;
$document
=
$this
->
collection
->
findOneAndDelete
(
$filter
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
22
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
22
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndDeleteWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
2
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
)
;
$filter
=
[
'_id'
=>
2
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
]
;
$document
=
$this
->
collection
->
findOneAndDelete
(
$filter
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
22
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
22
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndDeleteWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
)
;
$filter
=
[
'_id'
=>
4
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
]
;
$document
=
$this
->
collection
->
findOneAndDelete
(
$filter
,
$options
);
$this
->
assertNull
(
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php
View file @
4043b265
...
...
@@ -21,178 +21,178 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
public
function
testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$replacement
=
array
(
'x'
=>
32
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
)
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$replacement
=
[
'x'
=>
32
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
]
;
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
22
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
22
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
32
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
32
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$replacement
=
array
(
'x'
=>
32
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$replacement
=
[
'x'
=>
32
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'returnDocument'
=>
FindOneAndReplace
::
RETURN_DOCUMENT_AFTER
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
32
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
32
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
32
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
32
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
2
)
;
$replacement
=
array
(
'x'
=>
32
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
)
;
$filter
=
[
'_id'
=>
2
]
;
$replacement
=
[
'x'
=>
32
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
]
;
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
22
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
22
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
32
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
32
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
2
)
;
$replacement
=
array
(
'x'
=>
32
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$filter
=
[
'_id'
=>
2
]
;
$replacement
=
[
'x'
=>
32
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'returnDocument'
=>
FindOneAndReplace
::
RETURN_DOCUMENT_AFTER
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
32
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
32
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
32
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
32
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$replacement
=
array
(
'x'
=>
44
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
)
;
$filter
=
[
'_id'
=>
4
]
;
$replacement
=
[
'x'
=>
44
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
]
;
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertNull
(
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$filter
=
[
'_id'
=>
4
]
;
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement
=
array
(
'_id'
=>
4
,
'x'
=>
44
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$replacement
=
[
'_id'
=>
4
,
'x'
=>
44
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'upsert'
=>
true
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertNull
(
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
array
(
'_id'
=>
4
,
'x'
=>
44
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
[
'_id'
=>
4
,
'x'
=>
44
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$replacement
=
array
(
'x'
=>
44
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$filter
=
[
'_id'
=>
4
]
;
$replacement
=
[
'x'
=>
44
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'returnDocument'
=>
FindOneAndReplace
::
RETURN_DOCUMENT_AFTER
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertNull
(
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$filter
=
[
'_id'
=>
4
]
;
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement
=
array
(
'_id'
=>
4
,
'x'
=>
44
)
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$replacement
=
[
'_id'
=>
4
,
'x'
=>
44
]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'returnDocument'
=>
FindOneAndReplace
::
RETURN_DOCUMENT_AFTER
,
'upsert'
=>
true
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
44
)
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
array
(
'_id'
=>
4
,
'x'
=>
44
)
,
)
;
$this
->
assertSameDocument
(
[
'x'
=>
44
]
,
$document
);
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
[
'_id'
=>
4
,
'x'
=>
44
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php
View file @
4043b265
...
...
@@ -21,176 +21,176 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
public
function
testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
)
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
]
;
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
22
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
22
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
23
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
23
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'returnDocument'
=>
FindOneAndUpdate
::
RETURN_DOCUMENT_AFTER
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
23
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
23
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
23
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
23
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
2
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
)
;
$filter
=
[
'_id'
=>
2
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
]
;
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
22
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
22
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
23
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
23
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
2
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$filter
=
[
'_id'
=>
2
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'returnDocument'
=>
FindOneAndUpdate
::
RETURN_DOCUMENT_AFTER
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
23
)
,
$document
);
$this
->
assertSameDocument
(
[
'x'
=>
23
]
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
23
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
23
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
)
;
$filter
=
[
'_id'
=>
4
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
]
;
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertNull
(
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$filter
=
[
'_id'
=>
4
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'upsert'
=>
true
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertNull
(
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
array
(
'_id'
=>
4
,
'x'
=>
1
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
[
'_id'
=>
4
,
'x'
=>
1
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$filter
=
[
'_id'
=>
4
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'returnDocument'
=>
FindOneAndUpdate
::
RETURN_DOCUMENT_AFTER
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertNull
(
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
)
,
'sort'
=>
array
(
'x'
=>
1
)
,
$filter
=
[
'_id'
=>
4
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'projection'
=>
[
'x'
=>
1
,
'_id'
=>
0
]
,
'sort'
=>
[
'x'
=>
1
]
,
'returnDocument'
=>
FindOneAndUpdate
::
RETURN_DOCUMENT_AFTER
,
'upsert'
=>
true
,
)
;
]
;
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSameDocument
(
array
(
'x'
=>
1
)
,
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
array
(
'_id'
=>
4
,
'x'
=>
1
)
,
)
;
$this
->
assertSameDocument
(
[
'x'
=>
1
]
,
$document
);
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
[
'_id'
=>
4
,
'x'
=>
1
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/CrudSpec/FunctionalTestCase.php
View file @
4043b265
...
...
@@ -20,10 +20,10 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
$bulkWrite
=
new
BulkWrite
([
'ordered'
=>
true
]);
for
(
$i
=
1
;
$i
<=
$n
;
$i
++
)
{
$bulkWrite
->
insert
(
array
(
$bulkWrite
->
insert
(
[
'_id'
=>
$i
,
'x'
=>
(
integer
)
(
$i
.
$i
),
)
);
]
);
}
$result
=
$this
->
manager
->
executeBulkWrite
(
$this
->
getNamespace
(),
$bulkWrite
);
...
...
tests/Collection/CrudSpec/InsertManyFunctionalTest.php
View file @
4043b265
...
...
@@ -18,20 +18,20 @@ class InsertManyFunctionalTest extends FunctionalTestCase
public
function
testInsertManyWithNonexistentDocuments
()
{
$documents
=
array
(
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$documents
=
[
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$result
=
$this
->
collection
->
insertMany
(
$documents
);
$this
->
assertSame
(
2
,
$result
->
getInsertedCount
());
$this
->
assertSame
(
array
(
2
,
3
)
,
$result
->
getInsertedIds
());
$this
->
assertSame
(
[
2
,
3
]
,
$result
->
getInsertedIds
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/CrudSpec/InsertOneFunctionalTest.php
View file @
4043b265
...
...
@@ -18,16 +18,16 @@ class InsertOneFunctionalTest extends FunctionalTestCase
public
function
testInsertOneWithANonexistentDocument
()
{
$document
=
array
(
'_id'
=>
2
,
'x'
=>
22
)
;
$document
=
[
'_id'
=>
2
,
'x'
=>
22
]
;
$result
=
$this
->
collection
->
insertOne
(
$document
);
$this
->
assertSame
(
1
,
$result
->
getInsertedCount
());
$this
->
assertSame
(
2
,
$result
->
getInsertedId
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php
View file @
4043b265
...
...
@@ -22,97 +22,97 @@ class ReplaceOneFunctionalTest extends FunctionalTestCase
public
function
testReplaceOneWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$replacement
=
array
(
'x'
=>
111
)
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$replacement
=
[
'x'
=>
111
]
;
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
111
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
111
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testReplaceOneWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
1
)
;
$replacement
=
array
(
'x'
=>
111
)
;
$filter
=
[
'_id'
=>
1
]
;
$replacement
=
[
'x'
=>
111
]
;
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
111
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
111
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testReplaceOneWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$replacement
=
array
(
'x'
=>
111
)
;
$filter
=
[
'_id'
=>
4
]
;
$replacement
=
[
'x'
=>
111
]
;
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testReplaceOneWithUpsertWhenNoDocumentsMatchWithAnIdSpecified
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$replacement
=
array
(
'_id'
=>
4
,
'x'
=>
1
)
;
$options
=
array
(
'upsert'
=>
true
)
;
$filter
=
[
'_id'
=>
4
]
;
$replacement
=
[
'_id'
=>
4
,
'x'
=>
1
]
;
$options
=
[
'upsert'
=>
true
]
;
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
,
$options
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$this
->
assertSame
(
4
,
$result
->
getUpsertedId
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
array
(
'_id'
=>
4
,
'x'
=>
1
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
[
'_id'
=>
4
,
'x'
=>
1
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testReplaceOneWithUpsertWhenNoDocumentsMatchWithoutAnIdSpecified
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$filter
=
[
'_id'
=>
4
]
;
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement
=
array
(
'_id'
=>
4
,
'x'
=>
1
)
;
$options
=
array
(
'upsert'
=>
true
)
;
$replacement
=
[
'_id'
=>
4
,
'x'
=>
1
]
;
$options
=
[
'upsert'
=>
true
]
;
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
,
$options
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$this
->
assertSame
(
4
,
$result
->
getUpsertedId
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
array
(
'_id'
=>
4
,
'x'
=>
1
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
[
'_id'
=>
4
,
'x'
=>
1
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/CrudSpec/UpdateManyFunctionalTest.php
View file @
4043b265
...
...
@@ -22,75 +22,75 @@ class UpdateManyFunctionalTest extends FunctionalTestCase
public
function
testUpdateManyWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$result
=
$this
->
collection
->
updateMany
(
$filter
,
$update
);
$this
->
assertSame
(
2
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
2
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
23
)
,
array
(
'_id'
=>
3
,
'x'
=>
34
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
23
]
,
[
'_id'
=>
3
,
'x'
=>
34
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateManyWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
1
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$filter
=
[
'_id'
=>
1
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$result
=
$this
->
collection
->
updateMany
(
$filter
,
$update
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
12
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
12
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateManyWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$filter
=
[
'_id'
=>
4
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$result
=
$this
->
collection
->
updateMany
(
$filter
,
$update
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateManyWithUpsertWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'upsert'
=>
true
)
;
$filter
=
[
'_id'
=>
4
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'upsert'
=>
true
]
;
$result
=
$this
->
collection
->
updateMany
(
$filter
,
$update
,
$options
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$this
->
assertSame
(
4
,
$result
->
getUpsertedId
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
array
(
'_id'
=>
4
,
'x'
=>
1
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
[
'_id'
=>
4
,
'x'
=>
1
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/CrudSpec/UpdateOneFunctionalTest.php
View file @
4043b265
...
...
@@ -22,75 +22,75 @@ class UpdateOneFunctionalTest extends FunctionalTestCase
public
function
testUpdateOneWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
))
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$filter
=
[
'_id'
=>
[
'$gt'
=>
1
]]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$result
=
$this
->
collection
->
updateOne
(
$filter
,
$update
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
23
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
23
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateOneWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
1
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$filter
=
[
'_id'
=>
1
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$result
=
$this
->
collection
->
updateOne
(
$filter
,
$update
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
12
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
12
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateOneWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$filter
=
[
'_id'
=>
4
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$result
=
$this
->
collection
->
updateOne
(
$filter
,
$update
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateOneWithUpsertWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
)
;
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
))
;
$options
=
array
(
'upsert'
=>
true
)
;
$filter
=
[
'_id'
=>
4
]
;
$update
=
[
'$inc'
=>
[
'x'
=>
1
]]
;
$options
=
[
'upsert'
=>
true
]
;
$result
=
$this
->
collection
->
updateOne
(
$filter
,
$update
,
$options
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
omitModifiedCount
or
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$this
->
assertSame
(
4
,
$result
->
getUpsertedId
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
)
,
array
(
'_id'
=>
2
,
'x'
=>
22
)
,
array
(
'_id'
=>
3
,
'x'
=>
33
)
,
array
(
'_id'
=>
4
,
'x'
=>
1
)
,
)
;
$expected
=
[
[
'_id'
=>
1
,
'x'
=>
11
]
,
[
'_id'
=>
2
,
'x'
=>
22
]
,
[
'_id'
=>
3
,
'x'
=>
33
]
,
[
'_id'
=>
4
,
'x'
=>
1
]
,
]
;
$this
->
assertSameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
...
...
tests/Collection/IndexManagementFunctionalTest.php
View file @
4043b265
...
...
@@ -16,28 +16,28 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
{
$that
=
$this
;
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
array
(
'x'
=>
1
),
array
(
'sparse'
=>
true
,
'unique'
=>
true
)
));
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
[
'x'
=>
1
],
[
'sparse'
=>
true
,
'unique'
=>
true
]
));
$this
->
assertIndexExists
(
'x_1'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$that
->
assertTrue
(
$info
->
isSparse
());
$that
->
assertTrue
(
$info
->
isUnique
());
$that
->
assertFalse
(
$info
->
isTtl
());
});
$this
->
assertSame
(
'y_-1_z_1'
,
$this
->
collection
->
createIndex
(
array
(
'y'
=>
-
1
,
'z'
=>
1
)
));
$this
->
assertSame
(
'y_-1_z_1'
,
$this
->
collection
->
createIndex
(
[
'y'
=>
-
1
,
'z'
=>
1
]
));
$this
->
assertIndexExists
(
'y_-1_z_1'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$that
->
assertFalse
(
$info
->
isSparse
());
$that
->
assertFalse
(
$info
->
isUnique
());
$that
->
assertFalse
(
$info
->
isTtl
());
});
$this
->
assertSame
(
'g_2dsphere_z_1'
,
$this
->
collection
->
createIndex
(
array
(
'g'
=>
'2dsphere'
,
'z'
=>
1
)
));
$this
->
assertSame
(
'g_2dsphere_z_1'
,
$this
->
collection
->
createIndex
(
[
'g'
=>
'2dsphere'
,
'z'
=>
1
]
));
$this
->
assertIndexExists
(
'g_2dsphere_z_1'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$that
->
assertFalse
(
$info
->
isSparse
());
$that
->
assertFalse
(
$info
->
isUnique
());
$that
->
assertFalse
(
$info
->
isTtl
());
});
$this
->
assertSame
(
'my_ttl'
,
$this
->
collection
->
createIndex
(
array
(
't'
=>
1
),
array
(
'expireAfterSeconds'
=>
0
,
'name'
=>
'my_ttl'
)
));
$this
->
assertSame
(
'my_ttl'
,
$this
->
collection
->
createIndex
(
[
't'
=>
1
],
[
'expireAfterSeconds'
=>
0
,
'name'
=>
'my_ttl'
]
));
$this
->
assertIndexExists
(
'my_ttl'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$that
->
assertFalse
(
$info
->
isSparse
());
$that
->
assertFalse
(
$info
->
isUnique
());
...
...
@@ -49,14 +49,14 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
{
$that
=
$this
;
$expectedNames
=
array
(
'x_1'
,
'y_-1_z_1'
,
'g_2dsphere_z_1'
,
'my_ttl'
)
;
$expectedNames
=
[
'x_1'
,
'y_-1_z_1'
,
'g_2dsphere_z_1'
,
'my_ttl'
]
;
$indexes
=
array
(
array
(
'key'
=>
array
(
'x'
=>
1
),
'sparse'
=>
true
,
'unique'
=>
true
)
,
array
(
'key'
=>
array
(
'y'
=>
-
1
,
'z'
=>
1
))
,
array
(
'key'
=>
array
(
'g'
=>
'2dsphere'
,
'z'
=>
1
))
,
array
(
'key'
=>
array
(
't'
=>
1
),
'expireAfterSeconds'
=>
0
,
'name'
=>
'my_ttl'
)
,
)
;
$indexes
=
[
[
'key'
=>
[
'x'
=>
1
],
'sparse'
=>
true
,
'unique'
=>
true
]
,
[
'key'
=>
[
'y'
=>
-
1
,
'z'
=>
1
]]
,
[
'key'
=>
[
'g'
=>
'2dsphere'
,
'z'
=>
1
]]
,
[
'key'
=>
[
't'
=>
1
],
'expireAfterSeconds'
=>
0
,
'name'
=>
'my_ttl'
]
,
]
;
$this
->
assertSame
(
$expectedNames
,
$this
->
collection
->
createIndexes
(
$indexes
));
...
...
@@ -90,12 +90,12 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
*/
public
function
testCreateIndexesRequiresAtLeastOneIndex
()
{
$this
->
assertSame
(
array
(),
$this
->
collection
->
createIndexes
(
array
()
));
$this
->
assertSame
(
[],
$this
->
collection
->
createIndexes
([]
));
}
public
function
testDropIndex
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
array
(
'x'
=>
1
)
));
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
[
'x'
=>
1
]
));
$this
->
assertIndexExists
(
'x_1'
);
$this
->
assertCommandSucceeded
(
$this
->
collection
->
dropIndex
(
'x_1'
));
...
...
@@ -111,7 +111,7 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
*/
public
function
testDropIndexShouldNotAllowEmptyIndexName
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
array
(
'x'
=>
1
)
));
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
[
'x'
=>
1
]
));
$this
->
assertIndexExists
(
'x_1'
);
$this
->
collection
->
dropIndex
(
''
);
}
...
...
@@ -121,15 +121,15 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
*/
public
function
testDropIndexShouldNotAllowWildcardCharacter
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
array
(
'x'
=>
1
)
));
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
[
'x'
=>
1
]
));
$this
->
assertIndexExists
(
'x_1'
);
$this
->
collection
->
dropIndex
(
'*'
);
}
public
function
testDropIndexes
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
array
(
'x'
=>
1
)
));
$this
->
assertSame
(
'y_1'
,
$this
->
collection
->
createIndex
(
array
(
'y'
=>
1
)
));
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
[
'x'
=>
1
]
));
$this
->
assertSame
(
'y_1'
,
$this
->
collection
->
createIndex
(
[
'y'
=>
1
]
));
$this
->
assertIndexExists
(
'x_1'
);
$this
->
assertIndexExists
(
'y_1'
);
$this
->
assertCommandSucceeded
(
$this
->
collection
->
dropIndexes
());
...
...
@@ -147,7 +147,7 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
public
function
testListIndexes
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
array
(
'x'
=>
1
)
));
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
[
'x'
=>
1
]
));
$indexes
=
$this
->
collection
->
listIndexes
();
$this
->
assertInstanceOf
(
'MongoDB\Model\IndexInfoIterator'
,
$indexes
);
...
...
tests/Database/CollectionManagementFunctionalTest.php
View file @
4043b265
...
...
@@ -23,11 +23,11 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase
});
$cappedCollectionName
=
$this
->
getCollectionName
()
.
'.capped'
;
$cappedCollectionOptions
=
array
(
$cappedCollectionOptions
=
[
'capped'
=>
true
,
'max'
=>
100
,
'size'
=>
1048576
,
)
;
]
;
$commandResult
=
$this
->
database
->
createCollection
(
$cappedCollectionName
,
$cappedCollectionOptions
);
$this
->
assertCommandSucceeded
(
$commandResult
);
...
...
@@ -70,7 +70,7 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase
$this
->
assertCommandSucceeded
(
$commandResult
);
$collectionName
=
$this
->
getCollectionName
();
$options
=
array
(
'filter'
=>
array
(
'name'
=>
$collectionName
))
;
$options
=
[
'filter'
=>
[
'name'
=>
$collectionName
]]
;
$collections
=
$this
->
database
->
listCollections
(
$options
);
$this
->
assertInstanceOf
(
'MongoDB\Model\CollectionInfoIterator'
,
$collections
);
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
4043b265
...
...
@@ -22,10 +22,10 @@ class DatabaseFunctionalTest extends FunctionalTestCase
public
function
provideInvalidDatabaseValues
()
{
return
array
(
array
(
null
)
,
array
(
''
)
,
)
;
return
[
[
null
]
,
[
''
]
,
]
;
}
public
function
testToString
()
...
...
tests/FunctionalTestCase.php
View file @
4043b265
...
...
@@ -22,8 +22,8 @@ abstract class FunctionalTestCase extends TestCase
{
list
(
$databaseName
,
$collectionName
)
=
explode
(
'.'
,
$namespace
,
2
);
$cursor
=
$this
->
manager
->
executeCommand
(
$databaseName
,
new
Command
(
array
(
'count'
=>
$collectionName
)
));
$cursor
->
setTypeMap
(
array
(
'root'
=>
'array'
,
'document'
=>
'array'
)
);
$cursor
=
$this
->
manager
->
executeCommand
(
$databaseName
,
new
Command
(
[
'count'
=>
$collectionName
]
));
$cursor
->
setTypeMap
(
[
'root'
=>
'array'
,
'document'
=>
'array'
]
);
$document
=
current
(
$cursor
->
toArray
());
$this
->
assertArrayHasKey
(
'n'
,
$document
);
...
...
@@ -77,11 +77,11 @@ abstract class FunctionalTestCase extends TestCase
{
$cursor
=
$this
->
manager
->
executeCommand
(
$this
->
getDatabaseName
(),
new
Command
(
array
(
'buildInfo'
=>
1
)
),
new
Command
(
[
'buildInfo'
=>
1
]
),
$readPreference
?:
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
)
);
$cursor
->
setTypeMap
(
array
(
'root'
=>
'array'
,
'document'
=>
'array'
)
);
$cursor
->
setTypeMap
(
[
'root'
=>
'array'
,
'document'
=>
'array'
]
);
$document
=
current
(
$cursor
->
toArray
());
return
$document
[
'version'
];
...
...
tests/Model/CollectionInfoTest.php
View file @
4043b265
...
...
@@ -9,32 +9,32 @@ class CollectionInfoTest extends TestCase
{
public
function
testGetName
()
{
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
)
);
$info
=
new
CollectionInfo
(
[
'name'
=>
'foo'
]
);
$this
->
assertSame
(
'foo'
,
$info
->
getName
());
}
public
function
testGetOptions
()
{
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
)
);
$this
->
assertSame
(
array
()
,
$info
->
getOptions
());
$info
=
new
CollectionInfo
(
[
'name'
=>
'foo'
]
);
$this
->
assertSame
(
[]
,
$info
->
getOptions
());
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
,
'options'
=>
array
(
'capped'
=>
true
,
'size'
=>
1048576
))
);
$this
->
assertSame
(
array
(
'capped'
=>
true
,
'size'
=>
1048576
)
,
$info
->
getOptions
());
$info
=
new
CollectionInfo
(
[
'name'
=>
'foo'
,
'options'
=>
[
'capped'
=>
true
,
'size'
=>
1048576
]]
);
$this
->
assertSame
(
[
'capped'
=>
true
,
'size'
=>
1048576
]
,
$info
->
getOptions
());
}
public
function
testCappedCollectionMethods
()
{
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
)
);
$info
=
new
CollectionInfo
(
[
'name'
=>
'foo'
]
);
$this
->
assertFalse
(
$info
->
isCapped
());
$this
->
assertNull
(
$info
->
getCappedMax
());
$this
->
assertNull
(
$info
->
getCappedSize
());
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
,
'options'
=>
array
(
'capped'
=>
true
,
'size'
=>
1048576
))
);
$info
=
new
CollectionInfo
(
[
'name'
=>
'foo'
,
'options'
=>
[
'capped'
=>
true
,
'size'
=>
1048576
]]
);
$this
->
assertTrue
(
$info
->
isCapped
());
$this
->
assertNull
(
$info
->
getCappedMax
());
$this
->
assertSame
(
1048576
,
$info
->
getCappedSize
());
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
,
'options'
=>
array
(
'capped'
=>
true
,
'size'
=>
1048576
,
'max'
=>
100
))
);
$info
=
new
CollectionInfo
(
[
'name'
=>
'foo'
,
'options'
=>
[
'capped'
=>
true
,
'size'
=>
1048576
,
'max'
=>
100
]]
);
$this
->
assertTrue
(
$info
->
isCapped
());
$this
->
assertSame
(
100
,
$info
->
getCappedMax
());
$this
->
assertSame
(
1048576
,
$info
->
getCappedSize
());
...
...
@@ -42,10 +42,10 @@ class CollectionInfoTest extends TestCase
public
function
testDebugInfo
()
{
$expectedInfo
=
array
(
$expectedInfo
=
[
'name'
=>
'foo'
,
'options'
=>
array
(
'capped'
=>
true
,
'size'
=>
1048576
)
,
)
;
'options'
=>
[
'capped'
=>
true
,
'size'
=>
1048576
]
,
]
;
$info
=
new
CollectionInfo
(
$expectedInfo
);
$this
->
assertSame
(
$expectedInfo
,
$info
->
__debugInfo
());
...
...
tests/Model/DatabaseInfoTest.php
View file @
4043b265
...
...
@@ -9,32 +9,32 @@ class DatabaseInfoTest extends TestCase
{
public
function
testGetName
()
{
$info
=
new
DatabaseInfo
(
array
(
'name'
=>
'foo'
)
);
$info
=
new
DatabaseInfo
(
[
'name'
=>
'foo'
]
);
$this
->
assertSame
(
'foo'
,
$info
->
getName
());
}
public
function
testGetSizeOnDisk
()
{
$info
=
new
DatabaseInfo
(
array
(
'sizeOnDisk'
=>
1048576
)
);
$info
=
new
DatabaseInfo
(
[
'sizeOnDisk'
=>
1048576
]
);
$this
->
assertSame
(
1048576
,
$info
->
getSizeOnDisk
());
}
public
function
testIsEmpty
()
{
$info
=
new
DatabaseInfo
(
array
(
'empty'
=>
false
)
);
$info
=
new
DatabaseInfo
(
[
'empty'
=>
false
]
);
$this
->
assertFalse
(
$info
->
isEmpty
());
$info
=
new
DatabaseInfo
(
array
(
'empty'
=>
true
)
);
$info
=
new
DatabaseInfo
(
[
'empty'
=>
true
]
);
$this
->
assertTrue
(
$info
->
isEmpty
());
}
public
function
testDebugInfo
()
{
$expectedInfo
=
array
(
$expectedInfo
=
[
'name'
=>
'foo'
,
'sizeOnDisk'
=>
1048576
,
'empty'
=>
false
,
)
;
]
;
$info
=
new
DatabaseInfo
(
$expectedInfo
);
$this
->
assertSame
(
$expectedInfo
,
$info
->
__debugInfo
());
...
...
tests/Model/IndexInfoTest.php
View file @
4043b265
...
...
@@ -9,15 +9,15 @@ class IndexInfoTest extends TestCase
{
public
function
testBasicIndex
()
{
$info
=
new
IndexInfo
(
array
(
$info
=
new
IndexInfo
(
[
'v'
=>
1
,
'key'
=>
array
(
'x'
=>
1
)
,
'key'
=>
[
'x'
=>
1
]
,
'name'
=>
'x_1'
,
'ns'
=>
'foo.bar'
,
)
);
]
);
$this
->
assertSame
(
1
,
$info
->
getVersion
());
$this
->
assertSame
(
array
(
'x'
=>
1
)
,
$info
->
getKey
());
$this
->
assertSame
(
[
'x'
=>
1
]
,
$info
->
getKey
());
$this
->
assertSame
(
'x_1'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
isSparse
());
...
...
@@ -27,16 +27,16 @@ class IndexInfoTest extends TestCase
public
function
testSparseIndex
()
{
$info
=
new
IndexInfo
(
array
(
$info
=
new
IndexInfo
(
[
'v'
=>
1
,
'key'
=>
array
(
'y'
=>
1
)
,
'key'
=>
[
'y'
=>
1
]
,
'name'
=>
'y_sparse'
,
'ns'
=>
'foo.bar'
,
'sparse'
=>
true
,
)
);
]
);
$this
->
assertSame
(
1
,
$info
->
getVersion
());
$this
->
assertSame
(
array
(
'y'
=>
1
)
,
$info
->
getKey
());
$this
->
assertSame
(
[
'y'
=>
1
]
,
$info
->
getKey
());
$this
->
assertSame
(
'y_sparse'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertTrue
(
$info
->
isSparse
());
...
...
@@ -46,16 +46,16 @@ class IndexInfoTest extends TestCase
public
function
testUniqueIndex
()
{
$info
=
new
IndexInfo
(
array
(
$info
=
new
IndexInfo
(
[
'v'
=>
1
,
'key'
=>
array
(
'z'
=>
1
)
,
'key'
=>
[
'z'
=>
1
]
,
'name'
=>
'z_unique'
,
'ns'
=>
'foo.bar'
,
'unique'
=>
true
,
)
);
]
);
$this
->
assertSame
(
1
,
$info
->
getVersion
());
$this
->
assertSame
(
array
(
'z'
=>
1
)
,
$info
->
getKey
());
$this
->
assertSame
(
[
'z'
=>
1
]
,
$info
->
getKey
());
$this
->
assertSame
(
'z_unique'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
isSparse
());
...
...
@@ -65,16 +65,16 @@ class IndexInfoTest extends TestCase
public
function
testTtlIndex
()
{
$info
=
new
IndexInfo
(
array
(
$info
=
new
IndexInfo
(
[
'v'
=>
1
,
'key'
=>
array
(
'z'
=>
1
)
,
'key'
=>
[
'z'
=>
1
]
,
'name'
=>
'z_unique'
,
'ns'
=>
'foo.bar'
,
'expireAfterSeconds'
=>
100
,
)
);
]
);
$this
->
assertSame
(
1
,
$info
->
getVersion
());
$this
->
assertSame
(
array
(
'z'
=>
1
)
,
$info
->
getKey
());
$this
->
assertSame
(
[
'z'
=>
1
]
,
$info
->
getKey
());
$this
->
assertSame
(
'z_unique'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
isSparse
());
...
...
@@ -86,12 +86,12 @@ class IndexInfoTest extends TestCase
public
function
testDebugInfo
()
{
$expectedInfo
=
array
(
$expectedInfo
=
[
'v'
=>
1
,
'key'
=>
array
(
'x'
=>
1
)
,
'key'
=>
[
'x'
=>
1
]
,
'name'
=>
'x_1'
,
'ns'
=>
'foo.bar'
,
)
;
]
;
$info
=
new
IndexInfo
(
$expectedInfo
);
$this
->
assertSame
(
$expectedInfo
,
$info
->
__debugInfo
());
...
...
tests/Model/IndexInputTest.php
View file @
4043b265
...
...
@@ -12,7 +12,7 @@ class IndexInputTest extends TestCase
*/
public
function
testConstructorShouldRequireKey
()
{
new
IndexInput
(
array
()
);
new
IndexInput
(
[]
);
}
/**
...
...
@@ -20,7 +20,7 @@ class IndexInputTest extends TestCase
*/
public
function
testConstructorShouldRequireKeyToBeArrayOrObject
()
{
new
IndexInput
(
array
(
'key'
=>
'foo'
)
);
new
IndexInput
(
[
'key'
=>
'foo'
]
);
}
/**
...
...
@@ -28,7 +28,7 @@ class IndexInputTest extends TestCase
*/
public
function
testConstructorShouldRequireKeyOrderToBeScalar
()
{
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
array
()))
);
new
IndexInput
(
[
'key'
=>
[
'x'
=>
[]]]
);
}
/**
...
...
@@ -36,7 +36,7 @@ class IndexInputTest extends TestCase
*/
public
function
testConstructorShouldRequireNamespace
()
{
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
1
))
);
new
IndexInput
(
[
'key'
=>
[
'x'
=>
1
]]
);
}
/**
...
...
@@ -44,7 +44,7 @@ class IndexInputTest extends TestCase
*/
public
function
testConstructorShouldRequireNamespaceToBeString
()
{
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
1
),
'ns'
=>
1
)
);
new
IndexInput
(
[
'key'
=>
[
'x'
=>
1
],
'ns'
=>
1
]
);
}
/**
...
...
@@ -52,7 +52,7 @@ class IndexInputTest extends TestCase
*/
public
function
testConstructorShouldRequireNameToBeString
()
{
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
1
),
'ns'
=>
'foo.bar'
,
'name'
=>
1
)
);
new
IndexInput
(
[
'key'
=>
[
'x'
=>
1
],
'ns'
=>
'foo.bar'
,
'name'
=>
1
]
);
}
/**
...
...
@@ -60,32 +60,32 @@ class IndexInputTest extends TestCase
*/
public
function
testNameGeneration
(
$expectedName
,
array
$key
)
{
$this
->
assertSame
(
$expectedName
,
(
string
)
new
IndexInput
(
array
(
'key'
=>
$key
,
'ns'
=>
'foo.bar'
)
));
$this
->
assertSame
(
$expectedName
,
(
string
)
new
IndexInput
(
[
'key'
=>
$key
,
'ns'
=>
'foo.bar'
]
));
}
public
function
provideExpectedNameAndKey
()
{
return
array
(
array
(
'x_1'
,
array
(
'x'
=>
1
))
,
array
(
'x_1_y_-1'
,
array
(
'x'
=>
1
,
'y'
=>
-
1
))
,
array
(
'loc_2dsphere'
,
array
(
'loc'
=>
'2dsphere'
))
,
array
(
'loc_2dsphere_x_1'
,
array
(
'loc'
=>
'2dsphere'
,
'x'
=>
1
))
,
array
(
'doc_text'
,
array
(
'doc'
=>
'text'
))
,
)
;
return
[
[
'x_1'
,
[
'x'
=>
1
]]
,
[
'x_1_y_-1'
,
[
'x'
=>
1
,
'y'
=>
-
1
]]
,
[
'loc_2dsphere'
,
[
'loc'
=>
'2dsphere'
]]
,
[
'loc_2dsphere_x_1'
,
[
'loc'
=>
'2dsphere'
,
'x'
=>
1
]]
,
[
'doc_text'
,
[
'doc'
=>
'text'
]]
,
]
;
}
public
function
testBsonSerialization
()
{
$expected
=
array
(
'key'
=>
array
(
'x'
=>
1
)
,
$expected
=
[
'key'
=>
[
'x'
=>
1
]
,
'ns'
=>
'foo.bar'
,
'name'
=>
'x_1'
,
)
;
]
;
$indexInput
=
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
1
)
,
$indexInput
=
new
IndexInput
(
[
'key'
=>
[
'x'
=>
1
]
,
'ns'
=>
'foo.bar'
,
)
);
]
);
$this
->
assertInstanceOf
(
'MongoDB\BSON\Serializable'
,
$indexInput
);
$this
->
assertEquals
(
$expected
,
$indexInput
->
bsonSerialize
());
...
...
tests/Operation/AggregateTest.php
View file @
4043b265
...
...
@@ -12,7 +12,7 @@ class AggregateTest extends TestCase
*/
public
function
testConstructorPipelineArgumentMustNotBeEmpty
()
{
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
()
);
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
);
}
/**
...
...
@@ -21,7 +21,7 @@ class AggregateTest extends TestCase
*/
public
function
testConstructorPipelineArgumentMustBeAList
()
{
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
1
=>
array
(
'$match'
=>
array
(
'x'
=>
1
)))
);
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
1
=>
[
'$match'
=>
[
'x'
=>
1
]]]
);
}
/**
...
...
@@ -30,31 +30,31 @@ class AggregateTest extends TestCase
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
'$match'
=>
array
(
'x'
=>
1
)))
,
$options
);
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'$match'
=>
[
'x'
=>
1
]]]
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
()
;
$options
=
[]
;
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'allowDiskUse'
=>
$value
)
;
$options
[][]
=
[
'allowDiskUse'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'batchSize'
=>
$value
)
;
$options
[][]
=
[
'batchSize'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'maxTimeMS'
=>
$value
)
;
$options
[][]
=
[
'maxTimeMS'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidReadPreferenceValues
()
as
$value
)
{
$options
[][]
=
array
(
'readPreference'
=>
$value
)
;
$options
[][]
=
[
'readPreference'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'useCursor'
=>
$value
)
;
$options
[][]
=
[
'useCursor'
=>
$value
]
;
}
return
$options
;
...
...
@@ -69,8 +69,8 @@ class AggregateTest extends TestCase
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
'$match'
=>
array
(
'x'
=>
1
)))
,
array
(
'batchSize'
=>
100
,
'useCursor'
=>
false
)
[[
'$match'
=>
[
'x'
=>
1
]]]
,
[
'batchSize'
=>
100
,
'useCursor'
=>
false
]
);
}
}
tests/Operation/BulkWriteTest.php
View file @
4043b265
...
...
@@ -12,7 +12,7 @@ class BulkWriteTest extends TestCase
*/
public
function
testOperationsMustNotBeEmpty
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
()
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
);
}
/**
...
...
@@ -21,9 +21,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testOperationsMustBeAList
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
1
=>
array
(
BulkWrite
::
INSERT_ONE
=>
array
(
array
(
'x'
=>
1
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
1
=>
[
BulkWrite
::
INSERT_ONE
=>
[[
'x'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -32,12 +32,12 @@ class BulkWriteTest extends TestCase
*/
public
function
testMultipleOperationsInOneElement
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
INSERT_ONE
=>
array
(
array
(
'x'
=>
1
))
,
BulkWrite
::
DELETE_ONE
=>
array
(
array
(
'x'
=>
1
))
,
)
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
INSERT_ONE
=>
[[
'x'
=>
1
]]
,
BulkWrite
::
DELETE_ONE
=>
[[
'x'
=>
1
]]
,
]
,
]
);
}
/**
...
...
@@ -46,9 +46,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUnknownOperation
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
'foo'
=>
array
(
array
(
'_id'
=>
1
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
'foo'
=>
[[
'_id'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -57,9 +57,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testInsertOneDocumentArgumentMissing
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
INSERT_ONE
=>
array
())
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
INSERT_ONE
=>
[]]
,
]
);
}
/**
...
...
@@ -69,9 +69,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testInsertOneDocumentArgumentTypeCheck
(
$document
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
INSERT_ONE
=>
array
(
$document
))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
INSERT_ONE
=>
[
$document
]]
,
]
);
}
/**
...
...
@@ -80,9 +80,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testDeleteManyFilterArgumentMissing
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
DELETE_MANY
=>
array
())
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
DELETE_MANY
=>
[]]
,
]
);
}
/**
...
...
@@ -92,9 +92,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testDeleteManyFilterArgumentTypeCheck
(
$document
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
DELETE_MANY
=>
array
(
$document
))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
DELETE_MANY
=>
[
$document
]]
,
]
);
}
/**
...
...
@@ -103,9 +103,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testDeleteOneFilterArgumentMissing
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
DELETE_ONE
=>
array
())
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
DELETE_ONE
=>
[]]
,
]
);
}
/**
...
...
@@ -115,9 +115,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testDeleteOneFilterArgumentTypeCheck
(
$document
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
DELETE_ONE
=>
array
(
$document
))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
DELETE_ONE
=>
[
$document
]]
,
]
);
}
/**
...
...
@@ -126,9 +126,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testReplaceOneFilterArgumentMissing
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
REPLACE_ONE
=>
array
())
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
REPLACE_ONE
=>
[]]
,
]
);
}
/**
...
...
@@ -138,9 +138,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testReplaceOneFilterArgumentTypeCheck
(
$filter
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
$filter
,
array
(
'y'
=>
1
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
REPLACE_ONE
=>
[
$filter
,
[
'y'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -149,9 +149,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testReplaceOneReplacementArgumentMissing
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
array
(
'x'
=>
1
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
REPLACE_ONE
=>
[[
'x'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -161,9 +161,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testReplaceOneReplacementArgumentTypeCheck
(
$replacement
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
array
(
'x'
=>
1
),
$replacement
))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
REPLACE_ONE
=>
[[
'x'
=>
1
],
$replacement
]]
,
]
);
}
/**
...
...
@@ -172,9 +172,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testReplaceOneReplacementArgumentRequiresNoOperators
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
array
(
'_id'
=>
1
),
array
(
'$inc'
=>
array
(
'x'
=>
1
))))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
REPLACE_ONE
=>
[[
'_id'
=>
1
],
[
'$inc'
=>
[
'x'
=>
1
]]]]
,
]
);
}
/**
...
...
@@ -184,9 +184,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testReplaceOneUpsertOptionTypeCheck
(
$upsert
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
array
(
'x'
=>
1
),
array
(
'y'
=>
1
),
array
(
'upsert'
=>
$upsert
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
REPLACE_ONE
=>
[[
'x'
=>
1
],
[
'y'
=>
1
],
[
'upsert'
=>
$upsert
]]]
,
]
);
}
/**
...
...
@@ -195,9 +195,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateManyFilterArgumentMissing
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_MANY
=>
array
())
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_MANY
=>
[]]
,
]
);
}
/**
...
...
@@ -207,9 +207,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateManyFilterArgumentTypeCheck
(
$filter
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
))))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_MANY
=>
[
$filter
,
[
'$set'
=>
[
'x'
=>
1
]]]]
,
]
);
}
/**
...
...
@@ -218,9 +218,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateManyUpdateArgumentMissing
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
array
(
'x'
=>
1
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_MANY
=>
[[
'x'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -230,9 +230,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateManyUpdateArgumentTypeCheck
(
$update
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
array
(
'x'
=>
1
),
$update
))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_MANY
=>
[[
'x'
=>
1
],
$update
]]
,
]
);
}
/**
...
...
@@ -241,9 +241,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateManyUpdateArgumentRequiresOperators
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
array
(
'_id'
=>
array
(
'$gt'
=>
1
)),
array
(
'x'
=>
1
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_MANY
=>
[[
'_id'
=>
[
'$gt'
=>
1
]],
[
'x'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -253,9 +253,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateManyUpsertOptionTypeCheck
(
$upsert
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
array
(
'x'
=>
1
),
array
(
'$set'
=>
array
(
'x'
=>
1
)),
array
(
'upsert'
=>
$upsert
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_MANY
=>
[[
'x'
=>
1
],
[
'$set'
=>
[
'x'
=>
1
]],
[
'upsert'
=>
$upsert
]]]
,
]
);
}
/**
...
...
@@ -264,9 +264,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateOneFilterArgumentMissing
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_ONE
=>
array
())
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_ONE
=>
[]]
,
]
);
}
/**
...
...
@@ -276,9 +276,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateOneFilterArgumentTypeCheck
(
$filter
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
))))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_ONE
=>
[
$filter
,
[
'$set'
=>
[
'x'
=>
1
]]]]
,
]
);
}
/**
...
...
@@ -287,9 +287,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateOneUpdateArgumentMissing
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
array
(
'x'
=>
1
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_ONE
=>
[[
'x'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -299,9 +299,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateOneUpdateArgumentTypeCheck
(
$update
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
array
(
'x'
=>
1
),
$update
))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_ONE
=>
[[
'x'
=>
1
],
$update
]]
,
]
);
}
/**
...
...
@@ -310,9 +310,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateOneUpdateArgumentRequiresOperators
()
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
array
(
'_id'
=>
1
),
array
(
'x'
=>
1
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_ONE
=>
[[
'_id'
=>
1
],
[
'x'
=>
1
]]]
,
]
);
}
/**
...
...
@@ -322,9 +322,9 @@ class BulkWriteTest extends TestCase
*/
public
function
testUpdateOneUpsertOptionTypeCheck
(
$upsert
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
array
(
'x'
=>
1
),
array
(
'$set'
=>
array
(
'x'
=>
1
)),
array
(
'upsert'
=>
$upsert
)))
,
)
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_ONE
=>
[[
'x'
=>
1
],
[
'$set'
=>
[
'x'
=>
1
]],
[
'upsert'
=>
$upsert
]]]
,
]
);
}
/**
...
...
@@ -336,21 +336,21 @@ class BulkWriteTest extends TestCase
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
INSERT_ONE
=>
array
(
array
(
'x'
=>
1
))))
,
[[
BulkWrite
::
INSERT_ONE
=>
[[
'x'
=>
1
]]]]
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
()
;
$options
=
[]
;
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'ordered'
=>
$value
)
;
$options
[][]
=
[
'ordered'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
)
;
$options
[][]
=
[
'writeConcern'
=>
$value
]
;
}
return
$options
;
...
...
tests/Operation/CountTest.php
View file @
4043b265
...
...
@@ -21,31 +21,31 @@ class CountTest extends TestCase
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
()
,
$options
);
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
()
;
$options
=
[]
;
foreach
(
$this
->
getInvalidHintValues
()
as
$value
)
{
$options
[][]
=
array
(
'hint'
=>
$value
)
;
$options
[][]
=
[
'hint'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'limit'
=>
$value
)
;
$options
[][]
=
[
'limit'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'maxTimeMS'
=>
$value
)
;
$options
[][]
=
[
'maxTimeMS'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidReadPreferenceValues
()
as
$value
)
{
$options
[][]
=
array
(
'readPreference'
=>
$value
)
;
$options
[][]
=
[
'readPreference'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'skip'
=>
$value
)
;
$options
[][]
=
[
'skip'
=>
$value
]
;
}
return
$options
;
...
...
@@ -53,6 +53,6 @@ class CountTest extends TestCase
private
function
getInvalidHintValues
()
{
return
array
(
123
,
3.14
,
true
)
;
return
[
123
,
3.14
,
true
]
;
}
}
tests/Operation/DeleteTest.php
View file @
4043b265
...
...
@@ -22,12 +22,12 @@ class DeleteTest extends TestCase
*/
public
function
testConstructorLimitArgumentMustBeOneOrZero
(
$limit
)
{
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
()
,
$limit
);
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
,
$limit
);
}
public
function
provideInvalidLimitValues
()
{
return
$this
->
wrapValuesForDataProvider
(
array_merge
(
$this
->
getInvalidIntegerValues
(),
array
(
-
1
,
2
)
));
return
$this
->
wrapValuesForDataProvider
(
array_merge
(
$this
->
getInvalidIntegerValues
(),
[
-
1
,
2
]
));
}
/**
...
...
@@ -36,15 +36,15 @@ class DeleteTest extends TestCase
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
()
,
1
,
$options
);
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
,
1
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
()
;
$options
=
[]
;
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
)
;
$options
[][]
=
[
'writeConcern'
=>
$value
]
;
}
return
$options
;
...
...
tests/Operation/DistinctTest.php
View file @
4043b265
...
...
@@ -21,19 +21,19 @@ class DistinctTest extends TestCase
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
array
()
,
$options
);
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
[]
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
()
;
$options
=
[]
;
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'maxTimeMS'
=>
$value
)
;
$options
[][]
=
[
'maxTimeMS'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidReadPreferenceValues
()
as
$value
)
{
$options
[][]
=
array
(
'readPreference'
=>
$value
)
;
$options
[][]
=
[
'readPreference'
=>
$value
]
;
}
return
$options
;
...
...
tests/Operation/FindTest.php
View file @
4043b265
...
...
@@ -21,59 +21,59 @@ class FindTest extends TestCase
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
()
,
$options
);
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
()
;
$options
=
[]
;
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'allowPartialResults'
=>
$value
)
;
$options
[][]
=
[
'allowPartialResults'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'batchSize'
=>
$value
)
;
$options
[][]
=
[
'batchSize'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidStringValues
()
as
$value
)
{
$options
[][]
=
array
(
'comment'
=>
$value
)
;
$options
[][]
=
[
'comment'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'cursorType'
=>
$value
)
;
$options
[][]
=
[
'cursorType'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'limit'
=>
$value
)
;
$options
[][]
=
[
'limit'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'maxTimeMS'
=>
$value
)
;
$options
[][]
=
[
'maxTimeMS'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
array
(
'modifiers'
=>
$value
)
;
$options
[][]
=
[
'modifiers'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'oplogReplay'
=>
$value
)
;
$options
[][]
=
[
'oplogReplay'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
array
(
'projection'
=>
$value
)
;
$options
[][]
=
[
'projection'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidReadPreferenceValues
()
as
$value
)
{
$options
[][]
=
array
(
'readPreference'
=>
$value
)
;
$options
[][]
=
[
'readPreference'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'skip'
=>
$value
)
;
$options
[][]
=
[
'skip'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
array
(
'sort'
=>
$value
)
;
$options
[][]
=
[
'sort'
=>
$value
]
;
}
return
$options
;
...
...
@@ -85,11 +85,11 @@ class FindTest extends TestCase
*/
public
function
testConstructorCursorTypeOption
(
$cursorType
)
{
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(),
array
(
'cursorType'
=>
$cursorType
)
);
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'cursorType'
=>
$cursorType
]
);
}
public
function
provideInvalidConstructorCursorTypeOptions
()
{
return
$this
->
wrapValuesForDataProvider
(
array
(
-
1
,
0
,
4
)
);
return
$this
->
wrapValuesForDataProvider
(
[
-
1
,
0
,
4
]
);
}
}
tests/Operation/InsertManyTest.php
View file @
4043b265
...
...
@@ -12,7 +12,7 @@ class InsertManyTest extends TestCase
*/
public
function
testConstructorDocumentsMustNotBeEmpty
()
{
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
()
);
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
);
}
/**
...
...
@@ -21,7 +21,7 @@ class InsertManyTest extends TestCase
*/
public
function
testConstructorDocumentsMustBeAList
()
{
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
1
=>
array
(
'x'
=>
1
))
);
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
1
=>
[
'x'
=>
1
]]
);
}
/**
...
...
@@ -31,7 +31,7 @@ class InsertManyTest extends TestCase
*/
public
function
testConstructorDocumentsArgumentElementTypeChecks
(
$document
)
{
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
$document
)
);
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
$document
]
);
}
/**
...
...
@@ -40,19 +40,19 @@ class InsertManyTest extends TestCase
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
'x'
=>
1
))
,
$options
);
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'x'
=>
1
]]
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
()
;
$options
=
[]
;
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'ordered'
=>
$value
)
;
$options
[][]
=
[
'ordered'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
)
;
$options
[][]
=
[
'writeConcern'
=>
$value
]
;
}
return
$options
;
...
...
tests/Operation/InsertOneTest.php
View file @
4043b265
...
...
@@ -21,15 +21,15 @@ class InsertOneTest extends TestCase
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
)
,
$options
);
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
]
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
()
;
$options
=
[]
;
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
)
;
$options
[][]
=
[
'writeConcern'
=>
$value
]
;
}
return
$options
;
...
...
tests/Operation/ReplaceOneTest.php
View file @
4043b265
...
...
@@ -12,7 +12,7 @@ class ReplaceOneTest extends TestCase
*/
public
function
testConstructorFilterArgumentTypeCheck
(
$filter
)
{
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'y'
=>
1
)
);
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
[
'y'
=>
1
]
);
}
/**
...
...
@@ -21,7 +21,7 @@ class ReplaceOneTest extends TestCase
*/
public
function
testConstructorReplacementArgumentTypeCheck
(
$replacement
)
{
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
)
,
$replacement
);
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
]
,
$replacement
);
}
/**
...
...
@@ -30,6 +30,6 @@ class ReplaceOneTest extends TestCase
*/
public
function
testConstructorReplacementArgumentRequiresNoOperators
()
{
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
array
(
'$set'
=>
array
(
'x'
=>
1
))
);
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
],
[
'$set'
=>
[
'x'
=>
1
]]
);
}
}
tests/Operation/TestCase.php
View file @
4043b265
...
...
@@ -22,41 +22,41 @@ abstract class TestCase extends BaseTestCase
protected
function
getInvalidArrayValues
()
{
return
array
(
123
,
3.14
,
'foo'
,
true
,
new
stdClass
)
;
return
[
123
,
3.14
,
'foo'
,
true
,
new
stdClass
]
;
}
protected
function
getInvalidBooleanValues
()
{
return
array
(
123
,
3.14
,
'foo'
,
array
(),
new
stdClass
)
;
return
[
123
,
3.14
,
'foo'
,
[],
new
stdClass
]
;
}
protected
function
getInvalidDocumentValues
()
{
return
array
(
123
,
3.14
,
'foo'
,
true
)
;
return
[
123
,
3.14
,
'foo'
,
true
]
;
}
protected
function
getInvalidIntegerValues
()
{
return
array
(
3.14
,
'foo'
,
true
,
array
(),
new
stdClass
)
;
return
[
3.14
,
'foo'
,
true
,
[],
new
stdClass
]
;
}
protected
function
getInvalidStringValues
()
{
return
array
(
123
,
3.14
,
true
,
array
(),
new
stdClass
)
;
return
[
123
,
3.14
,
true
,
[],
new
stdClass
]
;
}
protected
function
getInvalidReadPreferenceValues
()
{
return
array
(
123
,
3.14
,
'foo'
,
true
,
array
(),
new
stdClass
)
;
return
[
123
,
3.14
,
'foo'
,
true
,
[],
new
stdClass
]
;
}
protected
function
getInvalidWriteConcernValues
()
{
return
array
(
123
,
3.14
,
'foo'
,
true
,
array
(),
new
stdClass
)
;
return
[
123
,
3.14
,
'foo'
,
true
,
[],
new
stdClass
]
;
}
protected
function
wrapValuesForDataProvider
(
array
$values
)
{
return
array_map
(
function
(
$value
)
{
return
array
(
$value
)
;
},
$values
);
return
array_map
(
function
(
$value
)
{
return
[
$value
]
;
},
$values
);
}
}
tests/Operation/UpdateManyTest.php
View file @
4043b265
...
...
@@ -12,7 +12,7 @@ class UpdateManyTest extends TestCase
*/
public
function
testConstructorFilterArgumentTypeCheck
(
$filter
)
{
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
))
);
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
[
'$set'
=>
[
'x'
=>
1
]]
);
}
/**
...
...
@@ -21,7 +21,7 @@ class UpdateManyTest extends TestCase
*/
public
function
testConstructorUpdateArgumentTypeCheck
(
$update
)
{
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
)
,
$update
);
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
]
,
$update
);
}
/**
...
...
@@ -30,6 +30,6 @@ class UpdateManyTest extends TestCase
*/
public
function
testConstructorUpdateArgumentRequiresOperators
()
{
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
array
(
'y'
=>
1
)
);
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
],
[
'y'
=>
1
]
);
}
}
tests/Operation/UpdateOneTest.php
View file @
4043b265
...
...
@@ -12,7 +12,7 @@ class UpdateOneTest extends TestCase
*/
public
function
testConstructorFilterArgumentTypeCheck
(
$filter
)
{
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
))
);
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
[
'$set'
=>
[
'x'
=>
1
]]
);
}
/**
...
...
@@ -21,7 +21,7 @@ class UpdateOneTest extends TestCase
*/
public
function
testConstructorUpdateArgumentTypeCheck
(
$update
)
{
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
)
,
$update
);
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
]
,
$update
);
}
/**
...
...
@@ -30,6 +30,6 @@ class UpdateOneTest extends TestCase
*/
public
function
testConstructorUpdateArgumentRequiresOperators
()
{
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
array
(
'y'
=>
1
)
);
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
],
[
'y'
=>
1
]
);
}
}
tests/Operation/UpdateTest.php
View file @
4043b265
...
...
@@ -13,7 +13,7 @@ class UpdateTest extends TestCase
*/
public
function
testConstructorFilterArgumentTypeCheck
(
$filter
)
{
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
))
);
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
[
'$set'
=>
[
'x'
=>
1
]]
);
}
/**
...
...
@@ -23,7 +23,7 @@ class UpdateTest extends TestCase
*/
public
function
testConstructorUpdateArgumentTypeCheck
(
$update
)
{
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
)
,
$update
);
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
]
,
$update
);
}
/**
...
...
@@ -32,23 +32,23 @@ class UpdateTest extends TestCase
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
array
(
'y'
=>
1
)
,
$options
);
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
],
[
'y'
=>
1
]
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
()
;
$options
=
[]
;
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'multi'
=>
$value
)
;
$options
[][]
=
[
'multi'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'upsert'
=>
$value
)
;
$options
[][]
=
[
'upsert'
=>
$value
]
;
}
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
)
;
$options
[][]
=
[
'writeConcern'
=>
$value
]
;
}
return
$options
;
...
...
tests/PedantryTest.php
View file @
4043b265
...
...
@@ -56,7 +56,7 @@ class PedantryTest extends \PHPUnit_Framework_TestCase
public
function
provideProjectClassNames
()
{
$classNames
=
array
()
;
$classNames
=
[]
;
$srcDir
=
realpath
(
__DIR__
.
'/../src/'
);
$files
=
new
RegexIterator
(
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$srcDir
)),
'/\.php$/i'
);
...
...
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