From fd4629a27be8161eec9b84e055ac732915e6f856 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Tue, 6 Nov 2018 22:51:01 +0200 Subject: [PATCH 01/13] fix typos --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0aa40e5c7..6f9ef0405 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,7 @@ This service provider will slightly modify the internal DatabaseReminderReposito ### Queues -If you want to use MongoDB as your database backend, change the the driver in `config/queue.php`: +If you want to use MongoDB as your database backend, change the driver in `config/queue.php`: ```php 'connections' => [ @@ -689,7 +689,7 @@ For more information about model manipulation, check http://laravel.com/docs/elo ### Dates -Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields you will need to manually specify them as described here: http://laravel.com/docs/eloquent#date-mutators +Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields, you will need to manually specify them as described here: http://laravel.com/docs/eloquent#date-mutators Example: @@ -787,7 +787,7 @@ class User extends Eloquent { } ``` -You access the embedded models through the dynamic property: +You can access the embedded models through the dynamic property: ```php $books = User::first()->books; @@ -849,7 +849,7 @@ Embedded relations will return a Collection of embedded items instead of a query ### EmbedsOne Relations -The embedsOne relation is similar to the EmbedsMany relation, but only embeds a single model. +The embedsOne relation is similar to the embedsMany relation, but only embeds a single model. ```php use Jenssegers\Mongodb\Eloquent\Model as Eloquent; @@ -864,7 +864,7 @@ class Book extends Eloquent { } ``` -You access the embedded models through the dynamic property: +You can access the embedded models through the dynamic property: ```php $author = Book::first()->author; @@ -1014,7 +1014,7 @@ DB::collection('items')->paginate($limit, $projections); **Push** -Add an items to an array. +Add items to an array. ```php DB::collection('users')->where('name', 'John')->push('items', 'boots'); From cc50f148721b968c203f809a15884a4b90f836c1 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Fri, 23 Nov 2018 15:48:30 +0200 Subject: [PATCH 02/13] laravel/lumen 5.7.14 compatibility Updated model to be compatible with laravel/lumen 5.7.14 --- src/Jenssegers/Mongodb/Eloquent/Model.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Jenssegers/Mongodb/Eloquent/Model.php b/src/Jenssegers/Mongodb/Eloquent/Model.php index 894ebe41a..6b931e468 100644 --- a/src/Jenssegers/Mongodb/Eloquent/Model.php +++ b/src/Jenssegers/Mongodb/Eloquent/Model.php @@ -31,6 +31,13 @@ abstract class Model extends BaseModel * @var string */ protected $primaryKey = '_id'; + + /** + * The primary key type. + * + * @var string + */ + protected $keyType = 'string'; /** * The parent relation instance. From 8ae7ffdaae5e5aaa8f1ea028e32b5fa336e5c0b6 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Wed, 28 Nov 2018 17:29:41 +0200 Subject: [PATCH 03/13] Overrided whereIn method retrieval for relations, to force use standart whereIn nor whereInRawInteger --- src/Jenssegers/Mongodb/Relations/BelongsTo.php | 13 +++++++++++++ src/Jenssegers/Mongodb/Relations/BelongsToMany.php | 13 +++++++++++++ src/Jenssegers/Mongodb/Relations/EmbedsMany.php | 13 +++++++++++++ src/Jenssegers/Mongodb/Relations/EmbedsOne.php | 13 +++++++++++++ .../Mongodb/Relations/EmbedsOneOrMany.php | 13 +++++++++++++ src/Jenssegers/Mongodb/Relations/HasMany.php | 13 +++++++++++++ src/Jenssegers/Mongodb/Relations/HasOne.php | 13 +++++++++++++ src/Jenssegers/Mongodb/Relations/MorphTo.php | 13 +++++++++++++ 8 files changed, 104 insertions(+) diff --git a/src/Jenssegers/Mongodb/Relations/BelongsTo.php b/src/Jenssegers/Mongodb/Relations/BelongsTo.php index 78b5d63be..457e6bc1f 100644 --- a/src/Jenssegers/Mongodb/Relations/BelongsTo.php +++ b/src/Jenssegers/Mongodb/Relations/BelongsTo.php @@ -3,6 +3,7 @@ namespace Jenssegers\Mongodb\Relations; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model as EloquentModel; class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo { @@ -59,4 +60,16 @@ public function getOwnerKey() { return property_exists($this, 'ownerKey') ? $this->ownerKey : $this->otherKey; } + + /** + * Get the name of the "where in" method for eager loading. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @return string + */ + protected function whereInMethod(EloquentModel $model, $key) + { + return 'whereIn'; + } } diff --git a/src/Jenssegers/Mongodb/Relations/BelongsToMany.php b/src/Jenssegers/Mongodb/Relations/BelongsToMany.php index 73816b049..0e1b5280b 100644 --- a/src/Jenssegers/Mongodb/Relations/BelongsToMany.php +++ b/src/Jenssegers/Mongodb/Relations/BelongsToMany.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany; use Illuminate\Support\Arr; +use Illuminate\Database\Eloquent\Model as EloquentModel; class BelongsToMany extends EloquentBelongsToMany { @@ -337,4 +338,16 @@ public function getRelatedKey() { return property_exists($this, 'relatedPivotKey') ? $this->relatedPivotKey : $this->relatedKey; } + + /** + * Get the name of the "where in" method for eager loading. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @return string + */ + protected function whereInMethod(EloquentModel $model, $key) + { + return 'whereIn'; + } } diff --git a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php index b0e40893d..825b0d594 100644 --- a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php +++ b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php @@ -7,6 +7,7 @@ use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\Paginator; use MongoDB\BSON\ObjectID; +use Illuminate\Database\Eloquent\Model as EloquentModel; class EmbedsMany extends EmbedsOneOrMany { @@ -328,4 +329,16 @@ public function __call($method, $parameters) return parent::__call($method, $parameters); } + + /** + * Get the name of the "where in" method for eager loading. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @return string + */ + protected function whereInMethod(EloquentModel $model, $key) + { + return 'whereIn'; + } } diff --git a/src/Jenssegers/Mongodb/Relations/EmbedsOne.php b/src/Jenssegers/Mongodb/Relations/EmbedsOne.php index 2efbfe1df..4640bdeb1 100644 --- a/src/Jenssegers/Mongodb/Relations/EmbedsOne.php +++ b/src/Jenssegers/Mongodb/Relations/EmbedsOne.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Model; use MongoDB\BSON\ObjectID; +use Illuminate\Database\Eloquent\Model as EloquentModel; class EmbedsOne extends EmbedsOneOrMany { @@ -136,4 +137,16 @@ public function delete() { return $this->performDelete(); } + + /** + * Get the name of the "where in" method for eager loading. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @return string + */ + protected function whereInMethod(EloquentModel $model, $key) + { + return 'whereIn'; + } } diff --git a/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php b/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php index a8f90544d..177160bf1 100644 --- a/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php +++ b/src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Relations\Relation; use Jenssegers\Mongodb\Eloquent\Model; +use Illuminate\Database\Eloquent\Model as EloquentModel; abstract class EmbedsOneOrMany extends Relation { @@ -403,4 +404,16 @@ public function getQualifiedForeignKeyName() { return $this->foreignKey; } + + /** + * Get the name of the "where in" method for eager loading. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @return string + */ + protected function whereInMethod(EloquentModel $model, $key) + { + return 'whereIn'; + } } diff --git a/src/Jenssegers/Mongodb/Relations/HasMany.php b/src/Jenssegers/Mongodb/Relations/HasMany.php index 47e60e533..93a25425a 100644 --- a/src/Jenssegers/Mongodb/Relations/HasMany.php +++ b/src/Jenssegers/Mongodb/Relations/HasMany.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\HasMany as EloquentHasMany; +use Illuminate\Database\Eloquent\Model as EloquentModel; class HasMany extends EloquentHasMany { @@ -77,4 +78,16 @@ public function getRelationQuery(Builder $query, Builder $parent, $columns = ['* return $query->where($this->getHasCompareKey(), 'exists', true); } + + /** + * Get the name of the "where in" method for eager loading. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @return string + */ + protected function whereInMethod(EloquentModel $model, $key) + { + return 'whereIn'; + } } diff --git a/src/Jenssegers/Mongodb/Relations/HasOne.php b/src/Jenssegers/Mongodb/Relations/HasOne.php index c91a65787..a8d65dba9 100644 --- a/src/Jenssegers/Mongodb/Relations/HasOne.php +++ b/src/Jenssegers/Mongodb/Relations/HasOne.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne; +use Illuminate\Database\Eloquent\Model as EloquentModel; class HasOne extends EloquentHasOne { @@ -77,4 +78,16 @@ public function getRelationQuery(Builder $query, Builder $parent, $columns = ['* return $query->where($this->getForeignKeyName(), 'exists', true); } + + /** + * Get the name of the "where in" method for eager loading. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @return string + */ + protected function whereInMethod(EloquentModel $model, $key) + { + return 'whereIn'; + } } diff --git a/src/Jenssegers/Mongodb/Relations/MorphTo.php b/src/Jenssegers/Mongodb/Relations/MorphTo.php index 08344f526..32f3d3ab6 100644 --- a/src/Jenssegers/Mongodb/Relations/MorphTo.php +++ b/src/Jenssegers/Mongodb/Relations/MorphTo.php @@ -3,6 +3,7 @@ namespace Jenssegers\Mongodb\Relations; use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo; +use Illuminate\Database\Eloquent\Model as EloquentModel; class MorphTo extends EloquentMorphTo { @@ -42,4 +43,16 @@ public function getOwnerKey() { return property_exists($this, 'ownerKey') ? $this->ownerKey : $this->otherKey; } + + /** + * Get the name of the "where in" method for eager loading. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @return string + */ + protected function whereInMethod(EloquentModel $model, $key) + { + return 'whereIn'; + } } From 4656b83af09cbe08158d27170981a3d7fe37d4a1 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Thu, 20 Dec 2018 21:56:53 +0800 Subject: [PATCH 04/13] fix bug The main solution is to solve the bugs encountered in using database alone --- README.md | 4 +++- src/Jenssegers/Mongodb/Query/Builder.php | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d1bc60f09..816d7b385 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,10 @@ The service provider will register a mongodb database extension with the origina For usage outside Laravel, check out the [Capsule manager](https://github.com/illuminate/database/blob/master/README.md) and add: ```php -$capsule->getDatabaseManager()->extend('mongodb', function($config) +$capsule->getDatabaseManager()->extend('mongodb', function($config, $name) { + $config['name'] = $name; + return new Jenssegers\Mongodb\Connection($config); }); ``` diff --git a/src/Jenssegers/Mongodb/Query/Builder.php b/src/Jenssegers/Mongodb/Query/Builder.php index 62f203f7c..2effd897f 100644 --- a/src/Jenssegers/Mongodb/Query/Builder.php +++ b/src/Jenssegers/Mongodb/Query/Builder.php @@ -152,6 +152,8 @@ protected function shouldUseCollections() $version = filter_var(explode(')', $version)[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); // lumen return version_compare($version, '5.3', '>='); } + + return true; } /** From f7f555d63884dd8f935aa69f330a94bde5d43ce4 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Thu, 24 Jan 2019 11:25:09 +0300 Subject: [PATCH 05/13] reassigned getDatabaseName method --- src/Jenssegers/Mongodb/Connection.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Jenssegers/Mongodb/Connection.php b/src/Jenssegers/Mongodb/Connection.php index 7276155a6..b95d922a1 100644 --- a/src/Jenssegers/Mongodb/Connection.php +++ b/src/Jenssegers/Mongodb/Connection.php @@ -113,6 +113,14 @@ public function getMongoClient() return $this->connection; } + /** + * {@inheritdoc} + */ + public function getDatabaseName() + { + return $this->getMongoDB()->getDatabaseName(); + } + /** * Create a new MongoDB connection. * From de22037ccac2913e09bb3c6f013eabda0a265d60 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Sat, 9 Feb 2019 01:09:52 +0100 Subject: [PATCH 06/13] Remove dead code --- src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php b/src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php index 5320ae890..281f8af75 100644 --- a/src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php +++ b/src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php @@ -11,14 +11,6 @@ class PasswordBrokerManager extends BasePasswordBrokerManager */ protected function createTokenRepository(array $config) { - $key = $this->app['config']['app.key']; - - if (\Illuminate\Support\Str::startsWith($key, 'base64:')) { - $key = base64_decode(substr($key, 7)); - } - - $connection = isset($config['connection']) ? $config['connection'] : null; - return new DatabaseTokenRepository( $this->app['db']->connection(), $this->app['hash'], From 7f52c05749b99fb831d401588c0d7da0d1e94b6d Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Tue, 26 Feb 2019 19:40:34 +0200 Subject: [PATCH 07/13] Update Model.php --- src/Jenssegers/Mongodb/Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jenssegers/Mongodb/Eloquent/Model.php b/src/Jenssegers/Mongodb/Eloquent/Model.php index 6b931e468..ef5e87184 100644 --- a/src/Jenssegers/Mongodb/Eloquent/Model.php +++ b/src/Jenssegers/Mongodb/Eloquent/Model.php @@ -228,7 +228,7 @@ public function getCasts() /** * @inheritdoc */ - protected function originalIsEquivalent($key, $current) + public function originalIsEquivalent($key, $current) { if (!array_key_exists($key, $this->original)) { return false; From 2596fddd7d6de769389112be729b0c52843fd03b Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Wed, 27 Feb 2019 17:25:45 +0100 Subject: [PATCH 08/13] Update supported versions --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4bf1c4384..e444dd9d2 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ composer require jenssegers/mongodb 5.4.x | 3.2.x 5.5.x | 3.3.x 5.6.x | 3.4.x + 5.7.x | 3.4.x + 5.8.x | 3.5.x And add the service provider in `config/app.php`: From 18bcf34efc324d2bc1e52e71be878d3180c693e5 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Wed, 27 Feb 2019 17:26:11 +0100 Subject: [PATCH 09/13] Require Laravel 5.8 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index ce32f6407..e0da76b94 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,10 @@ ], "license" : "MIT", "require": { - "illuminate/support": "^5.6", - "illuminate/container": "^5.6", - "illuminate/database": "^5.6", - "illuminate/events": "^5.6", + "illuminate/support": "^5.8", + "illuminate/container": "^5.8", + "illuminate/database": "^5.8", + "illuminate/events": "^5.8", "mongodb/mongodb": "^1.0.0" }, "require-dev": { From 17da25e108f14817eb95195df39b2bce6548cf93 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Tue, 12 Mar 2019 09:49:10 +0300 Subject: [PATCH 10/13] Fix tests (#1724) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *   Update Dockerfile, add for methods setUp and tearDown return type hint in all tests, replace fire on dispatch * Resolve error test with touch * Use COMPOSER_VERSION in Dockerfile * Add alias for composer * Change parent method's names Broken commit in laravel: https://github.com/laravel/framework/commit/2ee18923eaff142a89439f0adf0d3f15c30db85b * Remove changes in .travis.yml * Remove changes from Dockerfile * Revert changes in docker-compose.yml * Update image with mysql --- docker-compose.yml | 2 +- src/Jenssegers/Mongodb/Eloquent/Builder.php | 25 ++++++++ .../Mongodb/Helpers/QueriesRelationships.php | 4 +- tests/AuthTest.php | 3 +- tests/EmbeddedRelationsTest.php | 58 +++++++++---------- tests/GeospatialTest.php | 4 +- tests/HybridRelationsTest.php | 4 +- tests/ModelTest.php | 3 +- tests/QueryBuilderTest.php | 2 +- tests/QueryTest.php | 4 +- tests/QueueTest.php | 2 +- tests/RelationsTest.php | 2 +- tests/SchemaTest.php | 2 +- tests/SeederTest.php | 2 +- tests/ValidationTest.php | 2 +- 15 files changed, 72 insertions(+), 47 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 42546660b..a6e521d3b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ services: mysql: container_name: mysql - image: mysql + image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: MYSQL_DATABASE: unittest diff --git a/src/Jenssegers/Mongodb/Eloquent/Builder.php b/src/Jenssegers/Mongodb/Eloquent/Builder.php index 1ee1c41fe..b14053229 100644 --- a/src/Jenssegers/Mongodb/Eloquent/Builder.php +++ b/src/Jenssegers/Mongodb/Eloquent/Builder.php @@ -177,6 +177,31 @@ public function raw($expression = null) return $results; } + /** + * Add the "updated at" column to an array of values. + * TODO Remove if https://github.com/laravel/framework/commit/6484744326531829341e1ff886cc9b628b20d73e + * wiil be reverted + * Issue in laravel frawework https://github.com/laravel/framework/issues/27791 + * + * @param array $values + * @return array + */ + protected function addUpdatedAtColumn(array $values) + { + if (! $this->model->usesTimestamps() || + is_null($this->model->getUpdatedAtColumn())) { + return $values; + } + + $column = $this->model->getUpdatedAtColumn(); + $values = array_merge( + [$column => $this->model->freshTimestampString()], + $values + ); + + return $values; + } + /** * @return \Illuminate\Database\ConnectionInterface */ diff --git a/src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php b/src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php index 5fe908208..766567627 100644 --- a/src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php +++ b/src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php @@ -110,7 +110,7 @@ protected function getRelatedConstraintKey($relation) } if ($relation instanceof BelongsTo) { - return $relation->getForeignKey(); + return $relation->getForeignKeyName(); } if ($relation instanceof BelongsToMany && ! $this->isAcrossConnections($relation)) { @@ -130,7 +130,7 @@ protected function getHasCompareKey($relation) return $relation->getHasCompareKey(); } - return $relation instanceof HasOneOrMany ? $relation->getForeignKeyName() : $relation->getOwnerKey(); + return $relation instanceof HasOneOrMany ? $relation->getForeignKeyName() : $relation->getOwnerKeyName(); } /** diff --git a/tests/AuthTest.php b/tests/AuthTest.php index 2b671fdd5..e81efed90 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -5,8 +5,9 @@ class AuthTest extends TestCase { - public function tearDown() + public function tearDown(): void { + parent::setUp(); User::truncate(); DB::collection('password_reminders')->truncate(); } diff --git a/tests/EmbeddedRelationsTest.php b/tests/EmbeddedRelationsTest.php index 5caae5b28..440761e78 100644 --- a/tests/EmbeddedRelationsTest.php +++ b/tests/EmbeddedRelationsTest.php @@ -2,7 +2,7 @@ class EmbeddedRelationsTest extends TestCase { - public function tearDown() + public function tearDown(): void { Mockery::close(); @@ -21,11 +21,11 @@ public function testEmbedsManySave() $address = new Address(['city' => 'London']); $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(true); - $events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($address), $address); - $events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address); + $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($address), $address); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address); $address = $user->addresses()->save($address); $address->unsetEventDispatcher(); @@ -47,11 +47,11 @@ public function testEmbedsManySave() $this->assertEquals(['London', 'Paris'], $user->addresses->pluck('city')->all()); $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(true); - $events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($address), $address); - $events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address); + $events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($address), $address); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address); $address->city = 'New York'; $user->addresses()->save($address); @@ -94,16 +94,16 @@ public function testEmbedsManySave() // $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); // $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); // $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(true); - // $events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($address), $address); - // $events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address); + // $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($address), $address); + // $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address); // $address->save(); // $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); // $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); // $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(true); - // $events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($address), $address); - // $events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($address), $address); + // $events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($address), $address); + // $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address); // $address->city = 'Paris'; // $address->save(); @@ -213,9 +213,9 @@ public function testEmbedsManyDestroy() $address = $user->addresses->first(); $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::type('Address'))->andReturn(true); - $events->shouldReceive('fire')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address')); + $events->shouldReceive('dispatch')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address')); $user->addresses()->destroy($address->_id); $this->assertEquals(['Bristol', 'Bruxelles'], $user->addresses->pluck('city')->all()); @@ -252,9 +252,9 @@ public function testEmbedsManyDelete() $address = $user->addresses->first(); $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::type('Address'))->andReturn(true); - $events->shouldReceive('fire')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address')); + $events->shouldReceive('dispatch')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address')); $address->delete(); @@ -301,7 +301,7 @@ public function testEmbedsManyCreatingEventReturnsFalse() $address = new Address(['city' => 'London']); $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(false); @@ -316,7 +316,7 @@ public function testEmbedsManySavingEventReturnsFalse() $address->exists = true; $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(false); $this->assertFalse($user->addresses()->save($address)); @@ -330,7 +330,7 @@ public function testEmbedsManyUpdatingEventReturnsFalse() $user->addresses()->save($address); $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(false); @@ -348,7 +348,7 @@ public function testEmbedsManyDeletingEventReturnsFalse() $address = $user->addresses->first(); $address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($address), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::mustBe($address))->andReturn(false); $this->assertEquals(0, $user->addresses()->destroy($address)); @@ -452,11 +452,11 @@ public function testEmbedsOne() $father = new User(['name' => 'Mark Doe']); $father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true); - $events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($father), $father); - $events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($father), $father); $father = $user->father()->save($father); $father->unsetEventDispatcher(); @@ -472,11 +472,11 @@ public function testEmbedsOne() $this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']); $father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($father), $father)->andReturn(true); - $events->shouldReceive('fire')->once()->with('eloquent.updated: ' . get_class($father), $father); - $events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($father), $father); $father->name = 'Tom Doe'; $user->father()->save($father); @@ -488,11 +488,11 @@ public function testEmbedsOne() $father = new User(['name' => 'Jim Doe']); $father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($father), $father)->andReturn(true); $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($father), $father)->andReturn(true); - $events->shouldReceive('fire')->once()->with('eloquent.created: ' . get_class($father), $father); - $events->shouldReceive('fire')->once()->with('eloquent.saved: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($father), $father); + $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($father), $father); $father = $user->father()->save($father); $father->unsetEventDispatcher(); @@ -507,7 +507,7 @@ public function testEmbedsOneAssociate() $father = new User(['name' => 'Mark Doe']); $father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher')); - $events->shouldReceive('fire')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); + $events->shouldReceive('dispatch')->with('eloquent.retrieved: ' . get_class($father), Mockery::any()); $events->shouldReceive('until')->times(0)->with('eloquent.saving: ' . get_class($father), $father); $father = $user->father()->associate($father); diff --git a/tests/GeospatialTest.php b/tests/GeospatialTest.php index 2d646b337..b13ed46af 100644 --- a/tests/GeospatialTest.php +++ b/tests/GeospatialTest.php @@ -2,7 +2,7 @@ class GeospatialTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); @@ -43,7 +43,7 @@ public function setUp() ]); } - public function tearDown() + public function tearDown(): void { Schema::drop('locations'); } diff --git a/tests/HybridRelationsTest.php b/tests/HybridRelationsTest.php index 2223950ec..ade509067 100644 --- a/tests/HybridRelationsTest.php +++ b/tests/HybridRelationsTest.php @@ -2,7 +2,7 @@ class HybridRelationsTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); @@ -11,7 +11,7 @@ public function setUp() MysqlRole::executeSchema(); } - public function tearDown() + public function tearDown(): void { MysqlUser::truncate(); MysqlBook::truncate(); diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 4387d1231..f6e4f4eb6 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -8,7 +8,7 @@ class ModelTest extends TestCase { - public function tearDown() + public function tearDown(): void { User::truncate(); Soft::truncate(); @@ -262,7 +262,6 @@ public function testTouch() $user->save(); $old = $user->updated_at; - sleep(1); $user->touch(); $check = User::find($user->_id); diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index ac1479d26..0807b4ece 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -5,7 +5,7 @@ class QueryBuilderTest extends TestCase { - public function tearDown() + public function tearDown(): void { DB::collection('users')->truncate(); DB::collection('items')->truncate(); diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 2011305c2..de8589ebd 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -4,7 +4,7 @@ class QueryTest extends TestCase { protected static $started = false; - public function setUp() + public function setUp(): void { parent::setUp(); User::create(['name' => 'John Doe', 'age' => 35, 'title' => 'admin']); @@ -18,7 +18,7 @@ public function setUp() User::create(['name' => 'Error', 'age' => null, 'title' => null]); } - public function tearDown() + public function tearDown(): void { User::truncate(); parent::tearDown(); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 35be33f9a..f3ebc94f6 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -2,7 +2,7 @@ class QueueTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/RelationsTest.php b/tests/RelationsTest.php index 1e2aaa491..de3e0f222 100644 --- a/tests/RelationsTest.php +++ b/tests/RelationsTest.php @@ -2,7 +2,7 @@ class RelationsTest extends TestCase { - public function tearDown() + public function tearDown(): void { Mockery::close(); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index a04715d9d..5d63e28eb 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -2,7 +2,7 @@ class SchemaTest extends TestCase { - public function tearDown() + public function tearDown(): void { Schema::drop('newcollection'); } diff --git a/tests/SeederTest.php b/tests/SeederTest.php index 9581df3d3..61143e330 100644 --- a/tests/SeederTest.php +++ b/tests/SeederTest.php @@ -2,7 +2,7 @@ class SeederTest extends TestCase { - public function tearDown() + public function tearDown(): void { User::truncate(); } diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 16e31f4cf..267996420 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -2,7 +2,7 @@ class ValidationTest extends TestCase { - public function tearDown() + public function tearDown(): void { User::truncate(); } From 3a13cb0fbd4af4d38fb2a95c8d168f29b8f11b23 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Sun, 17 Mar 2019 15:52:15 +0100 Subject: [PATCH 11/13] :whale: New travis docker setup --- .travis.yml | 26 +++++++++++++++++--------- Dockerfile | 18 ++++++++---------- composer.json | 2 +- docker-compose.yml | 9 +++++---- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index fe11b61da..736c4c86e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,27 @@ -sudo: required -dist: trusty -language: php -php: - - "7.2" - - "7.1" +language: minimal + +matrix: + include: + - name: "7.1" + env: PHP_VERSION=7.1 + - name: "7.2" + env: PHP_VERSION=7.2 + - name: "7.3" + env: PHP_VERSION=7.3 services: - docker +cache: + directories: + - $HOME/.composer/cache + install: - docker version - sudo pip install docker-compose - docker-compose version - - cat Dockerfile - - docker-compose build --build-arg PHP_VERSION=${TRAVIS_PHP_VERSION} + - docker-compose build --build-arg PHP_VERSION=${PHP_VERSION} + - docker-compose run --rm tests composer install --no-interaction script: - - docker-compose up --exit-code-from php + - docker-compose run --rm tests ./vendor/bin/phpunit --coverage-clover ./clover.xml diff --git a/Dockerfile b/Dockerfile index 68eac169d..360f67e66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,15 @@ ARG PHP_VERSION=7.2 +ARG COMPOSER_VERSION=1.8 +FROM composer:${COMPOSER_VERSION} FROM php:${PHP_VERSION}-cli -RUN pecl install xdebug - RUN apt-get update && \ - apt-get install -y autoconf pkg-config libssl-dev git zlib1g-dev - -RUN pecl install mongodb && docker-php-ext-enable mongodb && \ - docker-php-ext-install -j$(nproc) pdo pdo_mysql zip && docker-php-ext-enable xdebug + apt-get install -y autoconf pkg-config libssl-dev git libzip-dev zlib1g-dev && \ + pecl install mongodb && docker-php-ext-enable mongodb && \ + pecl install xdebug && docker-php-ext-enable xdebug && \ + docker-php-ext-install -j$(nproc) pdo_mysql zip -RUN curl -sS https://getcomposer.org/installer | php \ - && mv composer.phar /usr/local/bin/ \ - && ln -s /usr/local/bin/composer.phar /usr/local/bin/composer +COPY --from=composer /usr/bin/composer /usr/local/bin/composer -ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" +WORKDIR /code diff --git a/composer.json b/composer.json index e0da76b94..cdd4bff2b 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "illuminate/container": "^5.8", "illuminate/database": "^5.8", "illuminate/events": "^5.8", - "mongodb/mongodb": "^1.0.0" + "mongodb/mongodb": "^1.0" }, "require-dev": { "phpunit/phpunit": "^6.0|^7.0", diff --git a/docker-compose.yml b/docker-compose.yml index a6e521d3b..c6f20163e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,17 @@ version: '3' services: - php: - container_name: php + tests: + container_name: tests build: context: . dockerfile: Dockerfile volumes: - .:/code working_dir: /code - command: bash -c "composer install --prefer-source --no-interaction && php ./vendor/bin/phpunit" depends_on: - - mysql - mongodb + - mysql mysql: container_name: mysql @@ -27,5 +26,7 @@ services: mongodb: container_name: mongodb image: mongo + ports: + - 27017:27017 logging: driver: none From 862205125a22535ab922a2f8083fad27d70b12ad Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Mon, 18 Mar 2019 10:04:43 +0300 Subject: [PATCH 12/13] Update phpunit.xml (#1733) --- phpunit.xml.dist | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bd9d7f5c4..2669537cb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,13 +8,11 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" verbose="true" > tests/ - tests/MysqlRelationsTest.php tests/SchemaTest.php @@ -39,7 +37,6 @@ tests/RelationsTest.php - tests/MysqlRelationsTest.php tests/ValidationTest.php From 3f0609c4dd4634df635a15dabf8e8e3fe90fc1a6 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Wed, 20 Mar 2019 21:27:14 +0300 Subject: [PATCH 13/13] Add arg options for creating collections with options (#1734) --- composer.json | 2 +- src/Jenssegers/Mongodb/Schema/Builder.php | 4 ++-- tests/SchemaTest.php | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index cdd4bff2b..36d14bf48 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "illuminate/container": "^5.8", "illuminate/database": "^5.8", "illuminate/events": "^5.8", - "mongodb/mongodb": "^1.0" + "mongodb/mongodb": "^1.4" }, "require-dev": { "phpunit/phpunit": "^6.0|^7.0", diff --git a/src/Jenssegers/Mongodb/Schema/Builder.php b/src/Jenssegers/Mongodb/Schema/Builder.php index 799fe8e80..0e352846d 100644 --- a/src/Jenssegers/Mongodb/Schema/Builder.php +++ b/src/Jenssegers/Mongodb/Schema/Builder.php @@ -85,11 +85,11 @@ public function table($collection, Closure $callback) /** * @inheritdoc */ - public function create($collection, Closure $callback = null) + public function create($collection, Closure $callback = null, array $options = []) { $blueprint = $this->createBlueprint($collection); - $blueprint->create(); + $blueprint->create($options); if ($callback) { $callback($blueprint); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 5d63e28eb..b56cc639c 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -5,6 +5,7 @@ class SchemaTest extends TestCase public function tearDown(): void { Schema::drop('newcollection'); + Schema::drop('newcollection_two'); } public function testCreate() @@ -25,6 +26,13 @@ public function testCreateWithCallback() $this->assertTrue(Schema::hasCollection('newcollection')); } + public function testCreateWithOptions() + { + Schema::create('newcollection_two', null, ['capped' => true, 'size' => 1024]); + $this->assertTrue(Schema::hasCollection('newcollection_two')); + $this->assertTrue(Schema::hasTable('newcollection_two')); + } + public function testDrop() { Schema::create('newcollection');