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
3e4d54b8
Commit
3e4d54b8
authored
Jun 19, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21
parents
60931d82
0437bb85
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
143 additions
and
87 deletions
+143
-87
Aggregate.php
src/Operation/Aggregate.php
+8
-7
Count.php
src/Operation/Count.php
+1
-0
CreateCollection.php
src/Operation/CreateCollection.php
+6
-2
CreateIndexes.php
src/Operation/CreateIndexes.php
+1
-0
Distinct.php
src/Operation/Distinct.php
+8
-4
DropCollection.php
src/Operation/DropCollection.php
+6
-2
DropDatabase.php
src/Operation/DropDatabase.php
+6
-2
DropIndexes.php
src/Operation/DropIndexes.php
+6
-2
FindAndModify.php
src/Operation/FindAndModify.php
+11
-7
BulkWriteFunctionalTest.php
tests/Collection/BulkWriteFunctionalTest.php
+4
-4
AggregateFunctionalTest.php
tests/Collection/CrudSpec/AggregateFunctionalTest.php
+2
-3
DeleteManyFunctionalTest.php
tests/Collection/CrudSpec/DeleteManyFunctionalTest.php
+2
-2
DeleteOneFunctionalTest.php
tests/Collection/CrudSpec/DeleteOneFunctionalTest.php
+3
-3
FindFunctionalTest.php
tests/Collection/CrudSpec/FindFunctionalTest.php
+3
-3
FindOneAndDeleteFunctionalTest.php
tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php
+5
-5
FindOneAndReplaceFunctionalTest.php
...s/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php
+13
-13
FindOneAndUpdateFunctionalTest.php
tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php
+13
-13
InsertManyFunctionalTest.php
tests/Collection/CrudSpec/InsertManyFunctionalTest.php
+1
-1
InsertOneFunctionalTest.php
tests/Collection/CrudSpec/InsertOneFunctionalTest.php
+1
-1
ReplaceOneFunctionalTest.php
tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php
+5
-5
UpdateManyFunctionalTest.php
tests/Collection/CrudSpec/UpdateManyFunctionalTest.php
+4
-4
UpdateOneFunctionalTest.php
tests/Collection/CrudSpec/UpdateOneFunctionalTest.php
+4
-4
FunctionalTestCase.php
tests/FunctionalTestCase.php
+30
-0
No files found.
src/Operation/Aggregate.php
View file @
3e4d54b8
...
...
@@ -122,20 +122,21 @@ class Aggregate implements Executable
return
$cursor
;
}
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
if
(
!
isset
(
$result
[
'result'
])
||
!
is_array
(
$result
[
'result'
]
))
{
if
(
!
isset
(
$result
->
result
)
||
!
is_array
(
$result
->
result
))
{
throw
new
UnexpectedValueException
(
'aggregate command did not return a "result" array'
);
}
return
new
ArrayIterator
(
array_map
(
function
(
stdClass
$document
)
{
return
(
array
)
$document
;
},
$result
[
'result'
]
));
return
new
ArrayIterator
(
$result
->
result
);
}
/**
...
...
src/Operation/Count.php
View file @
3e4d54b8
...
...
@@ -85,6 +85,7 @@ class Count implements Executable
public
function
execute
(
Server
$server
)
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
->
setTypeMap
(
array
(
'document'
=>
'array'
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
...
...
src/Operation/CreateCollection.php
View file @
3e4d54b8
...
...
@@ -106,10 +106,14 @@ class CreateCollection implements Executable
public
function
execute
(
Server
$server
)
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
return
$result
;
...
...
src/Operation/CreateIndexes.php
View file @
3e4d54b8
...
...
@@ -91,6 +91,7 @@ class CreateIndexes implements Executable
));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$command
);
$cursor
->
setTypeMap
(
array
(
'document'
=>
'array'
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
...
...
src/Operation/Distinct.php
View file @
3e4d54b8
...
...
@@ -62,17 +62,21 @@ class Distinct implements Executable
public
function
execute
(
Server
$server
)
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
if
(
!
isset
(
$result
[
'values'
])
||
!
is_array
(
$result
[
'values'
]
))
{
if
(
!
isset
(
$result
->
values
)
||
!
is_array
(
$result
->
values
))
{
throw
new
UnexpectedValueException
(
'distinct command did not return a "values" array'
);
}
return
$result
[
'values'
]
;
return
$result
->
values
;
}
/**
...
...
src/Operation/DropCollection.php
View file @
3e4d54b8
...
...
@@ -41,10 +41,14 @@ class DropCollection implements Executable
public
function
execute
(
Server
$server
)
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'drop'
=>
$this
->
collectionName
)));
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
return
$result
;
...
...
src/Operation/DropDatabase.php
View file @
3e4d54b8
...
...
@@ -39,10 +39,14 @@ class DropDatabase implements Executable
public
function
execute
(
Server
$server
)
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'dropDatabase'
=>
1
)));
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
return
$result
;
...
...
src/Operation/DropIndexes.php
View file @
3e4d54b8
...
...
@@ -56,10 +56,14 @@ class DropIndexes implements Executable
);
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
$cmd
));
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
return
$result
;
...
...
src/Operation/FindAndModify.php
View file @
3e4d54b8
...
...
@@ -118,13 +118,17 @@ class FindAndModify implements Executable
public
function
execute
(
Server
$server
)
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
if
(
!
isset
(
$result
[
'value'
]
))
{
if
(
!
isset
(
$result
->
value
))
{
return
null
;
}
...
...
@@ -133,17 +137,17 @@ class FindAndModify implements Executable
* requested.
*/
if
(
$this
->
options
[
'upsert'
]
&&
!
$this
->
options
[
'new'
]
&&
isset
(
$result
[
'lastErrorObject'
]
->
updatedExisting
)
&&
!
$result
[
'lastErrorObject'
]
->
updatedExisting
)
{
isset
(
$result
->
lastErrorObject
->
updatedExisting
)
&&
!
$result
->
lastErrorObject
->
updatedExisting
)
{
return
null
;
}
if
(
!
is_object
(
$result
[
'value'
]
))
{
if
(
!
is_object
(
$result
->
value
))
{
throw
new
UnexpectedValueException
(
'findAndModify command did not return a "value" document'
);
}
return
$result
[
'value'
]
;
return
$result
->
value
;
}
/**
...
...
tests/Collection/BulkWriteFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -35,7 +35,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
$insertedIds
[
1
],
'x'
=>
22
),
);
$this
->
assert
Equals
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assert
SameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdates
()
...
...
@@ -69,7 +69,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
$upsertedIds
[
3
],
'x'
=>
67
),
);
$this
->
assert
Equals
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assert
SameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testDeletes
()
...
...
@@ -89,7 +89,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
2
,
'x'
=>
22
),
);
$this
->
assert
Equals
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assert
SameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testMixedOrderedOperations
()
...
...
@@ -123,7 +123,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
44
),
);
$this
->
assert
Equals
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assert
SameDocuments
(
$expected
,
$this
->
collection
->
find
());
}
/**
...
...
tests/Collection/CrudSpec/AggregateFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -36,8 +36,7 @@ class AggregateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
// Use iterator_to_array() here since aggregate() may return an ArrayIterator
$this
->
assertEquals
(
$expected
,
iterator_to_array
(
$cursor
));
$this
->
assertSameDocuments
(
$expected
,
$cursor
);
}
public
function
testAggregateWithOut
()
...
...
@@ -64,7 +63,7 @@ class AggregateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assert
Equals
(
$expected
,
$outputCollection
->
find
()
->
toArray
());
$this
->
assert
SameDocuments
(
$expected
,
$outputCollection
->
find
());
// Manually clean up our output collection
$this
->
dropCollectionIfItExists
(
$outputCollection
);
...
...
tests/Collection/CrudSpec/DeleteManyFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -27,7 +27,7 @@ class DeleteManyFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
1
,
'x'
=>
11
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testDeleteManyWhenNoDocumentsMatch
()
...
...
@@ -43,6 +43,6 @@ class DeleteManyFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/Collection/CrudSpec/DeleteOneFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -28,7 +28,7 @@ class DeleteOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testDeleteOneWhenOneDocumentMatches
()
...
...
@@ -43,7 +43,7 @@ class DeleteOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testDeleteOneWhenNoDocumentsMatch
()
...
...
@@ -59,6 +59,6 @@ class DeleteOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/Collection/CrudSpec/FindFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -24,7 +24,7 @@ class FindFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
1
,
'x'
=>
11
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
(
$filter
)
->
toArray
(
));
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
(
$filter
));
}
public
function
testFindWithFilterSortSkipAndLimit
()
...
...
@@ -40,7 +40,7 @@ class FindFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
5
,
'x'
=>
55
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
(
$filter
,
$options
)
->
toArray
(
));
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
(
$filter
,
$options
));
}
public
function
testFindWithLimitSortAndBatchSize
()
...
...
@@ -59,6 +59,6 @@ class FindFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
44
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
(
$filter
,
$options
)
->
toArray
(
));
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
(
$filter
,
$options
));
}
}
tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -25,14 +25,14 @@ class FindOneAndDeleteFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndDelete
(
$filter
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
22
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndDeleteWhenOneDocumentMatches
()
...
...
@@ -44,14 +44,14 @@ class FindOneAndDeleteFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndDelete
(
$filter
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
22
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndDeleteWhenNoDocumentsMatch
()
...
...
@@ -71,6 +71,6 @@ class FindOneAndDeleteFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -29,7 +29,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
22
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -37,7 +37,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentAfterModification
()
...
...
@@ -51,7 +51,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
32
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
32
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -59,7 +59,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentBeforeModification
()
...
...
@@ -72,7 +72,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
22
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -80,7 +80,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentAfterModification
()
...
...
@@ -94,7 +94,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
32
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
32
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -102,7 +102,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentBeforeModification
()
...
...
@@ -123,7 +123,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification
()
...
...
@@ -147,7 +147,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
44
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentAfterModification
()
...
...
@@ -169,7 +169,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification
()
...
...
@@ -185,7 +185,7 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
44
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
44
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -194,6 +194,6 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
44
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -29,7 +29,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
22
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -37,7 +37,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentAfterModification
()
...
...
@@ -51,7 +51,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
23
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
23
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -59,7 +59,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentBeforeModification
()
...
...
@@ -72,7 +72,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
22
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -80,7 +80,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentAfterModification
()
...
...
@@ -94,7 +94,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
23
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
23
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -102,7 +102,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentBeforeModification
()
...
...
@@ -123,7 +123,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification
()
...
...
@@ -146,7 +146,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
1
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentAfterModification
()
...
...
@@ -168,7 +168,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification
()
...
...
@@ -183,7 +183,7 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assert
Equals
((
object
)
array
(
'x'
=>
1
),
$document
);
$this
->
assert
SameDocument
(
array
(
'x'
=>
1
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
...
...
@@ -192,6 +192,6 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
1
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/Collection/CrudSpec/InsertManyFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -33,6 +33,6 @@ class InsertManyFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/Collection/CrudSpec/InsertOneFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -29,6 +29,6 @@ class InsertOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
2
,
'x'
=>
22
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -35,7 +35,7 @@ class ReplaceOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testReplaceOneWhenOneDocumentMatches
()
...
...
@@ -53,7 +53,7 @@ class ReplaceOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testReplaceOneWhenNoDocumentsMatch
()
...
...
@@ -71,7 +71,7 @@ class ReplaceOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testReplaceOneWithUpsertWhenNoDocumentsMatchWithAnIdSpecified
()
...
...
@@ -92,7 +92,7 @@ class ReplaceOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
1
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testReplaceOneWithUpsertWhenNoDocumentsMatchWithoutAnIdSpecified
()
...
...
@@ -114,6 +114,6 @@ class ReplaceOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
1
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/Collection/CrudSpec/UpdateManyFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -35,7 +35,7 @@ class UpdateManyFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
34
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateManyWhenOneDocumentMatches
()
...
...
@@ -53,7 +53,7 @@ class UpdateManyFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateManyWhenNoDocumentsMatch
()
...
...
@@ -71,7 +71,7 @@ class UpdateManyFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateManyWithUpsertWhenNoDocumentsMatch
()
...
...
@@ -92,6 +92,6 @@ class UpdateManyFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
1
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/Collection/CrudSpec/UpdateOneFunctionalTest.php
View file @
3e4d54b8
...
...
@@ -35,7 +35,7 @@ class UpdateOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateOneWhenOneDocumentMatches
()
...
...
@@ -53,7 +53,7 @@ class UpdateOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateOneWhenNoDocumentsMatch
()
...
...
@@ -71,7 +71,7 @@ class UpdateOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
public
function
testUpdateOneWithUpsertWhenNoDocumentsMatch
()
...
...
@@ -92,6 +92,6 @@ class UpdateOneFunctionalTest extends FunctionalTestCase
array
(
'_id'
=>
4
,
'x'
=>
1
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
$this
->
assertSame
Documents
(
$expected
,
$this
->
collection
->
find
());
}
}
tests/FunctionalTestCase.php
View file @
3e4d54b8
...
...
@@ -6,6 +6,8 @@ use MongoDB\Driver\Command;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\ReadPreference
;
use
stdClass
;
use
Traversable
;
abstract
class
FunctionalTestCase
extends
TestCase
{
...
...
@@ -38,6 +40,34 @@ abstract class FunctionalTestCase extends TestCase
$this
->
assertEquals
(
1
,
$document
[
'ok'
]);
}
protected
function
assertSameDocument
(
$expectedDocument
,
$actualDocument
)
{
$this
->
assertEquals
(
(
$expectedDocument
instanceof
stdClass
)
?
(
array
)
$expectedDocument
:
$expectedDocument
,
(
$actualDocument
instanceof
stdClass
)
?
(
array
)
$actualDocument
:
$actualDocument
);
}
protected
function
assertSameDocuments
(
array
$expectedDocuments
,
$actualDocuments
)
{
if
(
$actualDocuments
instanceof
Traversable
)
{
$actualDocuments
=
iterator_to_array
(
$actualDocuments
);
}
if
(
!
is_array
(
$actualDocuments
))
{
throw
new
InvalidArgumentException
(
'$actualDocuments is not an array or Traversable'
);
}
$normalizeRootDocuments
=
function
(
$document
)
{
return
(
$document
instanceof
stdClass
)
?
(
array
)
$document
:
$document
;
};
$this
->
assertEquals
(
array_map
(
$normalizeRootDocuments
,
$expectedDocuments
),
array_map
(
$normalizeRootDocuments
,
$actualDocuments
)
);
}
protected
function
getServerVersion
(
ReadPreference
$readPreference
=
null
)
{
$cursor
=
$this
->
manager
->
executeCommand
(
...
...
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