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
107ece46
Commit
107ece46
authored
Sep 03, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit tests for Count operation and allow array/object $filter
parent
0c8b44f5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
4 deletions
+62
-4
Collection.php
src/Collection.php
+3
-3
Count.php
src/Operation/Count.php
+5
-1
CountTest.php
tests/Operation/CountTest.php
+54
-0
No files found.
src/Collection.php
View file @
107ece46
...
@@ -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
));
...
...
src/Operation/Count.php
View file @
107ece46
...
@@ -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'
]);
...
...
tests/Operation/CountTest.php
0 → 100644
View file @
107ece46
<?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
);
}
}
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