diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index e830b6569..d978a8536 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -13,7 +13,7 @@ jobs: matrix: php: ['7.2', '7.3', '7.4'] os: ['ubuntu-latest'] - mongodb: ['3.6', '4.0', '4.2'] + mongodb: ['3.6', '4.0', '4.2', '4.4'] services: mongo: image: mongo:${{ matrix.mongodb }} @@ -63,10 +63,6 @@ jobs: MONGO_HOST: 0.0.0.0 MYSQL_HOST: 0.0.0.0 MYSQL_PORT: 3307 - - name: Send coveralls - run: vendor/bin/coveralls coverage.xml - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: codecov/codecov-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2deb81ea7..e06bad963 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,13 @@ -# Changelog -All notable changes to this project will be documented in this file. - -## [Unreleased] \ No newline at end of file +# Changelog +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 +- shouldUseCollections function by [@divine](https://github.com/divine). diff --git a/README.md b/README.md index 56256fea5..e801fd51b 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,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 | 3.7.x Install the package via Composer: diff --git a/composer.json b/composer.json index 142a2c2e0..872a48cd3 100644 --- a/composer.json +++ b/composer.json @@ -19,19 +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", - "cedx/coveralls": "^11.2" + "phpunit/phpunit": "^8.4|^9.0", + "orchestra/testbench": "^5.0", + "mockery/mockery": "^1.3.1", + "doctrine/dbal": "^2.6" }, "autoload": { "psr-0": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4da34b41d..38d2b79c9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,9 +18,6 @@ tests/SeederTest.php - - tests/CacheTest.php - tests/QueryBuilderTest.php tests/QueryTest.php diff --git a/src/Jenssegers/Mongodb/Eloquent/Model.php b/src/Jenssegers/Mongodb/Eloquent/Model.php index 8aaef55bb..081659d73 100644 --- a/src/Jenssegers/Mongodb/Eloquent/Model.php +++ b/src/Jenssegers/Mongodb/Eloquent/Model.php @@ -234,36 +234,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/src/Jenssegers/Mongodb/Query/Builder.php b/src/Jenssegers/Mongodb/Query/Builder.php index 549e2b57f..86526ed53 100644 --- a/src/Jenssegers/Mongodb/Query/Builder.php +++ b/src/Jenssegers/Mongodb/Query/Builder.php @@ -120,12 +120,6 @@ class Builder extends BaseBuilder '>=' => '$gte', ]; - /** - * Check if we need to return Collections instead of plain arrays (laravel >= 5.3 ) - * @var boolean - */ - protected $useCollections; - /** * @inheritdoc */ @@ -134,22 +128,6 @@ public function __construct(Connection $connection, Processor $processor) $this->grammar = new Grammar; $this->connection = $connection; $this->processor = $processor; - $this->useCollections = $this->shouldUseCollections(); - } - - /** - * Returns true if Laravel or Lumen >= 5.3 - * @return bool - */ - protected function shouldUseCollections() - { - if (function_exists('app')) { - $version = app()->version(); - $version = filter_var(explode(')', $version)[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); // lumen - return version_compare($version, '5.3', '>='); - } - - return true; } /** @@ -303,7 +281,7 @@ public function getFresh($columns = [], $returnLazy = false) 'aggregate' => $totalResults ] ]; - return $this->useCollections ? new Collection($results) : $results; + return new Collection($results); } elseif ($function == 'count') { // Translate count into sum. $group['aggregate'] = ['$sum' => 1]; @@ -360,7 +338,7 @@ public function getFresh($columns = [], $returnLazy = false) $results = iterator_to_array($this->collection->aggregate($pipeline, $options)); // Return results - return $this->useCollections ? new Collection($results) : $results; + return new Collection($results); } // Distinct query elseif ($this->distinct) { // Return distinct results directly @@ -373,7 +351,7 @@ public function getFresh($columns = [], $returnLazy = false) $result = $this->collection->distinct($column); } - return $this->useCollections ? new Collection($result) : $result; + return new Collection($result); } // Normal query else { $columns = []; @@ -430,7 +408,7 @@ public function getFresh($columns = [], $returnLazy = false) // Return results as an array with numeric keys $results = iterator_to_array($cursor, false); - return $this->useCollections ? new Collection($results) : $results; + return new Collection($results); } } @@ -685,7 +663,7 @@ public function pluck($column, $key = null) } $p = Arr::pluck($results, $column, $key); - return $this->useCollections ? new Collection($p) : $p; + return new Collection($p); } /** diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 2e25a9a58..61f1df0ec 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -410,8 +410,8 @@ public function testDates(): void // 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())); @@ -420,7 +420,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->toISOString(), $json['created_at']); /** @var User $user */ //Test with create and standard property @@ -430,10 +430,10 @@ public function testDates(): void $user = User::create(['name' => 'Jane Doe', 'birthday' => Date::now()]); $this->assertInstanceOf(Carbon::class, $user->birthday); - $user = User::create(['name' => 'Jane Doe', 'birthday' => 'Monday 8th of August 2005 03:12:46 PM']); + $user = User::create(['name' => 'Jane Doe', 'birthday' => 'Monday 8th August 2005 03:12:46 PM']); $this->assertInstanceOf(Carbon::class, $user->birthday); - $user = User::create(['name' => 'Jane Doe', 'birthday' => 'Monday 8th of August 1960 03:12:46 PM']); + $user = User::create(['name' => 'Jane Doe', 'birthday' => 'Monday 8th August 1960 03:12:46 PM']); $this->assertInstanceOf(Carbon::class, $user->birthday); $user = User::create(['name' => 'Jane Doe', 'birthday' => '2005-08-08']); @@ -467,10 +467,10 @@ public function testDates(): void $user->setAttribute('birthday', Date::now()); $this->assertInstanceOf(Carbon::class, $user->birthday); - $user->setAttribute('birthday', 'Monday 8th of August 2005 03:12:46 PM'); + $user->setAttribute('birthday', 'Monday 8th August 2005 03:12:46 PM'); $this->assertInstanceOf(Carbon::class, $user->birthday); - $user->setAttribute('birthday', 'Monday 8th of August 1960 03:12:46 PM'); + $user->setAttribute('birthday', 'Monday 8th August 1960 03:12:46 PM'); $this->assertInstanceOf(Carbon::class, $user->birthday); $user->setAttribute('birthday', '2005-08-08'); @@ -504,10 +504,10 @@ public function testDates(): void $user = User::create(['name' => 'Jane Doe', 'entry' => ['date' => Date::now()]]); $this->assertInstanceOf(Carbon::class, $user->getAttribute('entry.date')); - $user = User::create(['name' => 'Jane Doe', 'entry' => ['date' => 'Monday 8th of August 2005 03:12:46 PM']]); + $user = User::create(['name' => 'Jane Doe', 'entry' => ['date' => 'Monday 8th August 2005 03:12:46 PM']]); $this->assertInstanceOf(Carbon::class, $user->getAttribute('entry.date')); - $user = User::create(['name' => 'Jane Doe', 'entry' => ['date' => 'Monday 8th of August 1960 03:12:46 PM']]); + $user = User::create(['name' => 'Jane Doe', 'entry' => ['date' => 'Monday 8th August 1960 03:12:46 PM']]); $this->assertInstanceOf(Carbon::class, $user->getAttribute('entry.date')); $user = User::create(['name' => 'Jane Doe', 'entry' => ['date' => '2005-08-08']]); @@ -541,10 +541,10 @@ public function testDates(): void $user->setAttribute('entry.date', Date::now()); $this->assertInstanceOf(Carbon::class, $user->getAttribute('entry.date')); - $user->setAttribute('entry.date', 'Monday 8th of August 2005 03:12:46 PM'); + $user->setAttribute('entry.date', 'Monday 8th August 2005 03:12:46 PM'); $this->assertInstanceOf(Carbon::class, $user->getAttribute('entry.date')); - $user->setAttribute('entry.date', 'Monday 8th of August 1960 03:12:46 PM'); + $user->setAttribute('entry.date', 'Monday 8th August 1960 03:12:46 PM'); $this->assertInstanceOf(Carbon::class, $user->getAttribute('entry.date')); $user->setAttribute('entry.date', '2005-08-08'); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 9f3ad8887..ce32c0979 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); use Carbon\Carbon; +use Illuminate\Support\Str; use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider; class QueueTest extends TestCase @@ -17,6 +18,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); @@ -25,9 +32,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'], @@ -36,6 +45,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 diff --git a/tests/models/User.php b/tests/models/User.php index 1217af762..6dc32cbe6 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -77,8 +77,8 @@ public function father() return $this->embedsOne('User'); } - public function getDateFormat() + protected function serializeDate(DateTimeInterface $date) { - return 'l jS \of F Y h:i:s A'; + return $date->format('l jS \of F Y h:i:s A'); } }