Commit 1bedfc9e authored by Jeremy Mikola's avatar Jeremy Mikola

Unit tests for Distinct operation and allow array/object $filter

parent 107ece46
...@@ -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));
......
...@@ -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');
} }
......
<?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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment