Skip to content

[4.x] Laravel 7 #1988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
21 changes: 11 additions & 10 deletions src/Jenssegers/Mongodb/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,36 +223,37 @@ public function getCasts()
/**
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to remove this dock block and same in this file

*/
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;
}

/**
Expand Down
11 changes: 3 additions & 8 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()]);
Expand Down
11 changes: 11 additions & 0 deletions tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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'],
Expand All @@ -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
Expand Down