Commit 4043b265 authored by Jeremy Mikola's avatar Jeremy Mikola

Shorthand array syntax

parent 303de406
......@@ -27,7 +27,7 @@ class Client
* @param array $options Additional connection string options
* @param array $driverOptions Driver-specific options
*/
public function __construct($uri, array $options = array(), array $driverOptions = array())
public function __construct($uri, array $options = [], array $driverOptions = [])
{
$this->manager = new Manager($uri, $options, $driverOptions);
}
......@@ -52,7 +52,7 @@ class Client
* @see ListDatabases::__construct() for supported options
* @return DatabaseInfoIterator
*/
public function listDatabases(array $options = array())
public function listDatabases(array $options = [])
{
$operation = new ListDatabases($options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
......
......@@ -93,7 +93,7 @@ class Collection
* @param array $options Command options
* @return Traversable
*/
public function aggregate(array $pipeline, array $options = array())
public function aggregate(array $pipeline, array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
......@@ -117,7 +117,7 @@ class Collection
* @param array $options Command options
* @return BulkWriteResult
*/
public function bulkWrite(array $operations, array $options = array())
public function bulkWrite(array $operations, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
......@@ -137,7 +137,7 @@ class Collection
* @param array $options Command options
* @return integer
*/
public function count($filter = array(), array $options = array())
public function count($filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
......@@ -158,9 +158,9 @@ class Collection
* @param array $options Index options
* @return string The name of the created index
*/
public function createIndex($key, array $options = array())
public function createIndex($key, array $options = [])
{
return current($this->createIndexes(array(array('key' => $key) + $options)));
return current($this->createIndexes([['key' => $key] + $options]));
}
/**
......@@ -203,7 +203,7 @@ class Collection
* @param array $options Command options
* @return DeleteResult
*/
public function deleteMany($filter, array $options = array())
public function deleteMany($filter, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
......@@ -224,7 +224,7 @@ class Collection
* @param array $options Command options
* @return DeleteResult
*/
public function deleteOne($filter, array $options = array())
public function deleteOne($filter, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
......@@ -245,7 +245,7 @@ class Collection
* @param array $options Command options
* @return mixed[]
*/
public function distinct($fieldName, $filter = array(), array $options = array())
public function distinct($fieldName, $filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
......@@ -313,7 +313,7 @@ class Collection
* @param array $options Additional options
* @return Cursor
*/
public function find($filter = array(), array $options = array())
public function find($filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
......@@ -334,7 +334,7 @@ class Collection
* @param array $options Additional options
* @return object|null
*/
public function findOne($filter = array(), array $options = array())
public function findOne($filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
......@@ -357,7 +357,7 @@ class Collection
* @param array $options Command options
* @return object|null
*/
public function findOneAndDelete($filter, array $options = array())
public function findOneAndDelete($filter, array $options = [])
{
$operation = new FindOneAndDelete($this->databaseName, $this->collectionName, $filter, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
......@@ -380,7 +380,7 @@ class Collection
* @param array $options Command options
* @return object|null
*/
public function findOneAndReplace($filter, $replacement, array $options = array())
public function findOneAndReplace($filter, $replacement, array $options = [])
{
$operation = new FindOneAndReplace($this->databaseName, $this->collectionName, $filter, $replacement, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
......@@ -403,7 +403,7 @@ class Collection
* @param array $options Command options
* @return object|null
*/
public function findOneAndUpdate($filter, $update, array $options = array())
public function findOneAndUpdate($filter, $update, array $options = [])
{
$operation = new FindOneAndUpdate($this->databaseName, $this->collectionName, $filter, $update, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
......@@ -451,7 +451,7 @@ class Collection
* @param array $options Command options
* @return InsertManyResult
*/
public function insertMany(array $documents, array $options = array())
public function insertMany(array $documents, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
......@@ -472,7 +472,7 @@ class Collection
* @param array $options Command options
* @return InsertOneResult
*/
public function insertOne($document, array $options = array())
public function insertOne($document, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
......@@ -490,7 +490,7 @@ class Collection
* @see ListIndexes::__construct() for supported options
* @return IndexInfoIterator
*/
public function listIndexes(array $options = array())
public function listIndexes(array $options = [])
{
$operation = new ListIndexes($this->databaseName, $this->collectionName, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
......@@ -508,7 +508,7 @@ class Collection
* @param array $options Command options
* @return UpdateResult
*/
public function replaceOne($filter, $replacement, array $options = array())
public function replaceOne($filter, $replacement, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
......@@ -530,7 +530,7 @@ class Collection
* @param array $options Command options
* @return UpdateResult
*/
public function updateMany($filter, $update, array $options = array())
public function updateMany($filter, $update, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
......@@ -552,7 +552,7 @@ class Collection
* @param array $options Command options
* @return UpdateResult
*/
public function updateOne($filter, $update, array $options = array())
public function updateOne($filter, $update, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
......
......@@ -66,7 +66,7 @@ class Database
* @param array $options
* @return object Command result document
*/
public function createCollection($collectionName, array $options = array())
public function createCollection($collectionName, array $options = [])
{
$operation = new CreateCollection($this->databaseName, $collectionName, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
......@@ -118,7 +118,7 @@ class Database
* @param array $options
* @return CollectionInfoIterator
*/
public function listCollections(array $options = array())
public function listCollections(array $options = [])
{
$operation = new ListCollections($this->databaseName, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
......
......@@ -75,7 +75,7 @@ class CollectionInfo
*/
public function getOptions()
{
return isset($this->info['options']) ? (array) $this->info['options'] : array();
return isset($this->info['options']) ? (array) $this->info['options'] : [];
}
/**
......
......@@ -60,7 +60,7 @@ class Aggregate implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, array $pipeline, array $options = array())
public function __construct($databaseName, $collectionName, array $pipeline, array $options = [])
{
if (empty($pipeline)) {
throw new InvalidArgumentException('$pipeline is empty');
......@@ -80,10 +80,10 @@ class Aggregate implements Executable
$expectedIndex += 1;
}
$options += array(
$options += [
'allowDiskUse' => false,
'useCursor' => true,
);
];
if ( ! is_bool($options['allowDiskUse'])) {
throw new InvalidArgumentTypeException('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
......@@ -156,10 +156,10 @@ class Aggregate implements Executable
*/
private function createCommand(Server $server, $isCursorSupported)
{
$cmd = array(
$cmd = [
'aggregate' => $this->collectionName,
'pipeline' => $this->pipeline,
);
];
// Servers < 2.6 do not support any command options
if ( ! $isCursorSupported) {
......@@ -174,7 +174,7 @@ class Aggregate implements Executable
if ($this->options['useCursor']) {
$cmd['cursor'] = isset($this->options["batchSize"])
? array('batchSize' => $this->options["batchSize"])
? ['batchSize' => $this->options["batchSize"]]
: new stdClass;
}
......
......@@ -66,7 +66,7 @@ class BulkWrite implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, array $operations, array $options = array())
public function __construct($databaseName, $collectionName, array $operations, array $options = [])
{
if (empty($operations)) {
throw new InvalidArgumentException('$operations is empty');
......@@ -104,7 +104,7 @@ class BulkWrite implements Executable
case self::DELETE_MANY:
case self::DELETE_ONE:
$operations[$i][$type][1] = array('limit' => ($type === self::DELETE_ONE ? 1 : 0));
$operations[$i][$type][1] = ['limit' => ($type === self::DELETE_ONE ? 1 : 0)];
break;
......@@ -122,7 +122,7 @@ class BulkWrite implements Executable
}
if ( ! isset($args[2])) {
$args[2] = array();
$args[2] = [];
}
if ( ! is_array($args[2])) {
......@@ -130,7 +130,7 @@ class BulkWrite implements Executable
}
$args[2]['multi'] = false;
$args[2] += array('upsert' => false);
$args[2] += ['upsert' => false];
if ( ! is_bool($args[2]['upsert'])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
......@@ -155,7 +155,7 @@ class BulkWrite implements Executable
}
if ( ! isset($args[2])) {
$args[2] = array();
$args[2] = [];
}
if ( ! is_array($args[2])) {
......@@ -163,7 +163,7 @@ class BulkWrite implements Executable
}
$args[2]['multi'] = ($type === self::UPDATE_MANY);
$args[2] += array('upsert' => false);
$args[2] += ['upsert' => false];
if ( ! is_bool($args[2]['upsert'])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
......@@ -180,9 +180,7 @@ class BulkWrite implements Executable
$expectedIndex += 1;
}
$options += array(
'ordered' => true,
);
$options += ['ordered' => true];
if ( ! is_bool($options['ordered'])) {
throw new InvalidArgumentTypeException('"ordered" option', $options['ordered'], 'boolean');
......@@ -208,7 +206,7 @@ class BulkWrite implements Executable
public function execute(Server $server)
{
$bulk = new Bulk(['ordered' => $this->options['ordered']]);
$insertedIds = array();
$insertedIds = [];
foreach ($this->operations as $i => $operation) {
$type = key($operation);
......
......@@ -48,7 +48,7 @@ class Count implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter = array(), array $options = array())
public function __construct($databaseName, $collectionName, $filter = [], array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
......@@ -119,15 +119,13 @@ class Count implements Executable
*/
private function createCommand()
{
$cmd = array(
'count' => $this->collectionName,
);
$cmd = ['count' => $this->collectionName];
if ( ! empty($this->filter)) {
$cmd['query'] = (object) $this->filter;
}
foreach (array('hint', 'limit', 'maxTimeMS', 'skip') as $option) {
foreach (['hint', 'limit', 'maxTimeMS', 'skip'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = $this->options[$option];
}
......
......@@ -23,7 +23,7 @@ class CreateCollection implements Executable
private $databaseName;
private $collectionName;
private $options = array();
private $options = [];
/**
* Constructs a create command.
......@@ -57,7 +57,7 @@ class CreateCollection implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, array $options = array())
public function __construct($databaseName, $collectionName, array $options = [])
{
if (isset($options['autoIndexId']) && ! is_bool($options['autoIndexId'])) {
throw new InvalidArgumentTypeException('"autoIndexId" option', $options['autoIndexId'], 'boolean');
......@@ -118,9 +118,9 @@ class CreateCollection implements Executable
*/
private function createCommand()
{
$cmd = array('create' => $this->collectionName);
$cmd = ['create' => $this->collectionName];
foreach (array('autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size') as $option) {
foreach (['autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = $this->options[$option];
}
......
......@@ -24,7 +24,7 @@ class CreateIndexes implements Executable
private $databaseName;
private $collectionName;
private $indexes = array();
private $indexes = [];
/**
* Constructs a createIndexes command.
......@@ -85,10 +85,10 @@ class CreateIndexes implements Executable
*/
private function executeCommand(Server $server)
{
$command = new Command(array(
$command = new Command([
'createIndexes' => $this->collectionName,
'indexes' => $this->indexes,
));
]);
$cursor = $server->executeCommand($this->databaseName, $command);
$result = current($cursor->toArray());
......
......@@ -42,7 +42,7 @@ class Delete implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, $limit, array $options = array())
public function __construct($databaseName, $collectionName, $filter, $limit, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
......@@ -73,7 +73,7 @@ class Delete implements Executable
public function execute(Server $server)
{
$bulk = new Bulk();
$bulk->delete($this->filter, array('limit' => $this->limit));
$bulk->delete($this->filter, ['limit' => $this->limit]);
$writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
$writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
......
......@@ -30,7 +30,7 @@ class DeleteMany implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, array $options = array())
public function __construct($databaseName, $collectionName, $filter, array $options = [])
{
$this->delete = new Delete($databaseName, $collectionName, $filter, 0, $options);
}
......
......@@ -30,7 +30,7 @@ class DeleteOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, array $options = array())
public function __construct($databaseName, $collectionName, $filter, array $options = [])
{
$this->delete = new Delete($databaseName, $collectionName, $filter, 1, $options);
}
......
......@@ -42,7 +42,7 @@ class Distinct implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $fieldName, $filter = array(), array $options = array())
public function __construct($databaseName, $collectionName, $fieldName, $filter = [], array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
......@@ -95,10 +95,10 @@ class Distinct implements Executable
*/
private function createCommand()
{
$cmd = array(
$cmd = [
'distinct' => $this->collectionName,
'key' => $this->fieldName,
);
];
if ( ! empty($this->filter)) {
$cmd['query'] = (object) $this->filter;
......
......@@ -43,7 +43,7 @@ class DropCollection implements Executable
public function execute(Server $server)
{
try {
$cursor = $server->executeCommand($this->databaseName, new Command(array('drop' => $this->collectionName)));
$cursor = $server->executeCommand($this->databaseName, new Command(['drop' => $this->collectionName]));
} catch (DriverRuntimeException $e) {
/* The server may return an error if the collection does not exist.
* Check for an error message (unfortunately, there isn't a code)
......
......@@ -38,7 +38,7 @@ class DropDatabase implements Executable
*/
public function execute(Server $server)
{
$cursor = $server->executeCommand($this->databaseName, new Command(array('dropDatabase' => 1)));
$cursor = $server->executeCommand($this->databaseName, new Command(['dropDatabase' => 1]));
$result = current($cursor->toArray());
if (empty($result->ok)) {
......
......@@ -50,10 +50,10 @@ class DropIndexes implements Executable
*/
public function execute(Server $server)
{
$cmd = array(
$cmd = [
'dropIndexes' => $this->collectionName,
'index' => $this->indexName,
);
];
$cursor = $server->executeCommand($this->databaseName, new Command($cmd));
$result = current($cursor->toArray());
......
......@@ -79,7 +79,7 @@ class Find implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, array $options = array())
public function __construct($databaseName, $collectionName, $filter, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
......@@ -172,7 +172,7 @@ class Find implements Executable
*/
private function createQuery()
{
$options = array();
$options = [];
if ( ! empty($this->options['allowPartialResults'])) {
$options['partial'] = true;
......@@ -188,13 +188,13 @@ class Find implements Executable
}
}
foreach (array('batchSize', 'limit', 'skip', 'sort', 'noCursorTimeout', 'oplogReplay', 'projection') as $option) {
foreach (['batchSize', 'limit', 'skip', 'sort', 'noCursorTimeout', 'oplogReplay', 'projection'] as $option) {
if (isset($this->options[$option])) {
$options[$option] = $this->options[$option];
}
}
$modifiers = empty($this->options['modifiers']) ? array() : (array) $this->options['modifiers'];
$modifiers = empty($this->options['modifiers']) ? [] : (array) $this->options['modifiers'];
if (isset($options['comment'])) {
$modifiers['$comment'] = $options['comment'];
......
......@@ -61,11 +61,11 @@ class FindAndModify implements Executable
*/
public function __construct($databaseName, $collectionName, array $options)
{
$options += array(
$options += [
'new' => false,
'remove' => false,
'upsert' => false,
);
];
if (isset($options['fields']) && ! is_array($options['fields']) && ! is_object($options['fields'])) {
throw new InvalidArgumentTypeException('"fields" option', $options['fields'], 'array or object');
......@@ -153,9 +153,7 @@ class FindAndModify implements Executable
*/
private function createCommand()
{
$cmd = array(
'findAndModify' => $this->collectionName,
);
$cmd = ['findAndModify' => $this->collectionName];
if ($this->options['remove']) {
$cmd['remove'] = true;
......@@ -164,7 +162,7 @@ class FindAndModify implements Executable
$cmd['upsert'] = $this->options['upsert'];
}
foreach (array('fields', 'query', 'sort', 'update') as $option) {
foreach (['fields', 'query', 'sort', 'update'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = (object) $this->options[$option];
}
......
......@@ -52,7 +52,7 @@ class FindOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, array $options = array())
public function __construct($databaseName, $collectionName, $filter, array $options = [])
{
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
throw new InvalidArgumentTypeException('"typeMap" option', $options['typeMap'], 'array');
......@@ -62,7 +62,7 @@ class FindOne implements Executable
$databaseName,
$collectionName,
$filter,
array('limit' => -1) + $options
['limit' => -1] + $options
);
$this->options = $options;
......
......@@ -38,7 +38,7 @@ class FindOneAndDelete implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, array $options = array())
public function __construct($databaseName, $collectionName, $filter, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
......@@ -57,10 +57,7 @@ class FindOneAndDelete implements Executable
$this->findAndModify = new FindAndModify(
$databaseName,
$collectionName,
array(
'query' => $filter,
'remove' => true,
) + $options
['query' => $filter, 'remove' => true] + $options
);
}
......
......@@ -49,7 +49,7 @@ class FindOneAndReplace implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = array())
public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
......@@ -63,10 +63,10 @@ class FindOneAndReplace implements Executable
throw new InvalidArgumentException('First key in $replacement argument is an update operator');
}
$options += array(
$options += [
'returnDocument' => self::RETURN_DOCUMENT_BEFORE,
'upsert' => false,
);
];
if (isset($options['projection']) && ! is_array($options['projection']) && ! is_object($options['projection'])) {
throw new InvalidArgumentTypeException('"projection" option', $options['projection'], 'array or object');
......@@ -92,10 +92,7 @@ class FindOneAndReplace implements Executable
$this->findAndModify = new FindAndModify(
$databaseName,
$collectionName,
array(
'query' => $filter,
'update' => $replacement,
) + $options
['query' => $filter, 'update' => $replacement] + $options
);
}
......
......@@ -49,7 +49,7 @@ class FindOneAndUpdate implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, $update, array $options = array())
public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
......@@ -63,10 +63,10 @@ class FindOneAndUpdate implements Executable
throw new InvalidArgumentException('First key in $update argument is not an update operator');
}
$options += array(
$options += [
'returnDocument' => self::RETURN_DOCUMENT_BEFORE,
'upsert' => false,
);
];
if (isset($options['projection']) && ! is_array($options['projection']) && ! is_object($options['projection'])) {
throw new InvalidArgumentTypeException('"projection" option', $options['projection'], 'array or object');
......@@ -92,10 +92,7 @@ class FindOneAndUpdate implements Executable
$this->findAndModify = new FindAndModify(
$databaseName,
$collectionName,
array(
'query' => $filter,
'update' => $update,
) + $options
['query' => $filter, 'update' => $update] + $options
);
}
......
......@@ -40,7 +40,7 @@ class InsertMany implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, array $documents, array $options = array())
public function __construct($databaseName, $collectionName, array $documents, array $options = [])
{
if (empty($documents)) {
throw new InvalidArgumentException('$documents is empty');
......@@ -60,9 +60,7 @@ class InsertMany implements Executable
$expectedIndex += 1;
}
$options += array(
'ordered' => true,
);
$options += ['ordered' => true];
if ( ! is_bool($options['ordered'])) {
throw new InvalidArgumentTypeException('"ordered" option', $options['ordered'], 'boolean');
......@@ -88,7 +86,7 @@ class InsertMany implements Executable
public function execute(Server $server)
{
$bulk = new Bulk(['ordered' => $this->options['ordered']]);
$insertedIds = array();
$insertedIds = [];
foreach ($this->documents as $i => $document) {
$insertedId = $bulk->insert($document);
......
......@@ -35,7 +35,7 @@ class InsertOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $document, array $options = array())
public function __construct($databaseName, $collectionName, $document, array $options = [])
{
if ( ! is_array($document) && ! is_object($document)) {
throw new InvalidArgumentTypeException('$document', $document, 'array or object');
......
......@@ -37,7 +37,7 @@ class ListCollections implements Executable
* @param string $databaseName Database name
* @param array $options Command options
*/
public function __construct($databaseName, array $options = array())
public function __construct($databaseName, array $options = [])
{
if (isset($options['filter']) && ! is_array($options['filter']) && ! is_object($options['filter'])) {
throw new InvalidArgumentTypeException('"filter" option', $options['filter'], 'array or object');
......@@ -74,7 +74,7 @@ class ListCollections implements Executable
*/
private function executeCommand(Server $server)
{
$cmd = array('listCollections' => 1);
$cmd = ['listCollections' => 1];
if ( ! empty($this->options['filter'])) {
$cmd['filter'] = (object) $this->options['filter'];
......@@ -85,7 +85,7 @@ class ListCollections implements Executable
}
$cursor = $server->executeCommand($this->databaseName, new Command($cmd));
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
return new CollectionInfoCommandIterator($cursor);
}
......@@ -100,7 +100,7 @@ class ListCollections implements Executable
*/
private function executeLegacy(Server $server)
{
$filter = empty($this->options['filter']) ? array() : (array) $this->options['filter'];
$filter = empty($this->options['filter']) ? [] : (array) $this->options['filter'];
if (array_key_exists('name', $filter)) {
if ( ! is_string($filter['name'])) {
......@@ -111,11 +111,11 @@ class ListCollections implements Executable
}
$options = isset($this->options['maxTimeMS'])
? array('modifiers' => array('$maxTimeMS' => $this->options['maxTimeMS']))
: array();
? ['modifiers' => ['$maxTimeMS' => $this->options['maxTimeMS']]]
: [];
$cursor = $server->executeQuery($this->databaseName . '.system.namespaces', new Query($filter, $options));
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
return new CollectionInfoLegacyIterator($cursor);
}
......
......@@ -30,7 +30,7 @@ class ListDatabases implements Executable
*
* @param array $options Command options
*/
public function __construct(array $options = array())
public function __construct(array $options = [])
{
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
......@@ -48,14 +48,14 @@ class ListDatabases implements Executable
*/
public function execute(Server $server)
{
$cmd = array('listDatabases' => 1);
$cmd = ['listDatabases' => 1];
if (isset($this->options['maxTimeMS'])) {
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
}
$cursor = $server->executeCommand('admin', new Command($cmd));
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
$result = current($cursor->toArray());
if (empty($result['ok'])) {
......
......@@ -39,7 +39,7 @@ class ListIndexes implements Executable
* @param string $collectionName Collection name
* @param array $options Command options
*/
public function __construct($databaseName, $collectionName, array $options = array())
public function __construct($databaseName, $collectionName, array $options = [])
{
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
......@@ -73,7 +73,7 @@ class ListIndexes implements Executable
*/
private function executeCommand(Server $server)
{
$cmd = array('listIndexes' => $this->collectionName);
$cmd = ['listIndexes' => $this->collectionName];
if (isset($this->options['maxTimeMS'])) {
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
......@@ -93,7 +93,7 @@ class ListIndexes implements Executable
throw $e;
}
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
return new IndexInfoIteratorIterator($cursor);
}
......@@ -107,14 +107,14 @@ class ListIndexes implements Executable
*/
private function executeLegacy(Server $server)
{
$filter = array('ns' => $this->databaseName . '.' . $this->collectionName);
$filter = ['ns' => $this->databaseName . '.' . $this->collectionName];
$options = isset($this->options['maxTimeMS'])
? array('modifiers' => array('$maxTimeMS' => $this->options['maxTimeMS']))
: array();
? ['modifiers' => ['$maxTimeMS' => $this->options['maxTimeMS']]]
: [];
$cursor = $server->executeQuery($this->databaseName . '.system.indexes', new Query($filter, $options));
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
return new IndexInfoIteratorIterator($cursor);
}
......
......@@ -35,7 +35,7 @@ class ReplaceOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = array())
public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = [])
{
if ( ! is_array($replacement) && ! is_object($replacement)) {
throw new InvalidArgumentTypeException('$replacement', $replacement, 'array or object');
......@@ -50,7 +50,7 @@ class ReplaceOne implements Executable
$collectionName,
$filter,
$replacement,
array('multi' => false) + $options
['multi' => false] + $options
);
}
......
......@@ -48,7 +48,7 @@ class Update implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, $update, array $options = array())
public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
......@@ -58,10 +58,10 @@ class Update implements Executable
throw new InvalidArgumentTypeException('$update', $filter, 'array or object');
}
$options += array(
$options += [
'multi' => false,
'upsert' => false,
);
];
if ( ! is_bool($options['multi'])) {
throw new InvalidArgumentTypeException('"multi" option', $options['multi'], 'boolean');
......@@ -95,10 +95,10 @@ class Update implements Executable
*/
public function execute(Server $server)
{
$options = array(
$options = [
'multi' => $this->options['multi'],
'upsert' => $this->options['upsert'],
);
];
$bulk = new Bulk();
$bulk->update($this->filter, $this->update, $options);
......
......@@ -35,7 +35,7 @@ class UpdateMany implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, $update, array $options = array())
public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{
if ( ! is_array($update) && ! is_object($update)) {
throw new InvalidArgumentTypeException('$update', $update, 'array or object');
......@@ -50,7 +50,7 @@ class UpdateMany implements Executable
$collectionName,
$filter,
$update,
array('multi' => true) + $options
['multi' => true] + $options
);
}
......
......@@ -35,7 +35,7 @@ class UpdateOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, $update, array $options = array())
public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{
if ( ! is_array($update) && ! is_object($update)) {
throw new InvalidArgumentTypeException('$update', $update, 'array or object');
......@@ -50,7 +50,7 @@ class UpdateOne implements Executable
$collectionName,
$filter,
$update,
array('multi' => false) + $options
['multi' => false] + $options
);
}
......
......@@ -17,10 +17,10 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
public function testInserts()
{
$ops = array(
array('insertOne' => array(array('_id' => 1, 'x' => 11))),
array('insertOne' => array(array('x' => 22))),
);
$ops = [
['insertOne' => [['_id' => 1, 'x' => 11]]],
['insertOne' => [['x' => 22]]],
];
$result = $this->collection->bulkWrite($ops);
$this->assertInstanceOf('MongoDB\BulkWriteResult', $result);
......@@ -30,10 +30,10 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
$this->assertSame(1, $insertedIds[0]);
$this->assertInstanceOf('MongoDB\BSON\ObjectId', $insertedIds[1]);
$expected = array(
array('_id' => $insertedIds[0], 'x' => 11),
array('_id' => $insertedIds[1], 'x' => 22),
);
$expected = [
['_id' => $insertedIds[0], 'x' => 11],
['_id' => $insertedIds[1], 'x' => 22],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......@@ -42,13 +42,13 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
{
$this->createFixtures(4);
$ops = array(
array('updateOne' => array(array('_id' => 2), array('$inc' => array('x' => 1)))),
array('updateMany' => array(array('_id' => array('$gt' => 2)), array('$inc' => array('x' => -1)))),
array('updateOne' => array(array('_id' => 5), array('$set' => array('x' => 55)), array('upsert' => true))),
array('updateOne' => array(array('x' => 66), array('$set' => array('x' => 66)), array('upsert' => true))),
array('updateMany' => array(array('x' => array('$gt' => 50)), array('$inc' => array('x' => 1)))),
);
$ops = [
['updateOne' => [['_id' => 2], ['$inc' => ['x' => 1]]]],
['updateMany' => [['_id' => ['$gt' => 2]], ['$inc' => ['x' => -1]]]],
['updateOne' => [['_id' => 5], ['$set' => ['x' => 55]], ['upsert' => true]]],
['updateOne' => [['x' => 66], ['$set' => ['x' => 66]], ['upsert' => true]]],
['updateMany' => [['x' => ['$gt' => 50]], ['$inc' => ['x' => 1]]]],
];
$result = $this->collection->bulkWrite($ops);
$this->assertInstanceOf('MongoDB\BulkWriteResult', $result);
......@@ -60,14 +60,14 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
$this->assertSame(5, $upsertedIds[2]);
$this->assertInstanceOf('MongoDB\BSON\ObjectId', $upsertedIds[3]);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 23),
array('_id' => 3, 'x' => 32),
array('_id' => 4, 'x' => 43),
array('_id' => 5, 'x' => 56),
array('_id' => $upsertedIds[3], 'x' => 67),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 32],
['_id' => 4, 'x' => 43],
['_id' => 5, 'x' => 56],
['_id' => $upsertedIds[3], 'x' => 67],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......@@ -76,18 +76,18 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
{
$this->createFixtures(4);
$ops = array(
array('deleteOne' => array(array('_id' => 1))),
array('deleteMany' => array(array('_id' => array('$gt' => 2)))),
);
$ops = [
['deleteOne' => [['_id' => 1]]],
['deleteMany' => [['_id' => ['$gt' => 2]]]],
];
$result = $this->collection->bulkWrite($ops);
$this->assertInstanceOf('MongoDB\BulkWriteResult', $result);
$this->assertSame(3, $result->getDeletedCount());
$expected = array(
array('_id' => 2, 'x' => 22),
);
$expected = [
['_id' => 2, 'x' => 22],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......@@ -96,32 +96,32 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
{
$this->createFixtures(3);
$ops = array(
array('updateOne' => array(array('_id' => array('$gt' => 1)), array('$inc' => array('x' => 1)))),
array('updateMany' => array(array('_id' => array('$gt' => 1)), array('$inc' => array('x' => 1)))),
array('insertOne' => array(array('_id' => 4, 'x' => 44))),
array('deleteMany' => array(array('x' => array('$nin' => array(24, 34))))),
array('replaceOne' => array(array('_id' => 4), array('_id' => 4, 'x' => 44), array('upsert' => true))),
);
$ops = [
['updateOne' => [['_id' => ['$gt' => 1]], ['$inc' => ['x' => 1]]]],
['updateMany' => [['_id' => ['$gt' => 1]], ['$inc' => ['x' => 1]]]],
['insertOne' => [['_id' => 4, 'x' => 44]]],
['deleteMany' => [['x' => ['$nin' => [24, 34]]]]],
['replaceOne' => [['_id' => 4], ['_id' => 4, 'x' => 44], ['upsert' => true]]],
];
$result = $this->collection->bulkWrite($ops);
$this->assertInstanceOf('MongoDB\BulkWriteResult', $result);
$this->assertSame(1, $result->getInsertedCount());
$this->assertSame(array(2 => 4), $result->getInsertedIds());
$this->assertSame([2 => 4], $result->getInsertedIds());
$this->assertSame(3, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(3, $result->getModifiedCount());
$this->assertSame(1, $result->getUpsertedCount());
$this->assertSame(array(4 => 4), $result->getUpsertedIds());
$this->assertSame([4 => 4], $result->getUpsertedIds());
$this->assertSame(2, $result->getDeletedCount());
$expected = array(
array('_id' => 2, 'x' => 24),
array('_id' => 3, 'x' => 34),
array('_id' => 4, 'x' => 44),
);
$expected = [
['_id' => 2, 'x' => 24],
['_id' => 3, 'x' => 34],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......@@ -132,9 +132,9 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
*/
public function testUnknownOperation()
{
$this->collection->bulkWrite(array(
array('foo' => array(array('_id' => 1))),
));
$this->collection->bulkWrite([
['foo' => [['_id' => 1]]],
]);
}
/**
......@@ -149,17 +149,17 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
public function provideOpsWithMissingArguments()
{
return array(
array(array(array('insertOne' => array()))),
array(array(array('updateOne' => array()))),
array(array(array('updateOne' => array(array('_id' => 1))))),
array(array(array('updateMany' => array()))),
array(array(array('updateMany' => array(array('_id' => 1))))),
array(array(array('replaceOne' => array()))),
array(array(array('replaceOne' => array(array('_id' => 1))))),
array(array(array('deleteOne' => array()))),
array(array(array('deleteMany' => array()))),
);
return [
[[['insertOne' => []]]],
[[['updateOne' => []]]],
[[['updateOne' => [['_id' => 1]]]]],
[[['updateMany' => []]]],
[[['updateMany' => [['_id' => 1]]]]],
[[['replaceOne' => []]]],
[[['replaceOne' => [['_id' => 1]]]]],
[[['deleteOne' => []]]],
[[['deleteMany' => []]]],
];
}
/**
......@@ -168,9 +168,9 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
*/
public function testUpdateOneRequiresUpdateOperators()
{
$this->collection->bulkWrite(array(
array('updateOne' => array(array('_id' => 1), array('x' => 1))),
));
$this->collection->bulkWrite([
['updateOne' => [['_id' => 1], ['x' => 1]]],
]);
}
/**
......@@ -179,9 +179,9 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
*/
public function testUpdateManyRequiresUpdateOperators()
{
$this->collection->bulkWrite(array(
array('updateMany' => array(array('_id' => array('$gt' => 1)), array('x' => 1))),
));
$this->collection->bulkWrite([
['updateMany' => [['_id' => ['$gt' => 1]], ['x' => 1]]],
]);
}
/**
......@@ -190,9 +190,9 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
*/
public function testReplaceOneRequiresReplacementDocument()
{
$this->collection->bulkWrite(array(
array('replaceOne' => array(array('_id' => 1), array('$inc' => array('x' => 1)))),
));
$this->collection->bulkWrite([
['replaceOne' => [['_id' => 1], ['$inc' => ['x' => 1]]]],
]);
}
/**
......@@ -205,10 +205,10 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
$bulkWrite = new BulkWrite(['ordered' => true]);
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert(array(
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
));
]);
}
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
......
......@@ -22,13 +22,13 @@ class CollectionFunctionalTest extends FunctionalTestCase
public function provideInvalidNamespaceValues()
{
return array(
array(null),
array(''),
array('db_collection'),
array('db'),
array('.collection'),
);
return [
[null],
[''],
['db_collection'],
['db'],
['.collection'],
];
}
public function testToString()
......@@ -53,7 +53,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
public function testDrop()
{
$writeResult = $this->collection->insertOne(array('x' => 1));
$writeResult = $this->collection->insertOne(['x' => 1]);
$this->assertEquals(1, $writeResult->getInsertedCount());
$commandResult = $this->collection->drop();
......@@ -65,13 +65,13 @@ class CollectionFunctionalTest extends FunctionalTestCase
{
$this->createFixtures(5);
$filter = array('_id' => array('$lt' => 5));
$options = array(
$filter = ['_id' => ['$lt' => 5]];
$options = [
'skip' => 1,
'sort' => array('x' => -1),
);
'sort' => ['x' => -1],
];
$expected = (object) array('_id' => 3, 'x' => 33);
$expected = (object) ['_id' => 3, 'x' => 33];
$this->assertEquals($expected, $this->collection->findOne($filter, $options));
}
......@@ -86,10 +86,10 @@ class CollectionFunctionalTest extends FunctionalTestCase
$bulkWrite = new BulkWrite(['ordered' => true]);
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert(array(
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
));
]);
}
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
......
......@@ -25,17 +25,17 @@ class AggregateFunctionalTest extends FunctionalTestCase
public function testAggregateWithMultipleStages()
{
$cursor = $this->collection->aggregate(
array(
array('$sort' => array('x' => 1)),
array('$match' => array('_id' => array('$gt' => 1))),
),
array('batchSize' => 2)
[
['$sort' => ['x' => 1]],
['$match' => ['_id' => ['$gt' => 1]]],
],
['batchSize' => 2]
);
$expected = array(
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $cursor);
}
......@@ -53,17 +53,17 @@ class AggregateFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
$this->collection->aggregate(
array(
array('$sort' => array('x' => 1)),
array('$match' => array('_id' => array('$gt' => 1))),
array('$out' => $outputCollection->getCollectionName()),
)
[
['$sort' => ['x' => 1]],
['$match' => ['_id' => ['$gt' => 1]]],
['$out' => $outputCollection->getCollectionName()],
]
);
$expected = array(
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $outputCollection->find());
......
......@@ -23,15 +23,15 @@ class CountFunctionalTest extends FunctionalTestCase
public function testCountWithFilter()
{
$filter = array('_id' => array('$gt' => 1));
$filter = ['_id' => ['$gt' => 1]];
$this->assertSame(2, $this->collection->count($filter));
}
public function testCountWithSkipAndLimit()
{
$filter = array();
$options = array('skip' => 1, 'limit' => 3);
$filter = [];
$options = ['skip' => 1, 'limit' => 3];
$this->assertSame(2, $this->collection->count($filter, $options));
}
......
......@@ -18,30 +18,30 @@ class DeleteManyFunctionalTest extends FunctionalTestCase
public function testDeleteManyWhenManyDocumentsMatch()
{
$filter = array('_id' => array('$gt' => 1));
$filter = ['_id' => ['$gt' => 1]];
$result = $this->collection->deleteMany($filter);
$this->assertSame(2, $result->getDeletedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
);
$expected = [
['_id' => 1, 'x' => 11],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testDeleteManyWhenNoDocumentsMatch()
{
$filter = array('_id' => 4);
$filter = ['_id' => 4];
$result = $this->collection->deleteMany($filter);
$this->assertSame(0, $result->getDeletedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -18,46 +18,46 @@ class DeleteOneFunctionalTest extends FunctionalTestCase
public function testDeleteOneWhenManyDocumentsMatch()
{
$filter = array('_id' => array('$gt' => 1));
$filter = ['_id' => ['$gt' => 1]];
$result = $this->collection->deleteOne($filter);
$this->assertSame(1, $result->getDeletedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testDeleteOneWhenOneDocumentMatches()
{
$filter = array('_id' => 2);
$filter = ['_id' => 2];
$result = $this->collection->deleteOne($filter);
$this->assertSame(1, $result->getDeletedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testDeleteOneWhenNoDocumentsMatch()
{
$filter = array('_id' => 4);
$filter = ['_id' => 4];
$result = $this->collection->deleteOne($filter);
$this->assertSame(0, $result->getDeletedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -18,13 +18,13 @@ class DistinctFunctionalTest extends FunctionalTestCase
public function testDistinctWithoutFilter()
{
$this->assertSame(array(11, 22, 33), $this->collection->distinct('x'));
$this->assertSame([11, 22, 33], $this->collection->distinct('x'));
}
public function testDistinctWithFilter()
{
$filter = array('_id' => array('$gt' => 1));
$filter = ['_id' => ['$gt' => 1]];
$this->assertSame(array(22, 33), $this->collection->distinct('x', $filter));
$this->assertSame([22, 33], $this->collection->distinct('x', $filter));
}
}
......@@ -18,46 +18,46 @@ class FindFunctionalTest extends FunctionalTestCase
public function testFindWithFilter()
{
$filter = array('_id' => 1);
$filter = ['_id' => 1];
$expected = array(
array('_id' => 1, 'x' => 11),
);
$expected = [
['_id' => 1, 'x' => 11],
];
$this->assertSameDocuments($expected, $this->collection->find($filter));
}
public function testFindWithFilterSortSkipAndLimit()
{
$filter = array('_id' => array('$gt' => 2));
$options = array(
'sort' => array('_id' => 1),
$filter = ['_id' => ['$gt' => 2]];
$options = [
'sort' => ['_id' => 1],
'skip' => 2,
'limit' => 2,
);
];
$expected = array(
array('_id' => 5, 'x' => 55),
);
$expected = [
['_id' => 5, 'x' => 55],
];
$this->assertSameDocuments($expected, $this->collection->find($filter, $options));
}
public function testFindWithLimitSortAndBatchSize()
{
$filter = array();
$options = array(
'sort' => array('_id' => 1),
$filter = [];
$options = [
'sort' => ['_id' => 1],
'limit' => 4,
'batchSize' => 2,
);
];
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
array('_id' => 4, 'x' => 44),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find($filter, $options));
}
......
......@@ -18,58 +18,58 @@ class FindOneAndDeleteFunctionalTest extends FunctionalTestCase
public function testFindOneAndDeleteWhenManyDocumentsMatch()
{
$filter = array('_id' => array('$gt' => 1));
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
);
$filter = ['_id' => ['$gt' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndDelete($filter, $options);
$this->assertSameDocument(array('x' => 22), $document);
$this->assertSameDocument(['x' => 22], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndDeleteWhenOneDocumentMatches()
{
$filter = array('_id' => 2);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
);
$filter = ['_id' => 2];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndDelete($filter, $options);
$this->assertSameDocument(array('x' => 22), $document);
$this->assertSameDocument(['x' => 22], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndDeleteWhenNoDocumentsMatch()
{
$filter = array('_id' => 4);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
);
$filter = ['_id' => 4];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndDelete($filter, $options);
$this->assertNull($document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -21,178 +21,178 @@ class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentBeforeModification()
{
$filter = array('_id' => array('$gt' => 1));
$replacement = array('x' => 32);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
);
$filter = ['_id' => ['$gt' => 1]];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(array('x' => 22), $document);
$this->assertSameDocument(['x' => 22], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 32),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentAfterModification()
{
$filter = array('_id' => array('$gt' => 1));
$replacement = array('x' => 32);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$filter = ['_id' => ['$gt' => 1]];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
);
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(array('x' => 32), $document);
$this->assertSameDocument(['x' => 32], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 32),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentBeforeModification()
{
$filter = array('_id' => 2);
$replacement = array('x' => 32);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
);
$filter = ['_id' => 2];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(array('x' => 22), $document);
$this->assertSameDocument(['x' => 22], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 32),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentAfterModification()
{
$filter = array('_id' => 2);
$replacement = array('x' => 32);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$filter = ['_id' => 2];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
);
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(array('x' => 32), $document);
$this->assertSameDocument(['x' => 32], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 32),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = array('_id' => 4);
$replacement = array('x' => 44);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
);
$filter = ['_id' => 4];
$replacement = ['x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertNull($document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = array('_id' => 4);
$filter = ['_id' => 4];
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement = array('_id' => 4, 'x' => 44);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$replacement = ['_id' => 4, 'x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'upsert' => true,
);
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertNull($document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
array('_id' => 4, 'x' => 44),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = array('_id' => 4);
$replacement = array('x' => 44);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$filter = ['_id' => 4];
$replacement = ['x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
);
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertNull($document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = array('_id' => 4);
$filter = ['_id' => 4];
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement = array('_id' => 4, 'x' => 44);
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$replacement = ['_id' => 4, 'x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
'upsert' => true,
);
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(array('x' => 44), $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
array('_id' => 4, 'x' => 44),
);
$this->assertSameDocument(['x' => 44], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -21,176 +21,176 @@ class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentBeforeModification()
{
$filter = array('_id' => array('$gt' => 1));
$update = array('$inc' => array('x' => 1));
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
);
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(array('x' => 22), $document);
$this->assertSameDocument(['x' => 22], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 23),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentAfterModification()
{
$filter = array('_id' => array('$gt' => 1));
$update = array('$inc' => array('x' => 1));
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
);
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(array('x' => 23), $document);
$this->assertSameDocument(['x' => 23], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 23),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentBeforeModification()
{
$filter = array('_id' => 2);
$update = array('$inc' => array('x' => 1));
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
);
$filter = ['_id' => 2];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(array('x' => 22), $document);
$this->assertSameDocument(['x' => 22], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 23),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentAfterModification()
{
$filter = array('_id' => 2);
$update = array('$inc' => array('x' => 1));
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$filter = ['_id' => 2];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
);
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(array('x' => 23), $document);
$this->assertSameDocument(['x' => 23], $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 23),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = array('_id' => 4);
$update = array('$inc' => array('x' => 1));
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
);
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertNull($document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = array('_id' => 4);
$update = array('$inc' => array('x' => 1));
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'upsert' => true,
);
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertNull($document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
array('_id' => 4, 'x' => 1),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = array('_id' => 4);
$update = array('$inc' => array('x' => 1));
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
);
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertNull($document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = array('_id' => 4);
$update = array('$inc' => array('x' => 1));
$options = array(
'projection' => array('x' => 1, '_id' => 0),
'sort' => array('x' => 1),
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
'upsert' => true,
);
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(array('x' => 1), $document);
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
array('_id' => 4, 'x' => 1),
);
$this->assertSameDocument(['x' => 1], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -20,10 +20,10 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
$bulkWrite = new BulkWrite(['ordered' => true]);
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert(array(
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
));
]);
}
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
......
......@@ -18,20 +18,20 @@ class InsertManyFunctionalTest extends FunctionalTestCase
public function testInsertManyWithNonexistentDocuments()
{
$documents = array(
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$documents = [
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$result = $this->collection->insertMany($documents);
$this->assertSame(2, $result->getInsertedCount());
$this->assertSame(array(2, 3), $result->getInsertedIds());
$this->assertSame([2, 3], $result->getInsertedIds());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -18,16 +18,16 @@ class InsertOneFunctionalTest extends FunctionalTestCase
public function testInsertOneWithANonexistentDocument()
{
$document = array('_id' => 2, 'x' => 22);
$document = ['_id' => 2, 'x' => 22];
$result = $this->collection->insertOne($document);
$this->assertSame(1, $result->getInsertedCount());
$this->assertSame(2, $result->getInsertedId());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -22,97 +22,97 @@ class ReplaceOneFunctionalTest extends FunctionalTestCase
public function testReplaceOneWhenManyDocumentsMatch()
{
$filter = array('_id' => array('$gt' => 1));
$replacement = array('x' => 111);
$filter = ['_id' => ['$gt' => 1]];
$replacement = ['x' => 111];
$result = $this->collection->replaceOne($filter, $replacement);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 111),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 111],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWhenOneDocumentMatches()
{
$filter = array('_id' => 1);
$replacement = array('x' => 111);
$filter = ['_id' => 1];
$replacement = ['x' => 111];
$result = $this->collection->replaceOne($filter, $replacement);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = array(
array('_id' => 1, 'x' => 111),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 111],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWhenNoDocumentsMatch()
{
$filter = array('_id' => 4);
$replacement = array('x' => 111);
$filter = ['_id' => 4];
$replacement = ['x' => 111];
$result = $this->collection->replaceOne($filter, $replacement);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWithUpsertWhenNoDocumentsMatchWithAnIdSpecified()
{
$filter = array('_id' => 4);
$replacement = array('_id' => 4, 'x' => 1);
$options = array('upsert' => true);
$filter = ['_id' => 4];
$replacement = ['_id' => 4, 'x' => 1];
$options = ['upsert' => true];
$result = $this->collection->replaceOne($filter, $replacement, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
array('_id' => 4, 'x' => 1),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWithUpsertWhenNoDocumentsMatchWithoutAnIdSpecified()
{
$filter = array('_id' => 4);
$filter = ['_id' => 4];
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement = array('_id' => 4, 'x' => 1);
$options = array('upsert' => true);
$replacement = ['_id' => 4, 'x' => 1];
$options = ['upsert' => true];
$result = $this->collection->replaceOne($filter, $replacement, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
array('_id' => 4, 'x' => 1),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -22,75 +22,75 @@ class UpdateManyFunctionalTest extends FunctionalTestCase
public function testUpdateManyWhenManyDocumentsMatch()
{
$filter = array('_id' => array('$gt' => 1));
$update = array('$inc' => array('x' => 1));
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateMany($filter, $update);
$this->assertSame(2, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(2, $result->getModifiedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 23),
array('_id' => 3, 'x' => 34),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 34],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateManyWhenOneDocumentMatches()
{
$filter = array('_id' => 1);
$update = array('$inc' => array('x' => 1));
$filter = ['_id' => 1];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateMany($filter, $update);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = array(
array('_id' => 1, 'x' => 12),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 12],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateManyWhenNoDocumentsMatch()
{
$filter = array('_id' => 4);
$update = array('$inc' => array('x' => 1));
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateMany($filter, $update);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateManyWithUpsertWhenNoDocumentsMatch()
{
$filter = array('_id' => 4);
$update = array('$inc' => array('x' => 1));
$options = array('upsert' => true);
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = ['upsert' => true];
$result = $this->collection->updateMany($filter, $update, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
array('_id' => 4, 'x' => 1),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -22,75 +22,75 @@ class UpdateOneFunctionalTest extends FunctionalTestCase
public function testUpdateOneWhenManyDocumentsMatch()
{
$filter = array('_id' => array('$gt' => 1));
$update = array('$inc' => array('x' => 1));
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateOne($filter, $update);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 23),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateOneWhenOneDocumentMatches()
{
$filter = array('_id' => 1);
$update = array('$inc' => array('x' => 1));
$filter = ['_id' => 1];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateOne($filter, $update);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = array(
array('_id' => 1, 'x' => 12),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 12],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateOneWhenNoDocumentsMatch()
{
$filter = array('_id' => 4);
$update = array('$inc' => array('x' => 1));
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateOne($filter, $update);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateOneWithUpsertWhenNoDocumentsMatch()
{
$filter = array('_id' => 4);
$update = array('$inc' => array('x' => 1));
$options = array('upsert' => true);
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = ['upsert' => true];
$result = $this->collection->updateOne($filter, $update, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = array(
array('_id' => 1, 'x' => 11),
array('_id' => 2, 'x' => 22),
array('_id' => 3, 'x' => 33),
array('_id' => 4, 'x' => 1),
);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
......
......@@ -16,28 +16,28 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
{
$that = $this;
$this->assertSame('x_1', $this->collection->createIndex(array('x' => 1), array('sparse' => true, 'unique' => true)));
$this->assertSame('x_1', $this->collection->createIndex(['x' => 1], ['sparse' => true, 'unique' => true]));
$this->assertIndexExists('x_1', function(IndexInfo $info) use ($that) {
$that->assertTrue($info->isSparse());
$that->assertTrue($info->isUnique());
$that->assertFalse($info->isTtl());
});
$this->assertSame('y_-1_z_1', $this->collection->createIndex(array('y' => -1, 'z' => 1)));
$this->assertSame('y_-1_z_1', $this->collection->createIndex(['y' => -1, 'z' => 1]));
$this->assertIndexExists('y_-1_z_1', function(IndexInfo $info) use ($that) {
$that->assertFalse($info->isSparse());
$that->assertFalse($info->isUnique());
$that->assertFalse($info->isTtl());
});
$this->assertSame('g_2dsphere_z_1', $this->collection->createIndex(array('g' => '2dsphere', 'z' => 1)));
$this->assertSame('g_2dsphere_z_1', $this->collection->createIndex(['g' => '2dsphere', 'z' => 1]));
$this->assertIndexExists('g_2dsphere_z_1', function(IndexInfo $info) use ($that) {
$that->assertFalse($info->isSparse());
$that->assertFalse($info->isUnique());
$that->assertFalse($info->isTtl());
});
$this->assertSame('my_ttl', $this->collection->createIndex(array('t' => 1), array('expireAfterSeconds' => 0, 'name' => 'my_ttl')));
$this->assertSame('my_ttl', $this->collection->createIndex(['t' => 1], ['expireAfterSeconds' => 0, 'name' => 'my_ttl']));
$this->assertIndexExists('my_ttl', function(IndexInfo $info) use ($that) {
$that->assertFalse($info->isSparse());
$that->assertFalse($info->isUnique());
......@@ -49,14 +49,14 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
{
$that = $this;
$expectedNames = array('x_1', 'y_-1_z_1', 'g_2dsphere_z_1', 'my_ttl');
$expectedNames = ['x_1', 'y_-1_z_1', 'g_2dsphere_z_1', 'my_ttl'];
$indexes = array(
array('key' => array('x' => 1), 'sparse' => true, 'unique' => true),
array('key' => array('y' => -1, 'z' => 1)),
array('key' => array('g' => '2dsphere', 'z' => 1)),
array('key' => array('t' => 1), 'expireAfterSeconds' => 0, 'name' => 'my_ttl'),
);
$indexes = [
['key' => ['x' => 1], 'sparse' => true, 'unique' => true],
['key' => ['y' => -1, 'z' => 1]],
['key' => ['g' => '2dsphere', 'z' => 1]],
['key' => ['t' => 1], 'expireAfterSeconds' => 0, 'name' => 'my_ttl'],
];
$this->assertSame($expectedNames, $this->collection->createIndexes($indexes));
......@@ -90,12 +90,12 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
*/
public function testCreateIndexesRequiresAtLeastOneIndex()
{
$this->assertSame(array(), $this->collection->createIndexes(array()));
$this->assertSame([], $this->collection->createIndexes([]));
}
public function testDropIndex()
{
$this->assertSame('x_1', $this->collection->createIndex(array('x' => 1)));
$this->assertSame('x_1', $this->collection->createIndex(['x' => 1]));
$this->assertIndexExists('x_1');
$this->assertCommandSucceeded($this->collection->dropIndex('x_1'));
......@@ -111,7 +111,7 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
*/
public function testDropIndexShouldNotAllowEmptyIndexName()
{
$this->assertSame('x_1', $this->collection->createIndex(array('x' => 1)));
$this->assertSame('x_1', $this->collection->createIndex(['x' => 1]));
$this->assertIndexExists('x_1');
$this->collection->dropIndex('');
}
......@@ -121,15 +121,15 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
*/
public function testDropIndexShouldNotAllowWildcardCharacter()
{
$this->assertSame('x_1', $this->collection->createIndex(array('x' => 1)));
$this->assertSame('x_1', $this->collection->createIndex(['x' => 1]));
$this->assertIndexExists('x_1');
$this->collection->dropIndex('*');
}
public function testDropIndexes()
{
$this->assertSame('x_1', $this->collection->createIndex(array('x' => 1)));
$this->assertSame('y_1', $this->collection->createIndex(array('y' => 1)));
$this->assertSame('x_1', $this->collection->createIndex(['x' => 1]));
$this->assertSame('y_1', $this->collection->createIndex(['y' => 1]));
$this->assertIndexExists('x_1');
$this->assertIndexExists('y_1');
$this->assertCommandSucceeded($this->collection->dropIndexes());
......@@ -147,7 +147,7 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
public function testListIndexes()
{
$this->assertSame('x_1', $this->collection->createIndex(array('x' => 1)));
$this->assertSame('x_1', $this->collection->createIndex(['x' => 1]));
$indexes = $this->collection->listIndexes();
$this->assertInstanceOf('MongoDB\Model\IndexInfoIterator', $indexes);
......
......@@ -23,11 +23,11 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase
});
$cappedCollectionName = $this->getCollectionName() . '.capped';
$cappedCollectionOptions = array(
$cappedCollectionOptions = [
'capped' => true,
'max' => 100,
'size' => 1048576,
);
];
$commandResult = $this->database->createCollection($cappedCollectionName, $cappedCollectionOptions);
$this->assertCommandSucceeded($commandResult);
......@@ -70,7 +70,7 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase
$this->assertCommandSucceeded($commandResult);
$collectionName = $this->getCollectionName();
$options = array('filter' => array('name' => $collectionName));
$options = ['filter' => ['name' => $collectionName]];
$collections = $this->database->listCollections($options);
$this->assertInstanceOf('MongoDB\Model\CollectionInfoIterator', $collections);
......
......@@ -22,10 +22,10 @@ class DatabaseFunctionalTest extends FunctionalTestCase
public function provideInvalidDatabaseValues()
{
return array(
array(null),
array(''),
);
return [
[null],
[''],
];
}
public function testToString()
......
......@@ -22,8 +22,8 @@ abstract class FunctionalTestCase extends TestCase
{
list($databaseName, $collectionName) = explode('.', $namespace, 2);
$cursor = $this->manager->executeCommand($databaseName, new Command(array('count' => $collectionName)));
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
$cursor = $this->manager->executeCommand($databaseName, new Command(['count' => $collectionName]));
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
$document = current($cursor->toArray());
$this->assertArrayHasKey('n', $document);
......@@ -77,11 +77,11 @@ abstract class FunctionalTestCase extends TestCase
{
$cursor = $this->manager->executeCommand(
$this->getDatabaseName(),
new Command(array('buildInfo' => 1)),
new Command(['buildInfo' => 1]),
$readPreference ?: new ReadPreference(ReadPreference::RP_PRIMARY)
);
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
$document = current($cursor->toArray());
return $document['version'];
......
......@@ -9,32 +9,32 @@ class CollectionInfoTest extends TestCase
{
public function testGetName()
{
$info = new CollectionInfo(array('name' => 'foo'));
$info = new CollectionInfo(['name' => 'foo']);
$this->assertSame('foo', $info->getName());
}
public function testGetOptions()
{
$info = new CollectionInfo(array('name' => 'foo'));
$this->assertSame(array(), $info->getOptions());
$info = new CollectionInfo(['name' => 'foo']);
$this->assertSame([], $info->getOptions());
$info = new CollectionInfo(array('name' => 'foo', 'options' => array('capped' => true, 'size' => 1048576)));
$this->assertSame(array('capped' => true, 'size' => 1048576), $info->getOptions());
$info = new CollectionInfo(['name' => 'foo', 'options' => ['capped' => true, 'size' => 1048576]]);
$this->assertSame(['capped' => true, 'size' => 1048576], $info->getOptions());
}
public function testCappedCollectionMethods()
{
$info = new CollectionInfo(array('name' => 'foo'));
$info = new CollectionInfo(['name' => 'foo']);
$this->assertFalse($info->isCapped());
$this->assertNull($info->getCappedMax());
$this->assertNull($info->getCappedSize());
$info = new CollectionInfo(array('name' => 'foo', 'options' => array('capped' => true, 'size' => 1048576)));
$info = new CollectionInfo(['name' => 'foo', 'options' => ['capped' => true, 'size' => 1048576]]);
$this->assertTrue($info->isCapped());
$this->assertNull($info->getCappedMax());
$this->assertSame(1048576, $info->getCappedSize());
$info = new CollectionInfo(array('name' => 'foo', 'options' => array('capped' => true, 'size' => 1048576, 'max' => 100)));
$info = new CollectionInfo(['name' => 'foo', 'options' => ['capped' => true, 'size' => 1048576, 'max' => 100]]);
$this->assertTrue($info->isCapped());
$this->assertSame(100, $info->getCappedMax());
$this->assertSame(1048576, $info->getCappedSize());
......@@ -42,10 +42,10 @@ class CollectionInfoTest extends TestCase
public function testDebugInfo()
{
$expectedInfo = array(
$expectedInfo = [
'name' => 'foo',
'options' => array('capped' => true, 'size' => 1048576),
);
'options' => ['capped' => true, 'size' => 1048576],
];
$info = new CollectionInfo($expectedInfo);
$this->assertSame($expectedInfo, $info->__debugInfo());
......
......@@ -9,32 +9,32 @@ class DatabaseInfoTest extends TestCase
{
public function testGetName()
{
$info = new DatabaseInfo(array('name' => 'foo'));
$info = new DatabaseInfo(['name' => 'foo']);
$this->assertSame('foo', $info->getName());
}
public function testGetSizeOnDisk()
{
$info = new DatabaseInfo(array('sizeOnDisk' => 1048576));
$info = new DatabaseInfo(['sizeOnDisk' => 1048576]);
$this->assertSame(1048576, $info->getSizeOnDisk());
}
public function testIsEmpty()
{
$info = new DatabaseInfo(array('empty' => false));
$info = new DatabaseInfo(['empty' => false]);
$this->assertFalse($info->isEmpty());
$info = new DatabaseInfo(array('empty' => true));
$info = new DatabaseInfo(['empty' => true]);
$this->assertTrue($info->isEmpty());
}
public function testDebugInfo()
{
$expectedInfo = array(
$expectedInfo = [
'name' => 'foo',
'sizeOnDisk' => 1048576,
'empty' => false,
);
];
$info = new DatabaseInfo($expectedInfo);
$this->assertSame($expectedInfo, $info->__debugInfo());
......
......@@ -9,15 +9,15 @@ class IndexInfoTest extends TestCase
{
public function testBasicIndex()
{
$info = new IndexInfo(array(
$info = new IndexInfo([
'v' => 1,
'key' => array('x' => 1),
'key' => ['x' => 1],
'name' => 'x_1',
'ns' => 'foo.bar',
));
]);
$this->assertSame(1, $info->getVersion());
$this->assertSame(array('x' => 1), $info->getKey());
$this->assertSame(['x' => 1], $info->getKey());
$this->assertSame('x_1', $info->getName());
$this->assertSame('foo.bar', $info->getNamespace());
$this->assertFalse($info->isSparse());
......@@ -27,16 +27,16 @@ class IndexInfoTest extends TestCase
public function testSparseIndex()
{
$info = new IndexInfo(array(
$info = new IndexInfo([
'v' => 1,
'key' => array('y' => 1),
'key' => ['y' => 1],
'name' => 'y_sparse',
'ns' => 'foo.bar',
'sparse' => true,
));
]);
$this->assertSame(1, $info->getVersion());
$this->assertSame(array('y' => 1), $info->getKey());
$this->assertSame(['y' => 1], $info->getKey());
$this->assertSame('y_sparse', $info->getName());
$this->assertSame('foo.bar', $info->getNamespace());
$this->assertTrue($info->isSparse());
......@@ -46,16 +46,16 @@ class IndexInfoTest extends TestCase
public function testUniqueIndex()
{
$info = new IndexInfo(array(
$info = new IndexInfo([
'v' => 1,
'key' => array('z' => 1),
'key' => ['z' => 1],
'name' => 'z_unique',
'ns' => 'foo.bar',
'unique' => true,
));
]);
$this->assertSame(1, $info->getVersion());
$this->assertSame(array('z' => 1), $info->getKey());
$this->assertSame(['z' => 1], $info->getKey());
$this->assertSame('z_unique', $info->getName());
$this->assertSame('foo.bar', $info->getNamespace());
$this->assertFalse($info->isSparse());
......@@ -65,16 +65,16 @@ class IndexInfoTest extends TestCase
public function testTtlIndex()
{
$info = new IndexInfo(array(
$info = new IndexInfo([
'v' => 1,
'key' => array('z' => 1),
'key' => ['z' => 1],
'name' => 'z_unique',
'ns' => 'foo.bar',
'expireAfterSeconds' => 100,
));
]);
$this->assertSame(1, $info->getVersion());
$this->assertSame(array('z' => 1), $info->getKey());
$this->assertSame(['z' => 1], $info->getKey());
$this->assertSame('z_unique', $info->getName());
$this->assertSame('foo.bar', $info->getNamespace());
$this->assertFalse($info->isSparse());
......@@ -86,12 +86,12 @@ class IndexInfoTest extends TestCase
public function testDebugInfo()
{
$expectedInfo = array(
$expectedInfo = [
'v' => 1,
'key' => array('x' => 1),
'key' => ['x' => 1],
'name' => 'x_1',
'ns' => 'foo.bar',
);
];
$info = new IndexInfo($expectedInfo);
$this->assertSame($expectedInfo, $info->__debugInfo());
......
......@@ -12,7 +12,7 @@ class IndexInputTest extends TestCase
*/
public function testConstructorShouldRequireKey()
{
new IndexInput(array());
new IndexInput([]);
}
/**
......@@ -20,7 +20,7 @@ class IndexInputTest extends TestCase
*/
public function testConstructorShouldRequireKeyToBeArrayOrObject()
{
new IndexInput(array('key' => 'foo'));
new IndexInput(['key' => 'foo']);
}
/**
......@@ -28,7 +28,7 @@ class IndexInputTest extends TestCase
*/
public function testConstructorShouldRequireKeyOrderToBeScalar()
{
new IndexInput(array('key' => array('x' => array())));
new IndexInput(['key' => ['x' => []]]);
}
/**
......@@ -36,7 +36,7 @@ class IndexInputTest extends TestCase
*/
public function testConstructorShouldRequireNamespace()
{
new IndexInput(array('key' => array('x' => 1)));
new IndexInput(['key' => ['x' => 1]]);
}
/**
......@@ -44,7 +44,7 @@ class IndexInputTest extends TestCase
*/
public function testConstructorShouldRequireNamespaceToBeString()
{
new IndexInput(array('key' => array('x' => 1), 'ns' => 1));
new IndexInput(['key' => ['x' => 1], 'ns' => 1]);
}
/**
......@@ -52,7 +52,7 @@ class IndexInputTest extends TestCase
*/
public function testConstructorShouldRequireNameToBeString()
{
new IndexInput(array('key' => array('x' => 1), 'ns' => 'foo.bar', 'name' => 1));
new IndexInput(['key' => ['x' => 1], 'ns' => 'foo.bar', 'name' => 1]);
}
/**
......@@ -60,32 +60,32 @@ class IndexInputTest extends TestCase
*/
public function testNameGeneration($expectedName, array $key)
{
$this->assertSame($expectedName, (string) new IndexInput(array('key' => $key, 'ns' => 'foo.bar')));
$this->assertSame($expectedName, (string) new IndexInput(['key' => $key, 'ns' => 'foo.bar']));
}
public function provideExpectedNameAndKey()
{
return array(
array('x_1', array('x' => 1)),
array('x_1_y_-1', array('x' => 1, 'y' => -1)),
array('loc_2dsphere', array('loc' => '2dsphere')),
array('loc_2dsphere_x_1', array('loc' => '2dsphere', 'x' => 1)),
array('doc_text', array('doc' => 'text')),
);
return [
['x_1', ['x' => 1]],
['x_1_y_-1', ['x' => 1, 'y' => -1]],
['loc_2dsphere', ['loc' => '2dsphere']],
['loc_2dsphere_x_1', ['loc' => '2dsphere', 'x' => 1]],
['doc_text', ['doc' => 'text']],
];
}
public function testBsonSerialization()
{
$expected = array(
'key' => array('x' => 1),
$expected = [
'key' => ['x' => 1],
'ns' => 'foo.bar',
'name' => 'x_1',
);
];
$indexInput = new IndexInput(array(
'key' => array('x' => 1),
$indexInput = new IndexInput([
'key' => ['x' => 1],
'ns' => 'foo.bar',
));
]);
$this->assertInstanceOf('MongoDB\BSON\Serializable', $indexInput);
$this->assertEquals($expected, $indexInput->bsonSerialize());
......
......@@ -12,7 +12,7 @@ class AggregateTest extends TestCase
*/
public function testConstructorPipelineArgumentMustNotBeEmpty()
{
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), array());
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), []);
}
/**
......@@ -21,7 +21,7 @@ class AggregateTest extends TestCase
*/
public function testConstructorPipelineArgumentMustBeAList()
{
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), array(1 => array('$match' => array('x' => 1))));
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [1 => ['$match' => ['x' => 1]]]);
}
/**
......@@ -30,31 +30,31 @@ class AggregateTest extends TestCase
*/
public function testConstructorOptionTypeChecks(array $options)
{
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), array(array('$match' => array('x' => 1))), $options);
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [['$match' => ['x' => 1]]], $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
$options = [];
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('allowDiskUse' => $value);
$options[][] = ['allowDiskUse' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('batchSize' => $value);
$options[][] = ['batchSize' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('maxTimeMS' => $value);
$options[][] = ['maxTimeMS' => $value];
}
foreach ($this->getInvalidReadPreferenceValues() as $value) {
$options[][] = array('readPreference' => $value);
$options[][] = ['readPreference' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('useCursor' => $value);
$options[][] = ['useCursor' => $value];
}
return $options;
......@@ -69,8 +69,8 @@ class AggregateTest extends TestCase
new Aggregate(
$this->getDatabaseName(),
$this->getCollectionName(),
array(array('$match' => array('x' => 1))),
array('batchSize' => 100, 'useCursor' => false)
[['$match' => ['x' => 1]]],
['batchSize' => 100, 'useCursor' => false]
);
}
}
......@@ -12,7 +12,7 @@ class BulkWriteTest extends TestCase
*/
public function testOperationsMustNotBeEmpty()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array());
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), []);
}
/**
......@@ -21,9 +21,9 @@ class BulkWriteTest extends TestCase
*/
public function testOperationsMustBeAList()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
1 => array(BulkWrite::INSERT_ONE => array(array('x' => 1))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
1 => [BulkWrite::INSERT_ONE => [['x' => 1]]],
]);
}
/**
......@@ -32,12 +32,12 @@ class BulkWriteTest extends TestCase
*/
public function testMultipleOperationsInOneElement()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(
BulkWrite::INSERT_ONE => array(array('x' => 1)),
BulkWrite::DELETE_ONE => array(array('x' => 1)),
),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[
BulkWrite::INSERT_ONE => [['x' => 1]],
BulkWrite::DELETE_ONE => [['x' => 1]],
],
]);
}
/**
......@@ -46,9 +46,9 @@ class BulkWriteTest extends TestCase
*/
public function testUnknownOperation()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array('foo' => array(array('_id' => 1))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
['foo' => [['_id' => 1]]],
]);
}
/**
......@@ -57,9 +57,9 @@ class BulkWriteTest extends TestCase
*/
public function testInsertOneDocumentArgumentMissing()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::INSERT_ONE => array()),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::INSERT_ONE => []],
]);
}
/**
......@@ -69,9 +69,9 @@ class BulkWriteTest extends TestCase
*/
public function testInsertOneDocumentArgumentTypeCheck($document)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::INSERT_ONE => array($document)),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::INSERT_ONE => [$document]],
]);
}
/**
......@@ -80,9 +80,9 @@ class BulkWriteTest extends TestCase
*/
public function testDeleteManyFilterArgumentMissing()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::DELETE_MANY => array()),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::DELETE_MANY => []],
]);
}
/**
......@@ -92,9 +92,9 @@ class BulkWriteTest extends TestCase
*/
public function testDeleteManyFilterArgumentTypeCheck($document)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::DELETE_MANY => array($document)),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::DELETE_MANY => [$document]],
]);
}
/**
......@@ -103,9 +103,9 @@ class BulkWriteTest extends TestCase
*/
public function testDeleteOneFilterArgumentMissing()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::DELETE_ONE => array()),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::DELETE_ONE => []],
]);
}
/**
......@@ -115,9 +115,9 @@ class BulkWriteTest extends TestCase
*/
public function testDeleteOneFilterArgumentTypeCheck($document)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::DELETE_ONE => array($document)),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::DELETE_ONE => [$document]],
]);
}
/**
......@@ -126,9 +126,9 @@ class BulkWriteTest extends TestCase
*/
public function testReplaceOneFilterArgumentMissing()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::REPLACE_ONE => array()),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::REPLACE_ONE => []],
]);
}
/**
......@@ -138,9 +138,9 @@ class BulkWriteTest extends TestCase
*/
public function testReplaceOneFilterArgumentTypeCheck($filter)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::REPLACE_ONE => array($filter, array('y' => 1))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::REPLACE_ONE => [$filter, ['y' => 1]]],
]);
}
/**
......@@ -149,9 +149,9 @@ class BulkWriteTest extends TestCase
*/
public function testReplaceOneReplacementArgumentMissing()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::REPLACE_ONE => array(array('x' => 1))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::REPLACE_ONE => [['x' => 1]]],
]);
}
/**
......@@ -161,9 +161,9 @@ class BulkWriteTest extends TestCase
*/
public function testReplaceOneReplacementArgumentTypeCheck($replacement)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::REPLACE_ONE => array(array('x' => 1), $replacement)),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::REPLACE_ONE => [['x' => 1], $replacement]],
]);
}
/**
......@@ -172,9 +172,9 @@ class BulkWriteTest extends TestCase
*/
public function testReplaceOneReplacementArgumentRequiresNoOperators()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::REPLACE_ONE => array(array('_id' => 1), array('$inc' => array('x' => 1)))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::REPLACE_ONE => [['_id' => 1], ['$inc' => ['x' => 1]]]],
]);
}
/**
......@@ -184,9 +184,9 @@ class BulkWriteTest extends TestCase
*/
public function testReplaceOneUpsertOptionTypeCheck($upsert)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::REPLACE_ONE => array(array('x' => 1), array('y' => 1), array('upsert' => $upsert))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::REPLACE_ONE => [['x' => 1], ['y' => 1], ['upsert' => $upsert]]],
]);
}
/**
......@@ -195,9 +195,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateManyFilterArgumentMissing()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_MANY => array()),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_MANY => []],
]);
}
/**
......@@ -207,9 +207,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateManyFilterArgumentTypeCheck($filter)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_MANY => array($filter, array('$set' => array('x' => 1)))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_MANY => [$filter, ['$set' => ['x' => 1]]]],
]);
}
/**
......@@ -218,9 +218,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateManyUpdateArgumentMissing()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_MANY => array(array('x' => 1))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_MANY => [['x' => 1]]],
]);
}
/**
......@@ -230,9 +230,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateManyUpdateArgumentTypeCheck($update)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_MANY => array(array('x' => 1), $update)),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_MANY => [['x' => 1], $update]],
]);
}
/**
......@@ -241,9 +241,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateManyUpdateArgumentRequiresOperators()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_MANY => array(array('_id' => array('$gt' => 1)), array('x' => 1))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_MANY => [['_id' => ['$gt' => 1]], ['x' => 1]]],
]);
}
/**
......@@ -253,9 +253,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateManyUpsertOptionTypeCheck($upsert)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_MANY => array(array('x' => 1), array('$set' => array('x' => 1)), array('upsert' => $upsert))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_MANY => [['x' => 1], ['$set' => ['x' => 1]], ['upsert' => $upsert]]],
]);
}
/**
......@@ -264,9 +264,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateOneFilterArgumentMissing()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_ONE => array()),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_ONE => []],
]);
}
/**
......@@ -276,9 +276,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateOneFilterArgumentTypeCheck($filter)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_ONE => array($filter, array('$set' => array('x' => 1)))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_ONE => [$filter, ['$set' => ['x' => 1]]]],
]);
}
/**
......@@ -287,9 +287,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateOneUpdateArgumentMissing()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_ONE => array(array('x' => 1))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_ONE => [['x' => 1]]],
]);
}
/**
......@@ -299,9 +299,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateOneUpdateArgumentTypeCheck($update)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_ONE => array(array('x' => 1), $update)),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_ONE => [['x' => 1], $update]],
]);
}
/**
......@@ -310,9 +310,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateOneUpdateArgumentRequiresOperators()
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_ONE => array(array('_id' => 1), array('x' => 1))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_ONE => [['_id' => 1], ['x' => 1]]],
]);
}
/**
......@@ -322,9 +322,9 @@ class BulkWriteTest extends TestCase
*/
public function testUpdateOneUpsertOptionTypeCheck($upsert)
{
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_ONE => array(array('x' => 1), array('$set' => array('x' => 1)), array('upsert' => $upsert))),
));
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
[BulkWrite::UPDATE_ONE => [['x' => 1], ['$set' => ['x' => 1]], ['upsert' => $upsert]]],
]);
}
/**
......@@ -336,21 +336,21 @@ class BulkWriteTest extends TestCase
new BulkWrite(
$this->getDatabaseName(),
$this->getCollectionName(),
array(array(BulkWrite::INSERT_ONE => array(array('x' => 1)))),
[[BulkWrite::INSERT_ONE => [['x' => 1]]]],
$options
);
}
public function provideInvalidConstructorOptions()
{
$options = array();
$options = [];
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('ordered' => $value);
$options[][] = ['ordered' => $value];
}
foreach ($this->getInvalidWriteConcernValues() as $value) {
$options[][] = array('writeConcern' => $value);
$options[][] = ['writeConcern' => $value];
}
return $options;
......
......@@ -21,31 +21,31 @@ class CountTest extends TestCase
*/
public function testConstructorOptionTypeChecks(array $options)
{
new Count($this->getDatabaseName(), $this->getCollectionName(), array(), $options);
new Count($this->getDatabaseName(), $this->getCollectionName(), [], $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
$options = [];
foreach ($this->getInvalidHintValues() as $value) {
$options[][] = array('hint' => $value);
$options[][] = ['hint' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('limit' => $value);
$options[][] = ['limit' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('maxTimeMS' => $value);
$options[][] = ['maxTimeMS' => $value];
}
foreach ($this->getInvalidReadPreferenceValues() as $value) {
$options[][] = array('readPreference' => $value);
$options[][] = ['readPreference' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('skip' => $value);
$options[][] = ['skip' => $value];
}
return $options;
......@@ -53,6 +53,6 @@ class CountTest extends TestCase
private function getInvalidHintValues()
{
return array(123, 3.14, true);
return [123, 3.14, true];
}
}
......@@ -22,12 +22,12 @@ class DeleteTest extends TestCase
*/
public function testConstructorLimitArgumentMustBeOneOrZero($limit)
{
new Delete($this->getDatabaseName(), $this->getCollectionName(), array(), $limit);
new Delete($this->getDatabaseName(), $this->getCollectionName(), [], $limit);
}
public function provideInvalidLimitValues()
{
return $this->wrapValuesForDataProvider(array_merge($this->getInvalidIntegerValues(), array(-1, 2)));
return $this->wrapValuesForDataProvider(array_merge($this->getInvalidIntegerValues(), [-1, 2]));
}
/**
......@@ -36,15 +36,15 @@ class DeleteTest extends TestCase
*/
public function testConstructorOptionTypeChecks(array $options)
{
new Delete($this->getDatabaseName(), $this->getCollectionName(), array(), 1, $options);
new Delete($this->getDatabaseName(), $this->getCollectionName(), [], 1, $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
$options = [];
foreach ($this->getInvalidWriteConcernValues() as $value) {
$options[][] = array('writeConcern' => $value);
$options[][] = ['writeConcern' => $value];
}
return $options;
......
......@@ -21,19 +21,19 @@ class DistinctTest extends TestCase
*/
public function testConstructorOptionTypeChecks(array $options)
{
new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', array(), $options);
new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', [], $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
$options = [];
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('maxTimeMS' => $value);
$options[][] = ['maxTimeMS' => $value];
}
foreach ($this->getInvalidReadPreferenceValues() as $value) {
$options[][] = array('readPreference' => $value);
$options[][] = ['readPreference' => $value];
}
return $options;
......
......@@ -21,59 +21,59 @@ class FindTest extends TestCase
*/
public function testConstructorOptionTypeChecks(array $options)
{
new Find($this->getDatabaseName(), $this->getCollectionName(), array(), $options);
new Find($this->getDatabaseName(), $this->getCollectionName(), [], $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
$options = [];
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('allowPartialResults' => $value);
$options[][] = ['allowPartialResults' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('batchSize' => $value);
$options[][] = ['batchSize' => $value];
}
foreach ($this->getInvalidStringValues() as $value) {
$options[][] = array('comment' => $value);
$options[][] = ['comment' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('cursorType' => $value);
$options[][] = ['cursorType' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('limit' => $value);
$options[][] = ['limit' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('maxTimeMS' => $value);
$options[][] = ['maxTimeMS' => $value];
}
foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = array('modifiers' => $value);
$options[][] = ['modifiers' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('oplogReplay' => $value);
$options[][] = ['oplogReplay' => $value];
}
foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = array('projection' => $value);
$options[][] = ['projection' => $value];
}
foreach ($this->getInvalidReadPreferenceValues() as $value) {
$options[][] = array('readPreference' => $value);
$options[][] = ['readPreference' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = array('skip' => $value);
$options[][] = ['skip' => $value];
}
foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = array('sort' => $value);
$options[][] = ['sort' => $value];
}
return $options;
......@@ -85,11 +85,11 @@ class FindTest extends TestCase
*/
public function testConstructorCursorTypeOption($cursorType)
{
new Find($this->getDatabaseName(), $this->getCollectionName(), array(), array('cursorType' => $cursorType));
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['cursorType' => $cursorType]);
}
public function provideInvalidConstructorCursorTypeOptions()
{
return $this->wrapValuesForDataProvider(array(-1, 0, 4));
return $this->wrapValuesForDataProvider([-1, 0, 4]);
}
}
......@@ -12,7 +12,7 @@ class InsertManyTest extends TestCase
*/
public function testConstructorDocumentsMustNotBeEmpty()
{
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), array());
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), []);
}
/**
......@@ -21,7 +21,7 @@ class InsertManyTest extends TestCase
*/
public function testConstructorDocumentsMustBeAList()
{
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), array(1 => array('x' => 1)));
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [1 => ['x' => 1]]);
}
/**
......@@ -31,7 +31,7 @@ class InsertManyTest extends TestCase
*/
public function testConstructorDocumentsArgumentElementTypeChecks($document)
{
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), array($document));
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [$document]);
}
/**
......@@ -40,19 +40,19 @@ class InsertManyTest extends TestCase
*/
public function testConstructorOptionTypeChecks(array $options)
{
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), array(array('x' => 1)), $options);
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [['x' => 1]], $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
$options = [];
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('ordered' => $value);
$options[][] = ['ordered' => $value];
}
foreach ($this->getInvalidWriteConcernValues() as $value) {
$options[][] = array('writeConcern' => $value);
$options[][] = ['writeConcern' => $value];
}
return $options;
......
......@@ -21,15 +21,15 @@ class InsertOneTest extends TestCase
*/
public function testConstructorOptionTypeChecks(array $options)
{
new InsertOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $options);
new InsertOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
$options = [];
foreach ($this->getInvalidWriteConcernValues() as $value) {
$options[][] = array('writeConcern' => $value);
$options[][] = ['writeConcern' => $value];
}
return $options;
......
......@@ -12,7 +12,7 @@ class ReplaceOneTest extends TestCase
*/
public function testConstructorFilterArgumentTypeCheck($filter)
{
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, array('y' => 1));
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['y' => 1]);
}
/**
......@@ -21,7 +21,7 @@ class ReplaceOneTest extends TestCase
*/
public function testConstructorReplacementArgumentTypeCheck($replacement)
{
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $replacement);
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement);
}
/**
......@@ -30,6 +30,6 @@ class ReplaceOneTest extends TestCase
*/
public function testConstructorReplacementArgumentRequiresNoOperators()
{
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), array('$set' => array('x' => 1)));
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], ['$set' => ['x' => 1]]);
}
}
......@@ -22,41 +22,41 @@ abstract class TestCase extends BaseTestCase
protected function getInvalidArrayValues()
{
return array(123, 3.14, 'foo', true, new stdClass);
return [123, 3.14, 'foo', true, new stdClass];
}
protected function getInvalidBooleanValues()
{
return array(123, 3.14, 'foo', array(), new stdClass);
return [123, 3.14, 'foo', [], new stdClass];
}
protected function getInvalidDocumentValues()
{
return array(123, 3.14, 'foo', true);
return [123, 3.14, 'foo', true];
}
protected function getInvalidIntegerValues()
{
return array(3.14, 'foo', true, array(), new stdClass);
return [3.14, 'foo', true, [], new stdClass];
}
protected function getInvalidStringValues()
{
return array(123, 3.14, true, array(), new stdClass);
return [123, 3.14, true, [], new stdClass];
}
protected function getInvalidReadPreferenceValues()
{
return array(123, 3.14, 'foo', true, array(), new stdClass);
return [123, 3.14, 'foo', true, [], new stdClass];
}
protected function getInvalidWriteConcernValues()
{
return array(123, 3.14, 'foo', true, array(), new stdClass);
return [123, 3.14, 'foo', true, [], new stdClass];
}
protected function wrapValuesForDataProvider(array $values)
{
return array_map(function($value) { return array($value); }, $values);
return array_map(function($value) { return [$value]; }, $values);
}
}
......@@ -12,7 +12,7 @@ class UpdateManyTest extends TestCase
*/
public function testConstructorFilterArgumentTypeCheck($filter)
{
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, array('$set' => array('x' => 1)));
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
}
/**
......@@ -21,7 +21,7 @@ class UpdateManyTest extends TestCase
*/
public function testConstructorUpdateArgumentTypeCheck($update)
{
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $update);
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
}
/**
......@@ -30,6 +30,6 @@ class UpdateManyTest extends TestCase
*/
public function testConstructorUpdateArgumentRequiresOperators()
{
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), array('y' => 1));
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], ['y' => 1]);
}
}
......@@ -12,7 +12,7 @@ class UpdateOneTest extends TestCase
*/
public function testConstructorFilterArgumentTypeCheck($filter)
{
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), $filter, array('$set' => array('x' => 1)));
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
}
/**
......@@ -21,7 +21,7 @@ class UpdateOneTest extends TestCase
*/
public function testConstructorUpdateArgumentTypeCheck($update)
{
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $update);
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
}
/**
......@@ -30,6 +30,6 @@ class UpdateOneTest extends TestCase
*/
public function testConstructorUpdateArgumentRequiresOperators()
{
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), array('y' => 1));
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], ['y' => 1]);
}
}
......@@ -13,7 +13,7 @@ class UpdateTest extends TestCase
*/
public function testConstructorFilterArgumentTypeCheck($filter)
{
new Update($this->getDatabaseName(), $this->getCollectionName(), $filter, array('$set' => array('x' => 1)));
new Update($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
}
/**
......@@ -23,7 +23,7 @@ class UpdateTest extends TestCase
*/
public function testConstructorUpdateArgumentTypeCheck($update)
{
new Update($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $update);
new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
}
/**
......@@ -32,23 +32,23 @@ class UpdateTest extends TestCase
*/
public function testConstructorOptionTypeChecks(array $options)
{
new Update($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), array('y' => 1), $options);
new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], ['y' => 1], $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
$options = [];
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('multi' => $value);
$options[][] = ['multi' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('upsert' => $value);
$options[][] = ['upsert' => $value];
}
foreach ($this->getInvalidWriteConcernValues() as $value) {
$options[][] = array('writeConcern' => $value);
$options[][] = ['writeConcern' => $value];
}
return $options;
......
......@@ -56,7 +56,7 @@ class PedantryTest extends \PHPUnit_Framework_TestCase
public function provideProjectClassNames()
{
$classNames = array();
$classNames = [];
$srcDir = realpath(__DIR__ . '/../src/');
$files = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcDir)), '/\.php$/i');
......
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