From c176dd4ac03e76b49117207cca4650ad6a67252c Mon Sep 17 00:00:00 2001 From: Ravan Scafi Date: Fri, 24 Nov 2017 02:32:46 -0200 Subject: [PATCH 1/8] Allow relations to not use cache --- src/Mongolid/Model/Relations.php | 22 ++++++++++++---------- tests/Mongolid/Model/RelationsTest.php | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/Mongolid/Model/Relations.php b/src/Mongolid/Model/Relations.php index 66bcef5f..081fa716 100644 --- a/src/Mongolid/Model/Relations.php +++ b/src/Mongolid/Model/Relations.php @@ -18,12 +18,13 @@ trait Relations /** * Returns the referenced documents as objects. * - * @param string $entity class of the entity or of the schema of the entity - * @param string $field the field where the _id is stored + * @param string $entity class of the entity or of the schema of the entity + * @param string $field the field where the _id is stored + * @param bool $cacheable retrieves a CacheableCursor instead * * @return mixed */ - protected function referencesOne(string $entity, string $field) + protected function referencesOne(string $entity, string $field, bool $cacheable = true) { $referenced_id = $this->$field; @@ -37,21 +38,22 @@ protected function referencesOne(string $entity, string $field) $dataMapper = Ioc::make(DataMapper::class); $dataMapper->setSchema($entityInstance); - return $dataMapper->first(['_id' => $referenced_id], [], true); + return $dataMapper->first(['_id' => $referenced_id], [], $cacheable); } - return $entityInstance::first(['_id' => $referenced_id], [], true); + return $entityInstance::first(['_id' => $referenced_id], [], $cacheable); } /** * Returns the cursor for the referenced documents as objects. * - * @param string $entity class of the entity or of the schema of the entity - * @param string $field the field where the _ids are stored + * @param string $entity class of the entity or of the schema of the entity + * @param string $field the field where the _ids are stored + * @param bool $cacheable retrieves a CacheableCursor instead * * @return array */ - protected function referencesMany(string $entity, string $field) + protected function referencesMany(string $entity, string $field, bool $cacheable = true) { $referencedIds = (array) $this->$field; @@ -69,10 +71,10 @@ protected function referencesMany(string $entity, string $field) $dataMapper = Ioc::make(DataMapper::class); $dataMapper->setSchema($entityInstance); - return $dataMapper->where($query, [], true); + return $dataMapper->where($query, [], $cacheable); } - return $entityInstance::where($query, [], true); + return $entityInstance::where($query, [], $cacheable); } /** diff --git a/tests/Mongolid/Model/RelationsTest.php b/tests/Mongolid/Model/RelationsTest.php index 7b80aec3..4e81c798 100644 --- a/tests/Mongolid/Model/RelationsTest.php +++ b/tests/Mongolid/Model/RelationsTest.php @@ -24,7 +24,7 @@ public function tearDown() /** * @dataProvider referenceScenarios */ - public function testShouldReferenceOne($entity, $field, $fieldValue, $expectedQuery) + public function testShouldReferenceOne($entity, $field, $fieldValue, $useCache, $expectedQuery) { // Set $expectedQuery = $expectedQuery['referencesOne']; @@ -39,6 +39,7 @@ public function testShouldReferenceOne($entity, $field, $fieldValue, $expectedQu Ioc::instance('EntityClass', $entity); $dataMapper->shouldReceive('first') + ->with(m::type('array'), [], $useCache) ->once() ->andReturnUsing(function ($query) use ($result, $expectedQuery) { $this->assertMongoQueryEquals($expectedQuery, $query); @@ -49,14 +50,14 @@ public function testShouldReferenceOne($entity, $field, $fieldValue, $expectedQu // Assert $this->assertSame( $result, - $this->callProtected($model, 'referencesOne', ['EntityClass', $field]) + $this->callProtected($model, 'referencesOne', ['EntityClass', $field, $useCache]) ); } /** * @dataProvider referenceScenarios */ - public function testShouldReferenceMany($entity, $field, $fieldValue, $expectedQuery) + public function testShouldReferenceMany($entity, $field, $fieldValue, $useCache, $expectedQuery) { // Set $expectedQuery = $expectedQuery['referencesMany']; @@ -71,6 +72,7 @@ public function testShouldReferenceMany($entity, $field, $fieldValue, $expectedQ Ioc::instance('EntityClass', $entity); $dataMapper->shouldReceive('where') + ->with(m::type('array'), [], $useCache) ->once() ->andReturnUsing(function ($query) use ($result, $expectedQuery) { $this->assertMongoQueryEquals($expectedQuery, $query); @@ -81,7 +83,7 @@ public function testShouldReferenceMany($entity, $field, $fieldValue, $expectedQ // Assert $this->assertSame( $result, - $this->callProtected($model, 'referencesMany', ['EntityClass', $field]) + $this->callProtected($model, 'referencesMany', ['EntityClass', $field, $useCache]) ); } @@ -175,6 +177,7 @@ public function referenceScenarios() }, 'field' => 'foo', 'fieldValue' => 12345, + 'useCache' => true, 'expectedQuery' => [ 'referencesOne' => ['_id' => 12345], 'referencesMany' => ['_id' => ['$in' => [12345]]], @@ -187,6 +190,7 @@ public function referenceScenarios() }, 'field' => 'foo', 'fieldValue' => 'abc123', + 'useCache' => true, 'expectedQuery' => [ 'referencesOne' => ['_id' => 'abc123'], 'referencesMany' => ['_id' => ['$in' => ['abc123']]], @@ -198,6 +202,7 @@ public function referenceScenarios() }, 'field' => 'foo', 'fieldValue' => ['553e3c80293fce6572ff2a40', '5571df31cf3fce544481a085'], + 'useCache' => false, 'expectedQuery' => [ 'referencesOne' => ['_id' => '553e3c80293fce6572ff2a40'], 'referencesMany' => ['_id' => ['$in' => [new ObjectID('553e3c80293fce6572ff2a40'), new ObjectID('5571df31cf3fce544481a085')]]], @@ -210,6 +215,7 @@ public function referenceScenarios() }, 'field' => 'foo', 'fieldValue' => '577afb0b4d3cec136058fa82', + 'useCache' => true, 'expectedQuery' => [ 'referencesOne' => ['_id' => '577afb0b4d3cec136058fa82'], 'referencesMany' => ['_id' => ['$in' => ['577afb0b4d3cec136058fa82']]], @@ -221,6 +227,7 @@ public function referenceScenarios() }, 'field' => 'foo', 'fieldValue' => [1, 2, 3, 4, 5], + 'useCache' => false, 'expectedQuery' => [ 'referencesOne' => ['_id' => 1], 'referencesMany' => ['_id' => ['$in' => [1, 2, 3, 4, 5]]], @@ -233,6 +240,7 @@ public function referenceScenarios() }, 'field' => 'foo', 'fieldValue' => ['577afb0b4d3cec136058fa82', '577afb7e4d3cec136258fa83'], + 'useCache' => false, 'expectedQuery' => [ 'referencesOne' => ['_id' => '577afb0b4d3cec136058fa82'], 'referencesMany' => ['_id' => ['$in' => [new ObjectID('577afb0b4d3cec136058fa82'), new ObjectID('577afb7e4d3cec136258fa83')]]], @@ -244,6 +252,7 @@ public function referenceScenarios() }, 'field' => 'foo', 'fieldValue' => [new ObjectID('577afb0b4d3cec136058fa82'), new ObjectID('577afb7e4d3cec136258fa83')], + 'useCache' => true, 'expectedQuery' => [ 'referencesOne' => ['_id' => new ObjectID('577afb0b4d3cec136058fa82')], 'referencesMany' => ['_id' => ['$in' => [new ObjectID('577afb0b4d3cec136058fa82'), new ObjectID('577afb7e4d3cec136258fa83')]]], @@ -256,6 +265,7 @@ public function referenceScenarios() }, 'field' => 'foo', 'fieldValue' => null, + 'useCache' => false, 'expectedQuery' => [ 'referencesOne' => ['_id' => null], 'referencesMany' => ['_id' => ['$in' => []]], From 6fb81e2b70b92e34cafa4fcc7eb2ca7b7742944b Mon Sep 17 00:00:00 2001 From: Ravan Scafi Date: Fri, 24 Nov 2017 04:37:20 +0000 Subject: [PATCH 2/8] Apply fixes from StyleCI --- src/Mongolid/DataMapper/DataMapper.php | 10 +++++----- src/Mongolid/DataMapper/EntityAssembler.php | 2 +- src/Mongolid/DataMapper/SchemaMapper.php | 2 +- src/Mongolid/Model/Attributes.php | 2 +- src/Mongolid/Schema/Schema.php | 2 +- src/Mongolid/Util/ObjectIdUtils.php | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Mongolid/DataMapper/DataMapper.php b/src/Mongolid/DataMapper/DataMapper.php index 0bef63ab..a4a9a688 100644 --- a/src/Mongolid/DataMapper/DataMapper.php +++ b/src/Mongolid/DataMapper/DataMapper.php @@ -83,7 +83,7 @@ public function save($entity, array $options = []) // If the "saving" event returns false we'll bail out of the save and return // false, indicating that the save failed. This gives an opportunities to // listeners to cancel save operations if validations fail or whatever. - if ($this->fireEvent('saving', $entity, true) === false) { + if (false === $this->fireEvent('saving', $entity, true)) { return false; } @@ -122,7 +122,7 @@ public function save($entity, array $options = []) */ public function insert($entity, array $options = [], bool $fireEvents = true): bool { - if ($fireEvents && $this->fireEvent('inserting', $entity, true) === false) { + if ($fireEvents && false === $this->fireEvent('inserting', $entity, true)) { return false; } @@ -160,7 +160,7 @@ public function insert($entity, array $options = [], bool $fireEvents = true): b */ public function update($entity, array $options = []): bool { - if ($this->fireEvent('updating', $entity, true) === false) { + if (false === $this->fireEvent('updating', $entity, true)) { return false; } @@ -205,7 +205,7 @@ public function update($entity, array $options = []): bool */ public function delete($entity, array $options = []): bool { - if ($this->fireEvent('deleting', $entity, true) === false) { + if (false === $this->fireEvent('deleting', $entity, true)) { return false; } @@ -504,7 +504,7 @@ protected function prepareProjection(array $fields) if (is_int($key) && is_string($value)) { $key = $value; - if (strpos($value, '-') === 0) { + if (0 === strpos($value, '-')) { $key = substr($key, 1); $value = false; } else { diff --git a/src/Mongolid/DataMapper/EntityAssembler.php b/src/Mongolid/DataMapper/EntityAssembler.php index b9b014dd..70412293 100644 --- a/src/Mongolid/DataMapper/EntityAssembler.php +++ b/src/Mongolid/DataMapper/EntityAssembler.php @@ -36,7 +36,7 @@ public function assemble($document, Schema $schema) foreach ($document as $field => $value) { $fieldType = $schema->fields[$field] ?? null; - if ($fieldType && substr($fieldType, 0, 7) == 'schema.') { + if ($fieldType && 'schema.' == substr($fieldType, 0, 7)) { $value = $this->assembleDocumentsRecursively($value, substr($fieldType, 7)); } diff --git a/src/Mongolid/DataMapper/SchemaMapper.php b/src/Mongolid/DataMapper/SchemaMapper.php index ea35aced..6e074fe1 100644 --- a/src/Mongolid/DataMapper/SchemaMapper.php +++ b/src/Mongolid/DataMapper/SchemaMapper.php @@ -98,7 +98,7 @@ public function parseField($value, string $fieldType) } // If the field type points to another schema. - if (substr($fieldType, 0, 7) == 'schema.') { + if ('schema.' == substr($fieldType, 0, 7)) { return $this->mapToSchema($value, substr($fieldType, 7)); } diff --git a/src/Mongolid/Model/Attributes.php b/src/Mongolid/Model/Attributes.php index 0bc11c13..2a492cef 100644 --- a/src/Mongolid/Model/Attributes.php +++ b/src/Mongolid/Model/Attributes.php @@ -65,7 +65,7 @@ public function getAttribute(string $key) if ($inAttributes) { return $this->attributes[$key]; - } elseif ($key == 'attributes') { + } elseif ('attributes' == $key) { return $this->attributes; } } diff --git a/src/Mongolid/Schema/Schema.php b/src/Mongolid/Schema/Schema.php index 3d6a93d6..930d3a7b 100644 --- a/src/Mongolid/Schema/Schema.php +++ b/src/Mongolid/Schema/Schema.php @@ -66,7 +66,7 @@ abstract class Schema */ public function objectId($value = null) { - if ($value === null) { + if (null === $value) { return new ObjectID(); } diff --git a/src/Mongolid/Util/ObjectIdUtils.php b/src/Mongolid/Util/ObjectIdUtils.php index 21c18153..a96cd381 100644 --- a/src/Mongolid/Util/ObjectIdUtils.php +++ b/src/Mongolid/Util/ObjectIdUtils.php @@ -21,7 +21,7 @@ public static function isObjectId($value) $value = (string) $value; } - if (is_string($value) && strlen($value) == 24 && ctype_xdigit($value)) { + if (is_string($value) && 24 == strlen($value) && ctype_xdigit($value)) { return true; } From 710259d531a8b77249a1e58b57d6e77f148fd56c Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sat, 4 Nov 2017 11:59:42 -0200 Subject: [PATCH 3/8] Updated to PHPUnit 6 and Mockery 1 --- composer.json | 4 ++-- phpunit.xml | 1 + phpunit.xml.dist | 1 + tests/Mongolid/Util/LocalDateTimeTest.php | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index d9989353..fbc6342c 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,9 @@ "illuminate/container": "^5.4" }, "require-dev": { - "mockery/mockery": "^0.9", + "mockery/mockery": "^1.0", "satooshi/php-coveralls": "^1.0", - "phpunit/phpunit": "^5.7", + "phpunit/phpunit": "^6.0", "squizlabs/php_codesniffer": "^2.0", "sami/sami": "^4.0" }, diff --git a/phpunit.xml b/phpunit.xml index c6f59d2f..7c9faa18 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,7 @@ Date: Mon, 6 Nov 2017 03:09:48 -0200 Subject: [PATCH 4/8] Bump PHPUnit version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fbc6342c..1647e5ef 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require-dev": { "mockery/mockery": "^1.0", "satooshi/php-coveralls": "^1.0", - "phpunit/phpunit": "^6.0", + "phpunit/phpunit": "^6.4", "squizlabs/php_codesniffer": "^2.0", "sami/sami": "^4.0" }, From 417117ee32fc3878b7be0fa0153193a0fed89c52 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sun, 14 Jan 2018 19:53:52 -0200 Subject: [PATCH 5/8] Simplify return --- src/Mongolid/Util/ObjectIdUtils.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Mongolid/Util/ObjectIdUtils.php b/src/Mongolid/Util/ObjectIdUtils.php index a96cd381..1d7783ab 100644 --- a/src/Mongolid/Util/ObjectIdUtils.php +++ b/src/Mongolid/Util/ObjectIdUtils.php @@ -21,10 +21,6 @@ public static function isObjectId($value) $value = (string) $value; } - if (is_string($value) && 24 == strlen($value) && ctype_xdigit($value)) { - return true; - } - - return false; + return is_string($value) && 24 == strlen($value) && ctype_xdigit($value); } } From a01239c5d0145ec89382380870c89bb2d28cb62b Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sun, 14 Jan 2018 20:29:25 -0200 Subject: [PATCH 6/8] Fixes from PHPStan level 0 --- src/Mongolid/Connection/Pool.php | 2 +- src/Mongolid/Cursor/CacheableCursor.php | 2 +- src/Mongolid/DataMapper/BulkWrite.php | 4 ++-- src/Mongolid/DataMapper/DataMapper.php | 8 ++++---- src/Mongolid/Manager.php | 2 +- src/Mongolid/Model/DocumentEmbedder.php | 10 +++++----- src/Mongolid/Model/Relations.php | 4 ++-- src/Mongolid/Schema/Schema.php | 14 +++++++------- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Mongolid/Connection/Pool.php b/src/Mongolid/Connection/Pool.php index 2c9b501b..1e4c7837 100644 --- a/src/Mongolid/Connection/Pool.php +++ b/src/Mongolid/Connection/Pool.php @@ -14,7 +14,7 @@ class Pool /** * Opened connections. * - * @var SplQueue + * @var \SplQueue */ protected $connections; diff --git a/src/Mongolid/Cursor/CacheableCursor.php b/src/Mongolid/Cursor/CacheableCursor.php index 54cd6fb5..e8a859d9 100644 --- a/src/Mongolid/Cursor/CacheableCursor.php +++ b/src/Mongolid/Cursor/CacheableCursor.php @@ -27,7 +27,7 @@ class CacheableCursor extends Cursor * Limit of the query. It is stored because when caching the documents * the DOCUMENT_LIMIT const will be used. * - * @var ìnteger + * @var integer */ protected $originalLimit; diff --git a/src/Mongolid/DataMapper/BulkWrite.php b/src/Mongolid/DataMapper/BulkWrite.php index 0bc0217b..85d02fe4 100644 --- a/src/Mongolid/DataMapper/BulkWrite.php +++ b/src/Mongolid/DataMapper/BulkWrite.php @@ -2,7 +2,7 @@ namespace Mongolid\DataMapper; -use MongoDB\BSON\ObjectID; +use MongoDB\BSON\ObjectId; use MongoDB\Driver\BulkWrite as MongoBulkWrite; use MongoDB\Driver\WriteConcern; use Mongolid\Connection\Pool; @@ -81,7 +81,7 @@ public function setBulkWrite(MongoBulkWrite $bulkWrite) * * @see https://docs.mongodb.com/manual/reference/operator/update/set/#set-top-level-fields * - * @param ObjectID|string $id + * @param ObjectId|string $id * @param array $dataToSet * @param array $options * @param string $operator diff --git a/src/Mongolid/DataMapper/DataMapper.php b/src/Mongolid/DataMapper/DataMapper.php index a4a9a688..68f22262 100644 --- a/src/Mongolid/DataMapper/DataMapper.php +++ b/src/Mongolid/DataMapper/DataMapper.php @@ -3,7 +3,7 @@ namespace Mongolid\DataMapper; use InvalidArgumentException; -use MongoDB\BSON\ObjectID; +use MongoDB\BSON\ObjectId; use MongoDB\Collection; use Mongolid\Connection\Pool; use Mongolid\Container\Ioc; @@ -393,7 +393,7 @@ protected function prepareValueQuery($value): array is_string($value['_id']) && ObjectIdUtils::isObjectId($value['_id']) ) { - $value['_id'] = new ObjectID($value['_id']); + $value['_id'] = new ObjectId($value['_id']); } if (isset($value['_id']) && @@ -406,7 +406,7 @@ protected function prepareValueQuery($value): array } /** - * Prepares an embedded array of an query. It will convert string ObjectIDs + * Prepares an embedded array of an query. It will convert string ObjectIds * in operators into actual objects. * * @param array $value array that will be treated @@ -421,7 +421,7 @@ protected function prepareArrayFieldOfQuery(array $value): array ) { foreach ($value[$operator] as $index => $id) { if (ObjectIdUtils::isObjectId($id)) { - $value[$operator][$index] = new ObjectID($id); + $value[$operator][$index] = new ObjectId($id); } } } diff --git a/src/Mongolid/Manager.php b/src/Mongolid/Manager.php index 1e84a91d..68aad958 100644 --- a/src/Mongolid/Manager.php +++ b/src/Mongolid/Manager.php @@ -36,7 +36,7 @@ class Manager /** * Container being used by Mongolid. * - * @var \Illuminate\Contracts\Container + * @var \Illuminate\Contracts\Container\Container */ public $container; diff --git a/src/Mongolid/Model/DocumentEmbedder.php b/src/Mongolid/Model/DocumentEmbedder.php index d101b431..0835f1b5 100644 --- a/src/Mongolid/Model/DocumentEmbedder.php +++ b/src/Mongolid/Model/DocumentEmbedder.php @@ -2,7 +2,7 @@ namespace Mongolid\Model; -use MongoDB\BSON\ObjectID; +use MongoDB\BSON\ObjectId; /** * Document embeder is a service that will embed documents within each other. @@ -115,7 +115,7 @@ public function detach($parent, string $field, &$entity): bool * * @param mixed $object the object|array that the _id will be retrieved from * - * @return ObjectID|mixed + * @return ObjectId|mixed */ protected function getId(&$object) { @@ -124,15 +124,15 @@ protected function getId(&$object) return $object['_id']; } - return $object['_id'] = new ObjectID(); + return $object['_id'] = new ObjectId(); } - if (is_object($object) && !$object instanceof ObjectID) { + if (is_object($object) && !$object instanceof ObjectId) { if (isset($object->_id) && $object->_id) { return $object->_id; } - return $object->_id = new ObjectID(); + return $object->_id = new ObjectId(); } return $object; diff --git a/src/Mongolid/Model/Relations.php b/src/Mongolid/Model/Relations.php index 081fa716..ea079348 100644 --- a/src/Mongolid/Model/Relations.php +++ b/src/Mongolid/Model/Relations.php @@ -2,7 +2,7 @@ namespace Mongolid\Model; -use MongoDB\BSON\ObjectID; +use MongoDB\BSON\ObjectId; use Mongolid\Container\Ioc; use Mongolid\Cursor\CursorFactory; use Mongolid\Cursor\EmbeddedCursor; @@ -59,7 +59,7 @@ protected function referencesMany(string $entity, string $field, bool $cacheable if (ObjectIdUtils::isObjectId($referencedIds[0] ?? '')) { foreach ($referencedIds as $key => $value) { - $referencedIds[$key] = new ObjectID($value); + $referencedIds[$key] = new ObjectId($value); } } diff --git a/src/Mongolid/Schema/Schema.php b/src/Mongolid/Schema/Schema.php index 930d3a7b..71d79db5 100644 --- a/src/Mongolid/Schema/Schema.php +++ b/src/Mongolid/Schema/Schema.php @@ -2,7 +2,7 @@ namespace Mongolid\Schema; -use MongoDB\BSON\ObjectID; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\UTCDateTime; use Mongolid\Container\Ioc; use Mongolid\Util\ObjectIdUtils; @@ -58,20 +58,20 @@ abstract class Schema /** * Filters any field in the $fields that has it's value specified as a - * 'objectId'. It will wraps the $value, if any, into a ObjectID object. + * 'objectId'. It will wraps the $value, if any, into a ObjectId object. * - * @param mixed $value value that may be converted to ObjectID + * @param mixed $value value that may be converted to ObjectId * - * @return ObjectID|mixed + * @return ObjectId|mixed */ public function objectId($value = null) { if (null === $value) { - return new ObjectID(); + return new ObjectId(); } if (is_string($value) && ObjectIdUtils::isObjectId($value)) { - $value = new ObjectID($value); + $value = new ObjectId($value); } return $value; @@ -109,7 +109,7 @@ public function createdAtTimestamp($value) return $value; } - return $this->updatedAtTimestamp(null); + return $this->updatedAtTimestamp(); } /** From a59f4f6ccb2a21054069fe876c6298c9d133000a Mon Sep 17 00:00:00 2001 From: Diego Felix Date: Mon, 15 Jan 2018 09:26:15 -0200 Subject: [PATCH 7/8] change from integer for StyleCi --- src/Mongolid/Cursor/CacheableCursor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mongolid/Cursor/CacheableCursor.php b/src/Mongolid/Cursor/CacheableCursor.php index e8a859d9..d8714c8f 100644 --- a/src/Mongolid/Cursor/CacheableCursor.php +++ b/src/Mongolid/Cursor/CacheableCursor.php @@ -27,7 +27,7 @@ class CacheableCursor extends Cursor * Limit of the query. It is stored because when caching the documents * the DOCUMENT_LIMIT const will be used. * - * @var integer + * @var int */ protected $originalLimit; From 1d42c5411e17655b4cc8efafdf79ac9550bf5bd7 Mon Sep 17 00:00:00 2001 From: gmsantos Date: Wed, 14 Mar 2018 16:19:51 -0300 Subject: [PATCH 8/8] Change 3th argument of bulkwrite to array --- .travis.yml | 2 +- composer.json | 2 +- src/Mongolid/DataMapper/BulkWrite.php | 2 +- tests/Mongolid/DataMapper/BulkWriteTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 48f00c46..4cba55d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ php: - 7.1 before_install: - - if [[ $TRAVIS_PHP_VERSION = 7.0 ]]; then pecl install mongodb; fi + - pecl install mongodb - echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini before_script: diff --git a/composer.json b/composer.json index 1647e5ef..1ccda769 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "require": { "php": ">=7.0", - "mongodb/mongodb": "^1.1", + "mongodb/mongodb": "^1.3", "illuminate/container": "^5.4" }, "require-dev": { diff --git a/src/Mongolid/DataMapper/BulkWrite.php b/src/Mongolid/DataMapper/BulkWrite.php index 85d02fe4..9aba4958 100644 --- a/src/Mongolid/DataMapper/BulkWrite.php +++ b/src/Mongolid/DataMapper/BulkWrite.php @@ -117,7 +117,7 @@ public function execute($writeConcern = 1) return $manager->executeBulkWrite( $namespace, $this->getBulkWrite(), - new WriteConcern($writeConcern) + ['writeConcern' => new WriteConcern($writeConcern)] ); } } diff --git a/tests/Mongolid/DataMapper/BulkWriteTest.php b/tests/Mongolid/DataMapper/BulkWriteTest.php index 47027a01..fd6a2358 100644 --- a/tests/Mongolid/DataMapper/BulkWriteTest.php +++ b/tests/Mongolid/DataMapper/BulkWriteTest.php @@ -146,7 +146,7 @@ public function testShouldExecuteBulkWrite() $manager->shouldReceive('executeBulkWrite') ->once() - ->with($namespace, $mongoBulkWrite, m::type(WriteConcern::class)) + ->with($namespace, $mongoBulkWrite, ['writeConcern' => new WriteConcern(1)]) ->andReturn(true); $bulkWrite = m::mock(BulkWrite::class.'[getBulkWrite]', [$entity]);