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