From ff9fa5e6a8b873c4533b640bc7e23b11c523d250 Mon Sep 17 00:00:00 2001 From: Ditty Date: Fri, 6 Mar 2020 00:01:17 +0300 Subject: [PATCH 1/8] Remove phpcov Remove phpcov, it's not compatible and suggested to be installed with phar instead of composer, see sebastianbergmann/phpcov#96 --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 142a2c2e0..34cf0e3c3 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,6 @@ "orchestra/testbench": "^3.1|^4.0", "mockery/mockery": "^1.0", "doctrine/dbal": "^2.5", - "phpunit/phpcov": "^6.0", "cedx/coveralls": "^11.2" }, "autoload": { From 727c2914704abc82160480b07d0af34815647bea Mon Sep 17 00:00:00 2001 From: Ditty Date: Fri, 6 Mar 2020 00:01:41 +0300 Subject: [PATCH 2/8] Remove php 7.1 Remove php 7.1 which is EOL. --- .github/workflows/build-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 4728f2a8c..7e829a5d4 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - php: ['7.1', '7.2', '7.3', '7.4'] + php: ['7.2', '7.3', '7.4'] os: ['ubuntu-latest'] mongodb: ['3.6', '4.0', '4.2'] services: From cbdce4f12f0fcc349616c082161eb3ea0e442217 Mon Sep 17 00:00:00 2001 From: Ditty Date: Fri, 6 Mar 2020 00:03:24 +0300 Subject: [PATCH 3/8] Bump dependencies Bump dependencies for laravel 7 --- README.md | 1 + composer.json | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4f1359972..0aa3f2c9a 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Make sure you have the MongoDB PHP driver installed. You can find installation i 5.7.x | 3.4.x 5.8.x | 3.5.x 6.x | 3.6.x + 7.x | 4.x Install the package via Composer: diff --git a/composer.json b/composer.json index 34cf0e3c3..8241ae285 100644 --- a/composer.json +++ b/composer.json @@ -19,17 +19,17 @@ ], "license": "MIT", "require": { - "illuminate/support": "^5.8|^6.0", - "illuminate/container": "^5.8|^6.0", - "illuminate/database": "^5.8|^6.0", - "illuminate/events": "^5.8|^6.0", - "mongodb/mongodb": "^1.4" + "illuminate/support": "^7.0", + "illuminate/container": "^7.0", + "illuminate/database": "^7.0", + "illuminate/events": "^7.0", + "mongodb/mongodb": "^1.6" }, "require-dev": { - "phpunit/phpunit": "^6.0|^7.0|^8.0", - "orchestra/testbench": "^3.1|^4.0", - "mockery/mockery": "^1.0", - "doctrine/dbal": "^2.5", + "phpunit/phpunit": "^8.4", + "orchestra/testbench": "^5.0", + "mockery/mockery": "^1.3.1", + "doctrine/dbal": "^2.6", "cedx/coveralls": "^11.2" }, "autoload": { From 0ae4287e88691f4d0061679ec6f7460efa954810 Mon Sep 17 00:00:00 2001 From: Ditty Date: Fri, 6 Mar 2020 00:16:30 +0300 Subject: [PATCH 4/8] Make functions and tests compatible Make functions and tests compatible with laravel 7 Date serialization changes Laravel 7 uses a new date serialization format when using the toArray or toJson method on Eloquent models. To format dates for serialization, the framework now uses Carbon's toJSON method, which produces an ISO-8601 https://laravel.com/docs/7.x/upgrade#date-serialization laravel_7_comptability $model->getOriginal() was moved to getRawOriginal method See https://laravel.com/docs/7.x/upgrade#factory-types --- src/Jenssegers/Mongodb/Eloquent/Model.php | 21 +++--- tests/DatabaseEloquentTimestampsTest.php | 85 +++++++++++++++++++++++ tests/ModelTest.php | 15 +--- tests/QueueTest.php | 11 +++ 4 files changed, 109 insertions(+), 23 deletions(-) create mode 100644 tests/DatabaseEloquentTimestampsTest.php diff --git a/src/Jenssegers/Mongodb/Eloquent/Model.php b/src/Jenssegers/Mongodb/Eloquent/Model.php index aafe49904..b0f60ed5e 100644 --- a/src/Jenssegers/Mongodb/Eloquent/Model.php +++ b/src/Jenssegers/Mongodb/Eloquent/Model.php @@ -223,36 +223,37 @@ public function getCasts() /** * {@inheritdoc} */ - public function originalIsEquivalent($key, $current) + public function originalIsEquivalent($key) { if (! array_key_exists($key, $this->original)) { return false; } - $original = $this->getOriginal($key); + $attribute = Arr::get($this->attributes, $key); + $original = Arr::get($this->original, $key); - if ($current === $original) { + if ($attribute === $original) { return true; } - if (null === $current) { + if (null === $attribute) { return false; } if ($this->isDateAttribute($key)) { - $current = $current instanceof UTCDateTime ? $this->asDateTime($current) : $current; + $attribute = $attribute instanceof UTCDateTime ? $this->asDateTime($attribute) : $attribute; $original = $original instanceof UTCDateTime ? $this->asDateTime($original) : $original; - return $current == $original; + return $attribute == $original; } - if ($this->hasCast($key)) { - return $this->castAttribute($key, $current) === + if ($this->hasCast($key, static::$primitiveCastTypes)) { + return $this->castAttribute($key, $attribute) === $this->castAttribute($key, $original); } - return is_numeric($current) && is_numeric($original) - && strcmp((string) $current, (string) $original) === 0; + return is_numeric($attribute) && is_numeric($original) + && strcmp((string) $attribute, (string) $original) === 0; } /** diff --git a/tests/DatabaseEloquentTimestampsTest.php b/tests/DatabaseEloquentTimestampsTest.php new file mode 100644 index 000000000..a3d1e21cc --- /dev/null +++ b/tests/DatabaseEloquentTimestampsTest.php @@ -0,0 +1,85 @@ + 'test@test.com', + ]); + + $this->assertEquals($now->toDateTimeString(), $user->created_at->toDateTimeString()); + $this->assertEquals($now->toDateTimeString(), $user->updated_at->toDateTimeString()); + } + + public function testUserWithCreatedAt() + { + $now = Carbon::now(); + $user = UserWithCreated::create([ + 'email' => 'test@test.com', + ]); + + $this->assertEquals($now->toDateTimeString(), $user->created_at->toDateTimeString()); + } + + public function testUserWithUpdatedAt() + { + $now = Carbon::now(); + $user = UserWithUpdated::create([ + 'email' => 'test@test.com', + ]); + + $this->assertEquals($now->toDateTimeString(), $user->updated_at->toDateTimeString()); + } +} + +/** + * Eloquent Models... + */ +class UserWithCreatedAndUpdated extends Eloquent +{ + protected $collection = 'users'; + + protected $guarded = []; +} + +class UserWithCreated extends Eloquent +{ + public const UPDATED_AT = null; + + protected $collection = 'users_created_at'; + + protected $guarded = []; + + protected $dateFormat = 'U'; +} + +class UserWithUpdated extends Eloquent +{ + public const CREATED_AT = null; + + protected $collection = 'users_updated_at'; + + protected $guarded = []; + + protected $dateFormat = 'U'; +} diff --git a/tests/ModelTest.php b/tests/ModelTest.php index c374ea828..8f2f081e6 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -397,25 +397,14 @@ public function testDates(): void $user = User::where('birthday', '>', new DateTime('1975/1/1'))->first(); $this->assertEquals('John Doe', $user->name); - // test custom date format for json output - $json = $user->toArray(); - $this->assertEquals($user->birthday->format('l jS \of F Y h:i:s A'), $json['birthday']); - $this->assertEquals($user->created_at->format('l jS \of F Y h:i:s A'), $json['created_at']); - // test created_at $item = Item::create(['name' => 'sword']); - $this->assertInstanceOf(UTCDateTime::class, $item->getOriginal('created_at')); - $this->assertEquals($item->getOriginal('created_at') + $this->assertInstanceOf(UTCDateTime::class, $item->getRawOriginal('created_at')); + $this->assertEquals($item->getRawOriginal('created_at') ->toDateTime() ->getTimestamp(), $item->created_at->getTimestamp()); $this->assertLessThan(2, abs(time() - $item->created_at->getTimestamp())); - // test default date format for json output - /** @var Item $item */ - $item = Item::create(['name' => 'sword']); - $json = $item->toArray(); - $this->assertEquals($item->created_at->format('Y-m-d H:i:s'), $json['created_at']); - /** @var User $user */ $user = User::create(['name' => 'Jane Doe', 'birthday' => time()]); $this->assertInstanceOf(Carbon::class, $user->birthday); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index a91fbdac4..0c8e58423 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Carbon\Carbon; +use Illuminate\Support\Str; use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider; class QueueTest extends TestCase @@ -18,6 +19,12 @@ public function setUp(): void public function testQueueJobLifeCycle(): void { + $uuid = Str::uuid(); + + Str::createUuidsUsing(function () use ($uuid) { + return $uuid; + }); + $id = Queue::push('test', ['action' => 'QueueJobLifeCycle'], 'test'); $this->assertNotNull($id); @@ -26,9 +33,11 @@ public function testQueueJobLifeCycle(): void $this->assertInstanceOf(Jenssegers\Mongodb\Queue\MongoJob::class, $job); $this->assertEquals(1, $job->isReserved()); $this->assertEquals(json_encode([ + 'uuid' => $uuid, 'displayName' => 'test', 'job' => 'test', 'maxTries' => null, + 'maxExceptions' => null, 'delay' => null, 'timeout' => null, 'data' => ['action' => 'QueueJobLifeCycle'], @@ -37,6 +46,8 @@ public function testQueueJobLifeCycle(): void // Remove reserved job $job->delete(); $this->assertEquals(0, Queue::getDatabase()->table(Config::get('queue.connections.database.table'))->count()); + + Str::createUuidsNormally(); } public function testQueueJobExpired(): void From a73a6670cd3b2f0d729fb21c89f1c9cad0003e2d Mon Sep 17 00:00:00 2001 From: Ditty Date: Fri, 6 Mar 2020 00:55:29 +0300 Subject: [PATCH 5/8] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b687a010..6c06ce104 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. ## [Unreleased] + +### Added +- Laravel 7 support by [@divine](https://github.com/divine). + +### Changed +- Updated versions of all dependencies by [@divine](https://github.com/divine) + ### Removed - EmbedsOne and EmbedsMany relations by [@divine](https://github.com/divine). - shouldUseCollections function by [@divine](https://github.com/divine). From 31b0fdf04aa3dc52714a4a4af54b845beb257992 Mon Sep 17 00:00:00 2001 From: Ditty Date: Fri, 6 Mar 2020 14:19:22 +0300 Subject: [PATCH 6/8] Drop test collections correctly Drop test collections correctly --- tests/DatabaseEloquentTimestampsTest.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/DatabaseEloquentTimestampsTest.php b/tests/DatabaseEloquentTimestampsTest.php index a3d1e21cc..aec17e54c 100644 --- a/tests/DatabaseEloquentTimestampsTest.php +++ b/tests/DatabaseEloquentTimestampsTest.php @@ -14,7 +14,9 @@ class DatabaseEloquentTimestampsTest extends TestCase */ protected function tearDown(): void { - User::truncate(); + $this->schema()->drop('users'); + $this->schema()->drop('users_created_at'); + $this->schema()->drop('users_updated_at'); } /** @@ -50,6 +52,26 @@ public function testUserWithUpdatedAt() $this->assertEquals($now->toDateTimeString(), $user->updated_at->toDateTimeString()); } + + /** + * Get a database connection instance. + * + * @return \Illuminate\Database\ConnectionInterface + */ + protected function connection() + { + return Eloquent::getConnectionResolver()->connection(); + } + + /** + * Get a schema builder instance. + * + * @return \Illuminate\Database\Schema\Builder + */ + protected function schema() + { + return $this->connection()->getSchemaBuilder(); + } } /** From 7bd92dbc2794e183e6cded8116e43d076cffbe4d Mon Sep 17 00:00:00 2001 From: Ditty Date: Tue, 10 Mar 2020 20:25:10 +0300 Subject: [PATCH 7/8] Remove test and revert back old test --- tests/DatabaseEloquentTimestampsTest.php | 107 ----------------------- tests/ModelTest.php | 6 ++ tests/models/User.php | 5 -- 3 files changed, 6 insertions(+), 112 deletions(-) delete mode 100644 tests/DatabaseEloquentTimestampsTest.php diff --git a/tests/DatabaseEloquentTimestampsTest.php b/tests/DatabaseEloquentTimestampsTest.php deleted file mode 100644 index aec17e54c..000000000 --- a/tests/DatabaseEloquentTimestampsTest.php +++ /dev/null @@ -1,107 +0,0 @@ -schema()->drop('users'); - $this->schema()->drop('users_created_at'); - $this->schema()->drop('users_updated_at'); - } - - /** - * Tests... - */ - public function testUserWithCreatedAtAndUpdatedAt() - { - $now = Carbon::now(); - $user = UserWithCreatedAndUpdated::create([ - 'email' => 'test@test.com', - ]); - - $this->assertEquals($now->toDateTimeString(), $user->created_at->toDateTimeString()); - $this->assertEquals($now->toDateTimeString(), $user->updated_at->toDateTimeString()); - } - - public function testUserWithCreatedAt() - { - $now = Carbon::now(); - $user = UserWithCreated::create([ - 'email' => 'test@test.com', - ]); - - $this->assertEquals($now->toDateTimeString(), $user->created_at->toDateTimeString()); - } - - public function testUserWithUpdatedAt() - { - $now = Carbon::now(); - $user = UserWithUpdated::create([ - 'email' => 'test@test.com', - ]); - - $this->assertEquals($now->toDateTimeString(), $user->updated_at->toDateTimeString()); - } - - /** - * Get a database connection instance. - * - * @return \Illuminate\Database\ConnectionInterface - */ - protected function connection() - { - return Eloquent::getConnectionResolver()->connection(); - } - - /** - * Get a schema builder instance. - * - * @return \Illuminate\Database\Schema\Builder - */ - protected function schema() - { - return $this->connection()->getSchemaBuilder(); - } -} - -/** - * Eloquent Models... - */ -class UserWithCreatedAndUpdated extends Eloquent -{ - protected $collection = 'users'; - - protected $guarded = []; -} - -class UserWithCreated extends Eloquent -{ - public const UPDATED_AT = null; - - protected $collection = 'users_created_at'; - - protected $guarded = []; - - protected $dateFormat = 'U'; -} - -class UserWithUpdated extends Eloquent -{ - public const CREATED_AT = null; - - protected $collection = 'users_updated_at'; - - protected $guarded = []; - - protected $dateFormat = 'U'; -} diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 8f2f081e6..3b3c6be10 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -405,6 +405,12 @@ public function testDates(): void ->getTimestamp(), $item->created_at->getTimestamp()); $this->assertLessThan(2, abs(time() - $item->created_at->getTimestamp())); + // test default date format for json output + /** @var Item $item */ + $item = Item::create(['name' => 'sword']); + $json = $item->toArray(); + $this->assertEquals($item->created_at->format('Y-m-d\TH:i:s.u\Z'), $json['created_at']); + /** @var User $user */ $user = User::create(['name' => 'Jane Doe', 'birthday' => time()]); $this->assertInstanceOf(Carbon::class, $user->birthday); diff --git a/tests/models/User.php b/tests/models/User.php index ebc564fcb..d2e0f1889 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -67,9 +67,4 @@ public function photos() { return $this->morphMany('Photo', 'imageable'); } - - public function getDateFormat() - { - return 'l jS \of F Y h:i:s A'; - } } From c5498ef9684d4d9e103451b68f1e01c1ee808ab9 Mon Sep 17 00:00:00 2001 From: Ditty Date: Tue, 10 Mar 2020 20:32:00 +0300 Subject: [PATCH 8/8] Revert getDateFormat --- tests/models/User.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/models/User.php b/tests/models/User.php index d2e0f1889..ebc564fcb 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -67,4 +67,9 @@ public function photos() { return $this->morphMany('Photo', 'imageable'); } + + public function getDateFormat() + { + return 'l jS \of F Y h:i:s A'; + } }