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
f2c10219
Commit
f2c10219
authored
Sep 03, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #28
parents
694c2117
424fc2cb
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
495 additions
and
132 deletions
+495
-132
.travis.yml
.travis.yml
+1
-0
Collection.php
src/Collection.php
+12
-12
Aggregate.php
src/Operation/Aggregate.php
+18
-14
Count.php
src/Operation/Count.php
+5
-1
Distinct.php
src/Operation/Distinct.php
+5
-1
AggregateTest.php
tests/Operation/AggregateTest.php
+72
-0
BulkWriteTest.php
tests/Operation/BulkWriteTest.php
+65
-36
CountTest.php
tests/Operation/CountTest.php
+54
-0
DeleteTest.php
tests/Operation/DeleteTest.php
+25
-7
DistinctTest.php
tests/Operation/DistinctTest.php
+37
-0
FindTest.php
tests/Operation/FindTest.php
+92
-0
InsertManyTest.php
tests/Operation/InsertManyTest.php
+20
-10
InsertOneTest.php
tests/Operation/InsertOneTest.php
+16
-4
ReplaceOneTest.php
tests/Operation/ReplaceOneTest.php
+5
-4
TestCase.php
tests/Operation/TestCase.php
+34
-15
UpdateManyTest.php
tests/Operation/UpdateManyTest.php
+5
-4
UpdateOneTest.php
tests/Operation/UpdateOneTest.php
+5
-4
UpdateTest.php
tests/Operation/UpdateTest.php
+24
-20
No files found.
.travis.yml
View file @
f2c10219
...
@@ -28,6 +28,7 @@ install:
...
@@ -28,6 +28,7 @@ install:
-
sudo apt-get -y install gdb
-
sudo apt-get -y install gdb
before_script
:
before_script
:
-
phpenv config-rm xdebug.ini
-
if dpkg --compare-versions ${SERVER_VERSION} le "2.4"; then export SERVER_SERVICE=mongodb; else export SERVER_SERVICE=mongod; fi
-
if dpkg --compare-versions ${SERVER_VERSION} le "2.4"; then export SERVER_SERVICE=mongodb; else export SERVER_SERVICE=mongod; fi
-
if ! nc -z localhost 27017; then sudo service ${SERVER_SERVICE} start; fi
-
if ! nc -z localhost 27017; then sudo service ${SERVER_SERVICE} start; fi
-
mongod --version
-
mongod --version
...
...
src/Collection.php
View file @
f2c10219
...
@@ -124,11 +124,11 @@ class Collection
...
@@ -124,11 +124,11 @@ class Collection
* Gets the number of documents matching the filter.
* Gets the number of documents matching the filter.
*
*
* @see Count::__construct() for supported options
* @see Count::__construct() for supported options
* @param array $filter Query by which to filter documents
* @param array
|object
$filter Query by which to filter documents
* @param array $options Command options
* @param array
$options Command options
* @return integer
* @return integer
*/
*/
public
function
count
(
array
$filter
=
array
(),
array
$options
=
array
())
public
function
count
(
$filter
=
array
(),
array
$options
=
array
())
{
{
$operation
=
new
Count
(
$this
->
dbname
,
$this
->
collname
,
$filter
,
$options
);
$operation
=
new
Count
(
$this
->
dbname
,
$this
->
collname
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
@@ -228,11 +228,11 @@ class Collection
...
@@ -228,11 +228,11 @@ class Collection
*
*
* @see Distinct::__construct() for supported options
* @see Distinct::__construct() for supported options
* @param string $fieldName Field for which to return distinct values
* @param string $fieldName Field for which to return distinct values
* @param array
$filter
Query by which to filter documents
* @param array
|object $filter
Query by which to filter documents
* @param array
$options
Command options
* @param array
$options
Command options
* @return mixed[]
* @return mixed[]
*/
*/
public
function
distinct
(
$fieldName
,
array
$filter
=
array
(),
array
$options
=
array
())
public
function
distinct
(
$fieldName
,
$filter
=
array
(),
array
$options
=
array
())
{
{
$operation
=
new
Distinct
(
$this
->
dbname
,
$this
->
collname
,
$fieldName
,
$filter
,
$options
);
$operation
=
new
Distinct
(
$this
->
dbname
,
$this
->
collname
,
$fieldName
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
@@ -292,11 +292,11 @@ class Collection
...
@@ -292,11 +292,11 @@ class Collection
*
*
* @see Find::__construct() for supported options
* @see Find::__construct() for supported options
* @see http://docs.mongodb.org/manual/core/read-operations-introduction/
* @see http://docs.mongodb.org/manual/core/read-operations-introduction/
* @param array $filter Query by which to filter documents
* @param array
|object
$filter Query by which to filter documents
* @param array $options Additional options
* @param array
$options Additional options
* @return Cursor
* @return Cursor
*/
*/
public
function
find
(
array
$filter
=
array
(),
array
$options
=
array
())
public
function
find
(
$filter
=
array
(),
array
$options
=
array
())
{
{
$operation
=
new
Find
(
$this
->
dbname
,
$this
->
collname
,
$filter
,
$options
);
$operation
=
new
Find
(
$this
->
dbname
,
$this
->
collname
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
@@ -309,11 +309,11 @@ class Collection
...
@@ -309,11 +309,11 @@ class Collection
*
*
* @see FindOne::__construct() for supported options
* @see FindOne::__construct() for supported options
* @see http://docs.mongodb.org/manual/core/read-operations-introduction/
* @see http://docs.mongodb.org/manual/core/read-operations-introduction/
* @param array
$filter The find query to execute
* @param array
|object $filter Query by which to filter documents
* @param array
$options
Additional options
* @param array
$options
Additional options
* @return object|null
* @return object|null
*/
*/
public
function
findOne
(
array
$filter
=
array
(),
array
$options
=
array
())
public
function
findOne
(
$filter
=
array
(),
array
$options
=
array
())
{
{
$operation
=
new
FindOne
(
$this
->
dbname
,
$this
->
collname
,
$filter
,
$options
);
$operation
=
new
FindOne
(
$this
->
dbname
,
$this
->
collname
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
...
...
src/Operation/Aggregate.php
View file @
f2c10219
...
@@ -59,6 +59,24 @@ class Aggregate implements Executable
...
@@ -59,6 +59,24 @@ class Aggregate implements Executable
*/
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$pipeline
,
array
$options
=
array
())
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$pipeline
,
array
$options
=
array
())
{
{
if
(
empty
(
$pipeline
))
{
throw
new
InvalidArgumentException
(
'$pipeline is empty'
);
}
$expectedIndex
=
0
;
foreach
(
$pipeline
as
$i
=>
$operation
)
{
if
(
$i
!==
$expectedIndex
)
{
throw
new
InvalidArgumentException
(
sprintf
(
'$pipeline is not a list (unexpected index: "%s")'
,
$i
));
}
if
(
!
is_array
(
$operation
)
&&
!
is_object
(
$operation
))
{
throw
new
InvalidArgumentTypeException
(
sprintf
(
'$pipeline[%d]'
,
$i
),
$operation
,
'array or object'
);
}
$expectedIndex
+=
1
;
}
$options
+=
array
(
$options
+=
array
(
'allowDiskUse'
=>
false
,
'allowDiskUse'
=>
false
,
'useCursor'
=>
true
,
'useCursor'
=>
true
,
...
@@ -84,20 +102,6 @@ class Aggregate implements Executable
...
@@ -84,20 +102,6 @@ class Aggregate implements Executable
throw
new
InvalidArgumentException
(
'"batchSize" option should not be used if "useCursor" is false'
);
throw
new
InvalidArgumentException
(
'"batchSize" option should not be used if "useCursor" is false'
);
}
}
$expectedIndex
=
0
;
foreach
(
$pipeline
as
$i
=>
$op
)
{
if
(
$i
!==
$expectedIndex
)
{
throw
new
InvalidArgumentException
(
sprintf
(
'$pipeline is not a list (unexpected index: "%s")'
,
$i
));
}
if
(
!
is_array
(
$op
)
&&
!
is_object
(
$op
))
{
throw
new
InvalidArgumentTypeException
(
sprintf
(
'$pipeline[%d]'
,
$i
),
$op
,
'array or object'
);
}
$expectedIndex
+=
1
;
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
pipeline
=
$pipeline
;
$this
->
pipeline
=
$pipeline
;
...
...
src/Operation/Count.php
View file @
f2c10219
...
@@ -45,8 +45,12 @@ class Count implements Executable
...
@@ -45,8 +45,12 @@ class Count implements Executable
* @param array $options Command options
* @param array $options Command options
* @throws InvalidArgumentException
* @throws InvalidArgumentException
*/
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$filter
=
array
(),
array
$options
=
array
())
public
function
__construct
(
$databaseName
,
$collectionName
,
$filter
=
array
(),
array
$options
=
array
())
{
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
}
if
(
isset
(
$options
[
'hint'
]))
{
if
(
isset
(
$options
[
'hint'
]))
{
if
(
is_array
(
$options
[
'hint'
])
||
is_object
(
$options
[
'hint'
]))
{
if
(
is_array
(
$options
[
'hint'
])
||
is_object
(
$options
[
'hint'
]))
{
$options
[
'hint'
]
=
\MongoDB\generate_index_name
(
$options
[
'hint'
]);
$options
[
'hint'
]
=
\MongoDB\generate_index_name
(
$options
[
'hint'
]);
...
...
src/Operation/Distinct.php
View file @
f2c10219
...
@@ -39,8 +39,12 @@ class Distinct implements Executable
...
@@ -39,8 +39,12 @@ class Distinct implements Executable
* @param array $options Command options
* @param array $options Command options
* @throws InvalidArgumentException
* @throws InvalidArgumentException
*/
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
$fieldName
,
array
$filter
=
array
(),
array
$options
=
array
())
public
function
__construct
(
$databaseName
,
$collectionName
,
$fieldName
,
$filter
=
array
(),
array
$options
=
array
())
{
{
if
(
!
is_array
(
$filter
)
&&
!
is_object
(
$filter
))
{
throw
new
InvalidArgumentTypeException
(
'$filter'
,
$filter
,
'array or object'
);
}
if
(
isset
(
$options
[
'maxTimeMS'
])
&&
!
is_integer
(
$options
[
'maxTimeMS'
]))
{
if
(
isset
(
$options
[
'maxTimeMS'
])
&&
!
is_integer
(
$options
[
'maxTimeMS'
]))
{
throw
new
InvalidArgumentTypeException
(
'"maxTimeMS" option'
,
$options
[
'maxTimeMS'
],
'integer'
);
throw
new
InvalidArgumentTypeException
(
'"maxTimeMS" option'
,
$options
[
'maxTimeMS'
],
'integer'
);
}
}
...
...
tests/Operation/AggregateTest.php
0 → 100644
View file @
f2c10219
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\Aggregate
;
class
AggregateTest
extends
TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $pipeline is empty
*/
public
function
testConstructorPipelineArgumentMustNotBeEmpty
()
{
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
());
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $pipeline is not a list (unexpected index: "1")
*/
public
function
testConstructorPipelineArgumentMustBeAList
()
{
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
1
=>
array
(
'$match'
=>
array
(
'x'
=>
1
))));
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidConstructorOptions
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
'$match'
=>
array
(
'x'
=>
1
))),
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
();
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'allowDiskUse'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'batchSize'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'maxTimeMS'
=>
$value
);
}
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'useCursor'
=>
$value
);
}
return
$options
;
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage "batchSize" option should not be used if "useCursor" is false
*/
public
function
testConstructorBatchSizeOptionRequiresUseCursor
()
{
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
'$match'
=>
array
(
'x'
=>
1
))),
array
(
'batchSize'
=>
100
,
'useCursor'
=>
false
)
);
}
}
tests/Operation/BulkWriteTest.php
View file @
f2c10219
...
@@ -64,10 +64,10 @@ class BulkWriteTest extends TestCase
...
@@ -64,10 +64,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["insertOne"\]\[0\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["insertOne"\]\[0\] to have type "
array or object
" but found "[\w ]+"/
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testInsertOneDocumentArgumentType
(
$document
)
public
function
testInsertOneDocumentArgumentType
Check
(
$document
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
INSERT_ONE
=>
array
(
$document
)),
array
(
BulkWrite
::
INSERT_ONE
=>
array
(
$document
)),
...
@@ -87,10 +87,10 @@ class BulkWriteTest extends TestCase
...
@@ -87,10 +87,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteMany"\]\[0\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteMany"\]\[0\] to have type "
array or object
" but found "[\w ]+"/
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testDeleteManyFilterArgumentType
(
$document
)
public
function
testDeleteManyFilterArgumentType
Check
(
$document
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
DELETE_MANY
=>
array
(
$document
)),
array
(
BulkWrite
::
DELETE_MANY
=>
array
(
$document
)),
...
@@ -110,10 +110,10 @@ class BulkWriteTest extends TestCase
...
@@ -110,10 +110,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteOne"\]\[0\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteOne"\]\[0\] to have type "
array or object
" but found "[\w ]+"/
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testDeleteOneFilterArgumentType
(
$document
)
public
function
testDeleteOneFilterArgumentType
Check
(
$document
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
DELETE_ONE
=>
array
(
$document
)),
array
(
BulkWrite
::
DELETE_ONE
=>
array
(
$document
)),
...
@@ -133,10 +133,10 @@ class BulkWriteTest extends TestCase
...
@@ -133,10 +133,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[0\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[0\] to have type "
array or object
" but found "[\w ]+"/
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testReplaceOneFilterArgumentType
(
$filter
)
public
function
testReplaceOneFilterArgumentType
Check
(
$filter
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
$filter
,
array
(
'y'
=>
1
))),
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
$filter
,
array
(
'y'
=>
1
))),
...
@@ -156,10 +156,10 @@ class BulkWriteTest extends TestCase
...
@@ -156,10 +156,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[1\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[1\] to have type "
array or object
" but found "[\w ]+"/
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testReplaceOneReplacementArgumentType
(
$replacement
)
public
function
testReplaceOneReplacementArgumentType
Check
(
$replacement
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
array
(
'x'
=>
1
),
$replacement
)),
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
array
(
'x'
=>
1
),
$replacement
)),
...
@@ -179,10 +179,10 @@ class BulkWriteTest extends TestCase
...
@@ -179,10 +179,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[2\]\["upsert"\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[2\]\["upsert"\] to have type "
boolean
" but found "[\w ]+"/
* @dataProvider provideInvalidBoolean
Argument
s
* @dataProvider provideInvalidBoolean
Value
s
*/
*/
public
function
testReplaceOneUpsertOptionType
(
$upsert
)
public
function
testReplaceOneUpsertOptionType
Check
(
$upsert
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
array
(
'x'
=>
1
),
array
(
'y'
=>
1
),
array
(
'upsert'
=>
$upsert
))),
array
(
BulkWrite
::
REPLACE_ONE
=>
array
(
array
(
'x'
=>
1
),
array
(
'y'
=>
1
),
array
(
'upsert'
=>
$upsert
))),
...
@@ -202,10 +202,10 @@ class BulkWriteTest extends TestCase
...
@@ -202,10 +202,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[0\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[0\] to have type "
array or object
" but found "[\w ]+"/
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testUpdateManyFilterArgumentType
(
$filter
)
public
function
testUpdateManyFilterArgumentType
Check
(
$filter
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)))),
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)))),
...
@@ -225,10 +225,10 @@ class BulkWriteTest extends TestCase
...
@@ -225,10 +225,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[1\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[1\] to have type "
array or object
" but found "[\w ]+"/
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testUpdateManyUpdateArgumentType
(
$update
)
public
function
testUpdateManyUpdateArgumentType
Check
(
$update
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
array
(
'x'
=>
1
),
$update
)),
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
array
(
'x'
=>
1
),
$update
)),
...
@@ -248,10 +248,10 @@ class BulkWriteTest extends TestCase
...
@@ -248,10 +248,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[2\]\["upsert"\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[2\]\["upsert"\] to have type "
boolean
" but found "[\w ]+"/
* @dataProvider provideInvalidBoolean
Argument
s
* @dataProvider provideInvalidBoolean
Value
s
*/
*/
public
function
testUpdateManyUpsertOptionType
(
$upsert
)
public
function
testUpdateManyUpsertOptionType
Check
(
$upsert
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
array
(
'x'
=>
1
),
array
(
'$set'
=>
array
(
'x'
=>
1
)),
array
(
'upsert'
=>
$upsert
))),
array
(
BulkWrite
::
UPDATE_MANY
=>
array
(
array
(
'x'
=>
1
),
array
(
'$set'
=>
array
(
'x'
=>
1
)),
array
(
'upsert'
=>
$upsert
))),
...
@@ -271,10 +271,10 @@ class BulkWriteTest extends TestCase
...
@@ -271,10 +271,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[0\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[0\] to have type "
array or object
" but found "[\w ]+"/
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testUpdateOneFilterArgumentType
(
$filter
)
public
function
testUpdateOneFilterArgumentType
Check
(
$filter
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)))),
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)))),
...
@@ -294,10 +294,10 @@ class BulkWriteTest extends TestCase
...
@@ -294,10 +294,10 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[1\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[1\] to have type "
array or object
" but found "[\w ]+"/
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testUpdateOneUpdateArgumentType
(
$update
)
public
function
testUpdateOneUpdateArgumentType
Check
(
$update
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
array
(
'x'
=>
1
),
$update
)),
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
array
(
'x'
=>
1
),
$update
)),
...
@@ -317,13 +317,42 @@ class BulkWriteTest extends TestCase
...
@@ -317,13 +317,42 @@ class BulkWriteTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[2\]\["upsert"\] to have type "
[\w ]+
" but found "[\w ]+"/
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[2\]\["upsert"\] to have type "
boolean
" but found "[\w ]+"/
* @dataProvider provideInvalidBoolean
Argument
s
* @dataProvider provideInvalidBoolean
Value
s
*/
*/
public
function
testUpdateOneUpsertOptionType
(
$upsert
)
public
function
testUpdateOneUpsertOptionType
Check
(
$upsert
)
{
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
array
(
'x'
=>
1
),
array
(
'$set'
=>
array
(
'x'
=>
1
)),
array
(
'upsert'
=>
$upsert
))),
array
(
BulkWrite
::
UPDATE_ONE
=>
array
(
array
(
'x'
=>
1
),
array
(
'$set'
=>
array
(
'x'
=>
1
)),
array
(
'upsert'
=>
$upsert
))),
));
));
}
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidConstructorOptions
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
BulkWrite
::
INSERT_ONE
=>
array
(
array
(
'x'
=>
1
)))),
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
();
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'ordered'
=>
$value
);
}
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
);
}
return
$options
;
}
}
}
tests/Operation/CountTest.php
0 → 100644
View file @
f2c10219
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\Count
;
class
CountTest
extends
TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentValues
*/
public
function
testConstructorFilterArgumentTypeCheck
(
$filter
)
{
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidConstructorOptions
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(),
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
();
foreach
(
$this
->
getInvalidHintValues
()
as
$value
)
{
$options
[][]
=
array
(
'hint'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'limit'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'maxTimeMS'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'skip'
=>
$value
);
}
return
$options
;
}
private
function
getInvalidHintValues
()
{
return
array
(
123
,
3.14
,
true
);
}
}
tests/Operation/DeleteTest.php
View file @
f2c10219
...
@@ -8,27 +8,45 @@ class DeleteTest extends TestCase
...
@@ -8,27 +8,45 @@ class DeleteTest extends TestCase
{
{
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testConstructorFilterArgumentType
(
$filter
)
public
function
testConstructorFilterArgumentType
Check
(
$filter
)
{
{
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
0
);
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
0
);
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentArguments
* @expectedExceptionMessage $limit must be 0 or 1
* @dataProvider provideInvalidLimitValues
*/
*/
public
function
testConstructorLimitArgumentMustBeOneOrZero
()
public
function
testConstructorLimitArgumentMustBeOneOrZero
(
$limit
)
{
{
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(),
2
);
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(),
$limit
);
}
public
function
provideInvalidLimitValues
()
{
return
$this
->
wrapValuesForDataProvider
(
array_merge
(
$this
->
getInvalidIntegerValues
(),
array
(
-
1
,
2
)));
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidConstructorOptions
*/
*/
public
function
testConstructorWriteConcernOptionType
()
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(),
1
,
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
{
new
Delete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(),
1
,
array
(
'writeConcern'
=>
null
));
$options
=
array
();
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
);
}
return
$options
;
}
}
}
}
tests/Operation/DistinctTest.php
0 → 100644
View file @
f2c10219
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\Distinct
;
class
DistinctTest
extends
TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentValues
*/
public
function
testConstructorFilterArgumentTypeCheck
(
$filter
)
{
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
$filter
);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidConstructorOptions
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
array
(),
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
();
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'maxTimeMS'
=>
$value
);
}
return
$options
;
}
}
tests/Operation/FindTest.php
0 → 100644
View file @
f2c10219
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\Find
;
use
stdClass
;
class
FindTest
extends
TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentValues
*/
public
function
testConstructorFilterArgumentTypeCheck
(
$filter
)
{
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidConstructorOptions
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(),
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
();
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'allowPartialResults'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'batchSize'
=>
$value
);
}
foreach
(
$this
->
getInvalidStringValues
()
as
$value
)
{
$options
[][]
=
array
(
'comment'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'cursorType'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'limit'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'maxTimeMS'
=>
$value
);
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
array
(
'modifiers'
=>
$value
);
}
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'oplogReplay'
=>
$value
);
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
array
(
'projection'
=>
$value
);
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
array
(
'skip'
=>
$value
);
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
array
(
'sort'
=>
$value
);
}
return
$options
;
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorCursorTypeOptions
*/
public
function
testConstructorCursorTypeOption
(
$cursorType
)
{
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(),
array
(
'cursorType'
=>
$cursorType
));
}
public
function
provideInvalidConstructorCursorTypeOptions
()
{
return
$this
->
wrapValuesForDataProvider
(
array
(
-
1
,
0
,
4
));
}
}
tests/Operation/InsertManyTest.php
View file @
f2c10219
...
@@ -8,6 +8,7 @@ class InsertManyTest extends TestCase
...
@@ -8,6 +8,7 @@ class InsertManyTest extends TestCase
{
{
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $documents is empty
*/
*/
public
function
testConstructorDocumentsMustNotBeEmpty
()
public
function
testConstructorDocumentsMustNotBeEmpty
()
{
{
...
@@ -16,6 +17,7 @@ class InsertManyTest extends TestCase
...
@@ -16,6 +17,7 @@ class InsertManyTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $documents is not a list (unexpected index: "1")
*/
*/
public
function
testConstructorDocumentsMustBeAList
()
public
function
testConstructorDocumentsMustBeAList
()
{
{
...
@@ -24,27 +26,35 @@ class InsertManyTest extends TestCase
...
@@ -24,27 +26,35 @@ class InsertManyTest extends TestCase
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments
* @expectedExceptionMessageRegExp /Expected \$documents\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
*/
public
function
testConstructorDocuments
ElementType
(
$document
)
public
function
testConstructorDocuments
ArgumentElementTypeChecks
(
$document
)
{
{
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
$document
));
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
$document
));
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalid
BooleanArgument
s
* @dataProvider provideInvalid
ConstructorOption
s
*/
*/
public
function
testConstructorO
rderedOptionType
(
$ordered
)
public
function
testConstructorO
ptionTypeChecks
(
array
$options
)
{
{
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
'x'
=>
1
)),
array
(
'ordered'
=>
$ordered
)
);
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
'x'
=>
1
)),
$options
);
}
}
/**
public
function
provideInvalidConstructorOptions
()
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
*/
public
function
testConstructorWriteConcernOptionType
()
{
{
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
array
(
'x'
=>
1
)),
array
(
'writeConcern'
=>
null
));
$options
=
array
();
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
array
(
'ordered'
=>
$value
);
}
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
);
}
return
$options
;
}
}
}
}
tests/Operation/InsertOneTest.php
View file @
f2c10219
...
@@ -8,18 +8,30 @@ class InsertOneTest extends TestCase
...
@@ -8,18 +8,30 @@ class InsertOneTest extends TestCase
{
{
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testConstructorDocumentArgumentType
(
$document
)
public
function
testConstructorDocumentArgumentType
Check
(
$document
)
{
{
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$document
);
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$document
);
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidConstructorOptions
*/
*/
public
function
testConstructor
WriteConcernOptionType
(
)
public
function
testConstructor
OptionTypeChecks
(
array
$options
)
{
{
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
array
(
'writeConcern'
=>
null
));
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
$options
);
}
public
function
provideInvalidConstructorOptions
()
{
$options
=
array
();
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
);
}
return
$options
;
}
}
}
}
tests/Operation/ReplaceOneTest.php
View file @
f2c10219
...
@@ -8,24 +8,25 @@ class ReplaceOneTest extends TestCase
...
@@ -8,24 +8,25 @@ class ReplaceOneTest extends TestCase
{
{
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testConstructorFilterArgumentType
(
$filter
)
public
function
testConstructorFilterArgumentType
Check
(
$filter
)
{
{
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'y'
=>
1
));
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'y'
=>
1
));
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testConstructorReplacementArgumentType
(
$replacement
)
public
function
testConstructorReplacementArgumentType
Check
(
$replacement
)
{
{
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
$replacement
);
new
ReplaceOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
$replacement
);
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $replacement argument is an update operator
*/
*/
public
function
testConstructorReplacementArgumentRequiresNoOperators
()
public
function
testConstructorReplacementArgumentRequiresNoOperators
()
{
{
...
...
tests/Operation/TestCase.php
View file @
f2c10219
...
@@ -10,24 +10,43 @@ use stdClass;
...
@@ -10,24 +10,43 @@ use stdClass;
*/
*/
abstract
class
TestCase
extends
BaseTestCase
abstract
class
TestCase
extends
BaseTestCase
{
{
public
function
provideInvalidDocument
Argument
s
()
public
function
provideInvalidDocument
Value
s
()
{
{
return
array
(
return
$this
->
wrapValuesForDataProvider
(
$this
->
getInvalidDocumentValues
());
array
(
null
),
array
(
123
),
array
(
'foo'
),
array
(
true
),
);
}
}
public
function
provideInvalidBoolean
Argument
s
()
public
function
provideInvalidBoolean
Value
s
()
{
{
return
array
(
return
$this
->
wrapValuesForDataProvider
(
$this
->
getInvalidBooleanValues
());
array
(
null
),
}
array
(
123
),
array
(
'foo'
),
protected
function
getInvalidBooleanValues
()
array
(
array
()),
{
array
(
new
stdClass
()),
return
array
(
123
,
3.14
,
'foo'
,
array
(),
new
stdClass
);
);
}
protected
function
getInvalidDocumentValues
()
{
return
array
(
123
,
3.14
,
'foo'
,
true
);
}
protected
function
getInvalidIntegerValues
()
{
return
array
(
3.14
,
'foo'
,
true
,
array
(),
new
stdClass
);
}
protected
function
getInvalidStringValues
()
{
return
array
(
123
,
3.14
,
true
,
array
(),
new
stdClass
);
}
protected
function
getInvalidWriteConcernValues
()
{
return
array
(
123
,
3.14
,
'foo'
,
true
,
array
(),
new
stdClass
);
}
protected
function
wrapValuesForDataProvider
(
array
$values
)
{
return
array_map
(
function
(
$value
)
{
return
array
(
$value
);
},
$values
);
}
}
}
}
tests/Operation/UpdateManyTest.php
View file @
f2c10219
...
@@ -8,24 +8,25 @@ class UpdateManyTest extends TestCase
...
@@ -8,24 +8,25 @@ class UpdateManyTest extends TestCase
{
{
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testConstructorFilterArgumentType
(
$filter
)
public
function
testConstructorFilterArgumentType
Check
(
$filter
)
{
{
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)));
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)));
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testConstructorUpdateArgumentType
(
$update
)
public
function
testConstructorUpdateArgumentType
Check
(
$update
)
{
{
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
$update
);
new
UpdateMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
$update
);
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $update argument is not an update operator
*/
*/
public
function
testConstructorUpdateArgumentRequiresOperators
()
public
function
testConstructorUpdateArgumentRequiresOperators
()
{
{
...
...
tests/Operation/UpdateOneTest.php
View file @
f2c10219
...
@@ -8,24 +8,25 @@ class UpdateOneTest extends TestCase
...
@@ -8,24 +8,25 @@ class UpdateOneTest extends TestCase
{
{
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testConstructorFilterArgumentType
(
$filter
)
public
function
testConstructorFilterArgumentType
Check
(
$filter
)
{
{
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)));
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)));
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocument
Argument
s
* @dataProvider provideInvalidDocument
Value
s
*/
*/
public
function
testConstructorUpdateArgumentType
(
$update
)
public
function
testConstructorUpdateArgumentType
Check
(
$update
)
{
{
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
$update
);
new
UpdateOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
$update
);
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $update argument is not an update operator
*/
*/
public
function
testConstructorUpdateArgumentRequiresOperators
()
public
function
testConstructorUpdateArgumentRequiresOperators
()
{
{
...
...
tests/Operation/UpdateTest.php
View file @
f2c10219
...
@@ -8,45 +8,49 @@ class UpdateTest extends TestCase
...
@@ -8,45 +8,49 @@ class UpdateTest extends TestCase
{
{
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments
* @expectedExceptionMessageRegExp /Expected \$filter to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
*/
public
function
testConstructorFilterArgumentType
(
$filter
)
public
function
testConstructorFilterArgumentType
Check
(
$filter
)
{
{
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)));
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$filter
,
array
(
'$set'
=>
array
(
'x'
=>
1
)));
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments
* @expectedExceptionMessageRegExp /Expected \$update to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
*/
public
function
testConstructorUpdateArgumentType
(
$update
)
public
function
testConstructorUpdateArgumentType
Check
(
$update
)
{
{
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
$update
);
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
$update
);
}
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalid
BooleanArgument
s
* @dataProvider provideInvalid
ConstructorOption
s
*/
*/
public
function
testConstructor
MultiOptionType
(
$multi
)
public
function
testConstructor
OptionTypeChecks
(
array
$options
)
{
{
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
array
(
'y'
=>
1
),
array
(
'multi'
=>
$multi
)
);
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
array
(
'y'
=>
1
),
$options
);
}
}
/**
public
function
provideInvalidConstructorOptions
()
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidBooleanArguments
*/
public
function
testConstructorUpsertOptionType
(
$upsert
)
{
{
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
array
(
'y'
=>
1
),
array
(
'upsert'
=>
$upsert
));
$options
=
array
();
}
/**
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
$options
[][]
=
array
(
'multi'
=>
$value
);
*/
}
public
function
testConstructorWriteConcernOptionType
()
{
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
array
(
'x'
=>
1
),
array
(
'y'
=>
1
),
array
(
'writeConcern'
=>
null
));
$options
[][]
=
array
(
'upsert'
=>
$value
);
}
foreach
(
$this
->
getInvalidWriteConcernValues
()
as
$value
)
{
$options
[][]
=
array
(
'writeConcern'
=>
$value
);
}
return
$options
;
}
}
}
}
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