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: 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). 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 142a2c2e0..8241ae285 100644 --- a/composer.json +++ b/composer.json @@ -19,18 +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/phpcov": "^6.0", + "phpunit/phpunit": "^8.4", + "orchestra/testbench": "^5.0", + "mockery/mockery": "^1.3.1", + "doctrine/dbal": "^2.6", "cedx/coveralls": "^11.2" }, "autoload": { 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/ModelTest.php b/tests/ModelTest.php index c374ea828..3b3c6be10 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -397,15 +397,10 @@ 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())); @@ -414,7 +409,7 @@ public function testDates(): void /** @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']); + $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()]); 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