Commit 9f2700fb authored by Derick Rethans's avatar Derick Rethans

PHPLIB-354: Implement new count API

parent 71d76b15
source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
arg_name: option
name: hint
type: string|array|object
description: |
The index to use. Specify either the index name as a string or the index key
pattern as a document. If specified, then the query system will only consider
plans using the hinted index.
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: limit
type: integer
description: |
The maximum number of matching documents to return.
interface: phpmethod
operation: ~
optional: true
---
source:
file: apiargs-common-option.yaml
ref: maxTimeMS
---
source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: readConcern
---
source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: readPreference
---
source:
file: apiargs-common-option.yaml
ref: session
---
arg_name: option
name: skip
type: integer
description: |
The number of matching documents to skip before returning results.
interface: phpmethod
operation: ~
optional: true
...
source:
file: apiargs-MongoDBCollection-common-param.yaml
ref: $filter
optional: true
replacement:
action: " to count"
---
source:
file: apiargs-common-param.yaml
ref: $options
...
source:
file: apiargs-common-option.yaml
ref: maxTimeMS
---
source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: readConcern
---
source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: readPreference
---
source:
file: apiargs-common-option.yaml
ref: session
...
source:
file: apiargs-common-param.yaml
ref: $options
...
......@@ -63,6 +63,7 @@ Methods
/reference/method/MongoDBCollection-aggregate
/reference/method/MongoDBCollection-bulkWrite
/reference/method/MongoDBCollection-count
/reference/method/MongoDBCollection-countDocuments
/reference/method/MongoDBCollection-createIndex
/reference/method/MongoDBCollection-createIndexes
/reference/method/MongoDBCollection-deleteMany
......@@ -71,6 +72,7 @@ Methods
/reference/method/MongoDBCollection-drop
/reference/method/MongoDBCollection-dropIndex
/reference/method/MongoDBCollection-dropIndexes
/reference/method/MongoDBCollection-estimatedDocumentCount
/reference/method/MongoDBCollection-explain
/reference/method/MongoDBCollection-find
/reference/method/MongoDBCollection-findOne
......
=====================================
MongoDB\\Collection::countDocuments()
=====================================
.. versionadded:: 1.4
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\\Collection::countDocuments()
Count the number of documents that match the filter criteria.
.. code-block:: php
function countDocuments($filter = [], array $options = []): integer
This method has the following parameters:
.. include:: /includes/apiargs/MongoDBCollection-method-countDocuments-param.rst
The ``$options`` parameter supports the following options:
.. include:: /includes/apiargs/MongoDBCollection-method-countDocuments-option.rst
Return Values
-------------
The number of documents matching the filter criteria.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-unexpectedvalueexception.rst
.. include:: /includes/extracts/error-unsupportedexception.rst
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
Internally, this method uses the ``$group`` aggregation pipeline operator to
obtain the result. If a ``filter`` parameter is given, this is converted into
a ``$match`` pipeline operator. Optional ``skip`` and ``limit`` stages are
added between ``$match`` and ``group`` if present in the options.
.. todo: add output and examples
=============================================
MongoDB\\Collection::estimatedDocumentCount()
=============================================
.. versionadded:: 1.4
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\\Collection::estimatedDocumentCount()
Gets an estimated number of documents in the collection using collection metadata.
.. code-block:: php
function countDocuments(array $options = []): integer
This method has the following parameters:
.. include:: /includes/apiargs/MongoDBCollection-method-estimateDocumentCount-param.rst
The ``$options`` parameter supports the following options:
.. include:: /includes/apiargs/MongoDBCollection-method-estimateDocumentCount-option.rst
Return Values
-------------
An estimated number of documents in the collection.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-unexpectedvalueexception.rst
.. include:: /includes/extracts/error-unsupportedexception.rst
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Behavior
--------
.. include:: /includes/extracts/note-bson-comparison.rst
See Also
--------
- :manual:`count </reference/command/count>` command reference in the MongoDB
manual
......@@ -35,11 +35,13 @@ use MongoDB\Operation\Aggregate;
use MongoDB\Operation\BulkWrite;
use MongoDB\Operation\CreateIndexes;
use MongoDB\Operation\Count;
use MongoDB\Operation\CountDocuments;
use MongoDB\Operation\DeleteMany;
use MongoDB\Operation\DeleteOne;
use MongoDB\Operation\Distinct;
use MongoDB\Operation\DropCollection;
use MongoDB\Operation\DropIndexes;
use MongoDB\Operation\EstimatedDocumentCount;
use MongoDB\Operation\Explain;
use MongoDB\Operation\Explainable;
use MongoDB\Operation\Find;
......@@ -255,6 +257,8 @@ class Collection
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*
* @deprecated 1.4
*/
public function count($filter = [], array $options = [])
{
......@@ -273,6 +277,35 @@ class Collection
return $operation->execute($server);
}
/**
* Gets the number of documents matching the filter.
*
* @see CountDocuments::__construct() for supported options
* @param array|object $filter Query by which to filter documents
* @param array $options Command options
* @return integer
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function countDocuments($filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
$server = $this->manager->selectServer($options['readPreference']);
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
$options['readConcern'] = $this->readConcern;
}
$operation = new CountDocuments($this->databaseName, $this->collectionName, $filter, $options);
return $operation->execute($server);
}
/**
* Create a single index for the collection.
*
......@@ -501,6 +534,34 @@ class Collection
return $operation->execute($server);
}
/**
* Gets an estimated number of documents in the collection using the collection metadata.
*
* @see EstimatedDocumentCount::__construct() for supported options
* @param array $options Command options
* @return integer
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function EstimatedDocumentCount(array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
}
$server = $this->manager->selectServer($options['readPreference']);
if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
$options['readConcern'] = $this->readConcern;
}
$operation = new EstimatedDocumentCount($this->databaseName, $this->collectionName, $options);
return $operation->execute($server);
}
/**
* Explains explainable commands.
*
......
<?php
/*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Driver\Session;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException;
/**
* Operation for obtaining an exact count of documents in a collection
*
* @api
* @see \MongoDB\Collection::countDocuments()
* @see https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#countdocuments
*/
class CountDocuments implements Executable
{
private static $wireVersionForCollation = 5;
private static $wireVersionForReadConcern = 4;
private $databaseName;
private $collectionName;
private $filter;
private $options;
/**
* Constructs an aggregate command for counting documents
*
* Supported options:
*
* * collation (document): Collation specification.
*
* This is not supported for server versions < 3.4 and will result in an
* exception at execution time if used.
*
* * hint (string|document): The index to use. Specify either the index
* name as a string or the index key pattern as a document. If specified,
* then the query system will only consider plans using the hinted index.
*
* * limit (integer): The maximum number of documents to count.
*
* * maxTimeMS (integer): The maximum amount of time to allow the query to
* run.
*
* * readConcern (MongoDB\Driver\ReadConcern): Read concern.
*
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
*
* * readPreference (MongoDB\Driver\ReadPreference): Read preference.
*
* * session (MongoDB\Driver\Session): Client session.
*
* Sessions are not supported for server versions < 3.6.
*
* * skip (integer): The number of documents to skip before returning the
* documents.
*
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param array|object $filter Query by which to filter documents
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
public function __construct($databaseName, $collectionName, $filter, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if (isset($options['collation']) && ! is_array($options['collation']) && ! is_object($options['collation'])) {
throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object');
}
if (isset($options['hint']) && ! is_string($options['hint']) && ! is_array($options['hint']) && ! is_object($options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], 'string or array or object');
}
if (isset($options['limit']) && ! is_integer($options['limit'])) {
throw InvalidArgumentException::invalidType('"limit" option', $options['limit'], 'integer');
}
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
if (isset($options['session']) && ! $options['session'] instanceof Session) {
throw InvalidArgumentException::invalidType('"session" option', $options['session'], 'MongoDB\Driver\Session');
}
if (isset($options['skip']) && ! is_integer($options['skip'])) {
throw InvalidArgumentException::invalidType('"skip" option', $options['skip'], 'integer');
}
if (isset($options['readConcern']) && $options['readConcern']->isDefault()) {
unset($options['readConcern']);
}
$this->databaseName = (string) $databaseName;
$this->collectionName = (string) $collectionName;
$this->filter = $filter;
$this->options = $options;
}
/**
* Execute the operation.
*
* @see Executable::execute()
* @param Server $server
* @return integer
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if collation or read concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function execute(Server $server)
{
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported();
}
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported();
}
$cursor = $server->executeReadCommand($this->databaseName, new Command($this->createCommandDocument()), $this->createOptions());
$result = current($cursor->toArray());
if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
throw new UnexpectedValueException('count command did not return a numeric "n" value');
}
return (integer) $result->n;
}
/**
* Create the count command document.
*
* @return array
*/
private function createCommandDocument()
{
$pipeline = [
['$match' => (object) $this->filter]
];
if (isset($this->options['skip'])) {
$pipeline[] = ['$skip' => $this->options['skip']];
}
if (isset($this->options['limit'])) {
$pipeline[] = ['$limit' => $this->options['limit']];
}
$pipeline[] = ['$group' => [ '_id' => null, 'n' => ['$sum' => 1]]];
$cmd = [
'aggregate' => $this->collectionName,
'pipeline' => $pipeline,
'cursor' => (object) [],
];
if (isset($this->options['collation'])) {
$cmd['collation'] = (object) $this->options['collation'];
}
if (isset($this->options['hint'])) {
$cmd['hint'] = is_array($this->options['hint']) ? (object) $this->options['hint'] : $this->options['hint'];
}
if (isset($this->options['maxTimeMS'])) {
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
}
return $cmd;
}
/**
* Create options for executing the command.
*
* @see http://php.net/manual/en/mongodb-driver-server.executereadcommand.php
* @return array
*/
private function createOptions()
{
$options = [];
if (isset($this->options['readConcern'])) {
$options['readConcern'] = $this->options['readConcern'];
}
if (isset($this->options['readPreference'])) {
$options['readPreference'] = $this->options['readPreference'];
}
if (isset($this->options['session'])) {
$options['session'] = $this->options['session'];
}
return $options;
}
}
<?php
/*
* Copyright 2015-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Driver\Session;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException;
/**
* Operation for obtaining an estimated count of documents in a collection
*
* @api
* @see \MongoDB\Collection::estimatedDocumentCount()
* @see http://docs.mongodb.org/manual/reference/command/count/
*/
class EstimatedDocumentCount implements Executable, Explainable
{
private static $wireVersionForCollation = 5;
private static $wireVersionForReadConcern = 4;
private $databaseName;
private $collectionName;
private $options;
/**
* Constructs a count command.
*
* Supported options:
*
* * maxTimeMS (integer): The maximum amount of time to allow the query to
* run.
*
* * readConcern (MongoDB\Driver\ReadConcern): Read concern.
*
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
*
* * readPreference (MongoDB\Driver\ReadPreference): Read preference.
*
* * session (MongoDB\Driver\Session): Client session.
*
* Sessions are not supported for server versions < 3.6.
*
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
public function __construct($databaseName, $collectionName, array $options = [])
{
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
if (isset($options['session']) && ! $options['session'] instanceof Session) {
throw InvalidArgumentException::invalidType('"session" option', $options['session'], 'MongoDB\Driver\Session');
}
if (isset($options['readConcern']) && $options['readConcern']->isDefault()) {
unset($options['readConcern']);
}
$this->databaseName = (string) $databaseName;
$this->collectionName = (string) $collectionName;
$this->options = $options;
}
/**
* Execute the operation.
*
* @see Executable::execute()
* @param Server $server
* @return integer
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if collation or read concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function execute(Server $server)
{
if (isset($this->options['collation']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) {
throw UnsupportedException::collationNotSupported();
}
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported();
}
$cursor = $server->executeReadCommand($this->databaseName, new Command($this->createCommandDocument()), $this->createOptions());
$result = current($cursor->toArray());
// Older server versions may return a float
if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
throw new UnexpectedValueException('count command did not return a numeric "n" value');
}
return (integer) $result->n;
}
public function getCommandDocument(Server $server)
{
return $this->createCommandDocument();
}
/**
* Create the count command document.
*
* @return array
*/
private function createCommandDocument()
{
$cmd = ['count' => $this->collectionName];
if (isset($this->options['maxTimeMS'])) {
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
}
return $cmd;
}
/**
* Create options for executing the command.
*
* @see http://php.net/manual/en/mongodb-driver-server.executereadcommand.php
* @return array
*/
private function createOptions()
{
$options = [];
if (isset($this->options['readConcern'])) {
$options['readConcern'] = $this->options['readConcern'];
}
if (isset($this->options['readPreference'])) {
$options['readPreference'] = $this->options['readPreference'];
}
if (isset($this->options['session'])) {
$options['session'] = $this->options['session'];
}
return $options;
}
}
......@@ -123,12 +123,16 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
);
case 'count':
case 'countDocuments':
case 'find':
return $this->collection->{$operation['name']}(
isset($operation['arguments']['filter']) ? $operation['arguments']['filter'] : [],
array_diff_key($operation['arguments'], ['filter' => 1])
);
case 'estimatedDocumentCount':
return $this->collection->estimatedDocumentCount($operation['arguments']);
case 'deleteMany':
case 'deleteOne':
case 'findOneAndDelete':
......@@ -264,6 +268,8 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
break;
case 'count':
case 'countDocuments':
case 'estimatedDocumentCount':
$this->assertSame($expectedResult, $actualResult);
break;
......
......@@ -8,7 +8,25 @@
"minServerVersion": "3.4",
"tests": [
{
"description": "Count with collation",
"description": "Count documents with collation",
"operation": {
"name": "countDocuments",
"arguments": {
"filter": {
"x": "ping"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": 1
}
},
{
"description": "Deprecated count with collation",
"operation": {
"name": "count",
"arguments": {
......
......@@ -15,7 +15,59 @@
],
"tests": [
{
"description": "Count without a filter",
"description": "Estimated document count",
"operation": {
"name": "estimatedDocumentCount",
"arguments": {}
},
"outcome": {
"result": 3
}
},
{
"description": "Count documents without a filter",
"operation": {
"name": "countDocuments",
"arguments": {
"filter": {}
}
},
"outcome": {
"result": 3
}
},
{
"description": "Count documents with a filter",
"operation": {
"name": "countDocuments",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
}
}
},
"outcome": {
"result": 2
}
},
{
"description": "Count documents with skip and limit",
"operation": {
"name": "countDocuments",
"arguments": {
"filter": {},
"skip": 1,
"limit": 3
}
},
"outcome": {
"result": 2
}
},
{
"description": "Deprecated count without a filter",
"operation": {
"name": "count",
"arguments": {
......@@ -27,7 +79,7 @@
}
},
{
"description": "Count with a filter",
"description": "Deprecated count with a filter",
"operation": {
"name": "count",
"arguments": {
......@@ -43,7 +95,7 @@
}
},
{
"description": "Count with skip and limit",
"description": "Deprecated count with skip and limit",
"operation": {
"name": "count",
"arguments": {
......
<?php
namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\CountDocuments;
class CountDocumentsTest extends TestCase
{
/**
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
{
$this->expectException(InvalidArgumentException::class);
new CountDocuments($this->getDatabaseName(), $this->getCollectionName(), $filter);
}
/**
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
{
$this->expectException(InvalidArgumentException::class);
new CountDocuments($this->getDatabaseName(), $this->getCollectionName(), [], $options);
}
public function provideInvalidConstructorOptions()
{
$options = [];
foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = ['collation' => $value];
}
foreach ($this->getInvalidHintValues() as $value) {
$options[][] = ['hint' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['limit' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['maxTimeMS' => $value];
}
foreach ($this->getInvalidReadConcernValues() as $value) {
$options[][] = ['readConcern' => $value];
}
foreach ($this->getInvalidReadPreferenceValues() as $value) {
$options[][] = ['readPreference' => $value];
}
foreach ($this->getInvalidSessionValues() as $value) {
$options[][] = ['session' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['skip' => $value];
}
return $options;
}
private function getInvalidHintValues()
{
return [123, 3.14, true];
}
}
<?php
namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\EstimatedDocumentCount;
class EstimatedDocumentCountTest extends TestCase
{
/**
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
{
$this->expectException(InvalidArgumentException::class);
new EstimatedDocumentCount($this->getDatabaseName(), $this->getCollectionName(), $options);
}
public function provideInvalidConstructorOptions()
{
$options = [];
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['maxTimeMS' => $value];
}
foreach ($this->getInvalidReadConcernValues() as $value) {
$options[][] = ['readConcern' => $value];
}
foreach ($this->getInvalidReadPreferenceValues() as $value) {
$options[][] = ['readPreference' => $value];
}
foreach ($this->getInvalidSessionValues() as $value) {
$options[][] = ['session' => $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