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
362a27ff
Commit
362a27ff
authored
Apr 29, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-58: Functional tests for CRUD spec write methods
parent
89391d25
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
952 additions
and
0 deletions
+952
-0
DeleteManyFunctionalTest.php
tests/Collection/CrudSpec/DeleteManyFunctionalTest.php
+48
-0
DeleteOneFunctionalTest.php
tests/Collection/CrudSpec/DeleteOneFunctionalTest.php
+64
-0
FindOneAndDeleteFunctionalTest.php
tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php
+76
-0
FindOneAndReplaceFunctionalTest.php
...s/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php
+196
-0
FindOneAndUpdateFunctionalTest.php
tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php
+196
-0
InsertManyFunctionalTest.php
tests/Collection/CrudSpec/InsertManyFunctionalTest.php
+38
-0
InsertOneFunctionalTest.php
tests/Collection/CrudSpec/InsertOneFunctionalTest.php
+34
-0
ReplaceOneFunctionalTest.php
tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php
+114
-0
UpdateManyFunctionalTest.php
tests/Collection/CrudSpec/UpdateManyFunctionalTest.php
+93
-0
UpdateOneFunctionalTest.php
tests/Collection/CrudSpec/UpdateOneFunctionalTest.php
+93
-0
No files found.
tests/Collection/CrudSpec/DeleteManyFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for deleteMany().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
DeleteManyFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
public
function
testDeleteManyWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
));
$result
=
$this
->
collection
->
deleteMany
(
$filter
);
$this
->
assertSame
(
2
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testDeleteManyWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/DeleteOneFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for deleteOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
DeleteOneFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
public
function
testDeleteOneWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
));
$result
=
$this
->
collection
->
deleteOne
(
$filter
);
$this
->
assertSame
(
1
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testDeleteOneWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
2
);
$result
=
$this
->
collection
->
deleteOne
(
$filter
);
$this
->
assertSame
(
1
,
$result
->
getDeletedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testDeleteOneWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for findOneAndDelete().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
FindOneAndDeleteFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
public
function
testFindOneAndDeleteWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
));
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
),
'sort'
=>
array
(
'x'
=>
1
),
);
$document
=
$this
->
collection
->
findOneAndDelete
(
$filter
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testFindOneAndDeleteWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
2
);
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
),
'sort'
=>
array
(
'x'
=>
1
),
);
$document
=
$this
->
collection
->
findOneAndDelete
(
$filter
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testFindOneAndDeleteWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
);
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
),
'sort'
=>
array
(
'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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
use
MongoDB\Collection
;
/**
* CRUD spec functional tests for findOneAndReplace().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
FindOneAndReplaceFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
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
),
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
32
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
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
),
'returnDocument'
=>
Collection
::
FIND_ONE_AND_RETURN_AFTER
,
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
32
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
32
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
2
);
$replacement
=
array
(
'x'
=>
32
);
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
),
'sort'
=>
array
(
'x'
=>
1
),
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
32
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
2
);
$replacement
=
array
(
'x'
=>
32
);
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
),
'sort'
=>
array
(
'x'
=>
1
),
'returnDocument'
=>
Collection
::
FIND_ONE_AND_RETURN_AFTER
,
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
32
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
32
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
4
);
$replacement
=
array
(
'x'
=>
44
);
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
),
'sort'
=>
array
(
'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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification
()
{
$filter
=
array
(
'_id'
=>
4
);
$replacement
=
array
(
'x'
=>
44
);
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
),
'sort'
=>
array
(
'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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
4
);
$replacement
=
array
(
'x'
=>
44
);
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
),
'sort'
=>
array
(
'x'
=>
1
),
'returnDocument'
=>
Collection
::
FIND_ONE_AND_RETURN_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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification
()
{
$filter
=
array
(
'_id'
=>
4
);
$replacement
=
array
(
'x'
=>
44
);
$options
=
array
(
'projection'
=>
array
(
'x'
=>
1
,
'_id'
=>
0
),
'sort'
=>
array
(
'x'
=>
1
),
'returnDocument'
=>
Collection
::
FIND_ONE_AND_RETURN_AFTER
,
'upsert'
=>
true
,
);
$document
=
$this
->
collection
->
findOneAndReplace
(
$filter
,
$replacement
,
$options
);
$this
->
assertSame
(
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
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
use
MongoDB\Collection
;
/**
* CRUD spec functional tests for findOneAndUpdate().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
FindOneAndUpdateFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
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
),
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
23
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
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
),
'returnDocument'
=>
Collection
::
FIND_ONE_AND_RETURN_AFTER
,
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
23
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
23
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
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
),
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
22
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
23
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
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
),
'returnDocument'
=>
Collection
::
FIND_ONE_AND_RETURN_AFTER
,
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSame
(
array
(
'x'
=>
23
),
$document
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
23
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
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
),
);
$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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
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
),
'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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
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
),
'returnDocument'
=>
Collection
::
FIND_ONE_AND_RETURN_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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
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
),
'returnDocument'
=>
Collection
::
FIND_ONE_AND_RETURN_AFTER
,
'upsert'
=>
true
,
);
$document
=
$this
->
collection
->
findOneAndUpdate
(
$filter
,
$update
,
$options
);
$this
->
assertSame
(
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
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/InsertManyFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for insertMany().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
InsertManyFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
1
);
}
public
function
testInsertManyWithNonexistentDocuments
()
{
$documents
=
array
(
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$result
=
$this
->
collection
->
insertMany
(
$documents
);
$this
->
assertSame
(
2
,
$result
->
getInsertedCount
());
$this
->
assertSame
(
array
(
2
,
3
),
$result
->
getInsertedIds
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/InsertOneFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for insertOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
InsertOneFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
1
);
}
public
function
testInsertOneWithANonexistentDocument
()
{
$document
=
array
(
'_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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for replaceOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
ReplaceOneFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
public
function
testReplaceOneWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
));
$replacement
=
array
(
'x'
=>
111
);
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
111
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testReplaceOneWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
1
);
$replacement
=
array
(
'x'
=>
111
);
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
111
),
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testReplaceOneWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
);
$replacement
=
array
(
'x'
=>
111
);
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testReplaceOneWithUpsertWhenNoDocumentsMatchWithAnIdSpecified
()
{
$filter
=
array
(
'_id'
=>
4
);
$replacement
=
array
(
'_id'
=>
4
,
'x'
=>
1
);
$options
=
array
(
'upsert'
=>
true
);
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
,
$options
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testReplaceOneWithUpsertWhenNoDocumentsMatchWithoutAnIdSpecified
()
{
$filter
=
array
(
'_id'
=>
4
);
$replacement
=
array
(
'x'
=>
1
);
$options
=
array
(
'upsert'
=>
true
);
$result
=
$this
->
collection
->
replaceOne
(
$filter
,
$replacement
,
$options
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/UpdateManyFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for updateMany().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
UpdateManyFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
public
function
testUpdateManyWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
));
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
));
$result
=
$this
->
collection
->
updateMany
(
$filter
,
$update
);
$this
->
assertSame
(
2
,
$result
->
getMatchedCount
());
$this
->
assertSame
(
2
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
23
),
array
(
'_id'
=>
3
,
'x'
=>
34
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testUpdateManyWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
1
);
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
));
$result
=
$this
->
collection
->
updateMany
(
$filter
,
$update
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
12
),
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testUpdateManyWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
);
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
));
$result
=
$this
->
collection
->
updateMany
(
$filter
,
$update
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testUpdateManyWithUpsertWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
);
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
));
$options
=
array
(
'upsert'
=>
true
);
$result
=
$this
->
collection
->
updateMany
(
$filter
,
$update
,
$options
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/UpdateOneFunctionalTest.php
0 → 100644
View file @
362a27ff
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for updateOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
UpdateOneFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
public
function
testUpdateOneWhenManyDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
));
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
));
$result
=
$this
->
collection
->
updateOne
(
$filter
,
$update
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
23
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testUpdateOneWhenOneDocumentMatches
()
{
$filter
=
array
(
'_id'
=>
1
);
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
));
$result
=
$this
->
collection
->
updateOne
(
$filter
,
$update
);
$this
->
assertSame
(
1
,
$result
->
getMatchedCount
());
$this
->
assertSame
(
1
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
12
),
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testUpdateOneWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
);
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
));
$result
=
$this
->
collection
->
updateOne
(
$filter
,
$update
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$this
->
assertSame
(
0
,
$result
->
getModifiedCount
());
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
public
function
testUpdateOneWithUpsertWhenNoDocumentsMatch
()
{
$filter
=
array
(
'_id'
=>
4
);
$update
=
array
(
'$inc'
=>
array
(
'x'
=>
1
));
$options
=
array
(
'upsert'
=>
true
);
$result
=
$this
->
collection
->
updateOne
(
$filter
,
$update
,
$options
);
$this
->
assertSame
(
0
,
$result
->
getMatchedCount
());
$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
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
()
->
toArray
());
}
}
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