Skip to content

Commit ec89233

Browse files
authored
Merge pull request #1988 from divine/laravel_7
[4.x] Laravel 7
2 parents b379bd3 + c5498ef commit ec89233

File tree

7 files changed

+43
-29
lines changed

7 files changed

+43
-29
lines changed

.github/workflows/build-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ${{matrix.os}}
1212
strategy:
1313
matrix:
14-
php: ['7.1', '7.2', '7.3', '7.4']
14+
php: ['7.2', '7.3', '7.4']
1515
os: ['ubuntu-latest']
1616
mongodb: ['3.6', '4.0', '4.2']
1717
services:

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5+
6+
### Added
7+
- Laravel 7 support by [@divine](https://github.com/divine).
8+
9+
### Changed
10+
- Updated versions of all dependencies by [@divine](https://github.com/divine)
11+
512
### Removed
613
- EmbedsOne and EmbedsMany relations by [@divine](https://github.com/divine).
714
- shouldUseCollections function by [@divine](https://github.com/divine).

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Make sure you have the MongoDB PHP driver installed. You can find installation i
6262
5.7.x | 3.4.x
6363
5.8.x | 3.5.x
6464
6.x | 3.6.x
65+
7.x | 4.x
6566

6667
Install the package via Composer:
6768

composer.json

+9-10
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
],
2020
"license": "MIT",
2121
"require": {
22-
"illuminate/support": "^5.8|^6.0",
23-
"illuminate/container": "^5.8|^6.0",
24-
"illuminate/database": "^5.8|^6.0",
25-
"illuminate/events": "^5.8|^6.0",
26-
"mongodb/mongodb": "^1.4"
22+
"illuminate/support": "^7.0",
23+
"illuminate/container": "^7.0",
24+
"illuminate/database": "^7.0",
25+
"illuminate/events": "^7.0",
26+
"mongodb/mongodb": "^1.6"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^6.0|^7.0|^8.0",
30-
"orchestra/testbench": "^3.1|^4.0",
31-
"mockery/mockery": "^1.0",
32-
"doctrine/dbal": "^2.5",
33-
"phpunit/phpcov": "^6.0",
29+
"phpunit/phpunit": "^8.4",
30+
"orchestra/testbench": "^5.0",
31+
"mockery/mockery": "^1.3.1",
32+
"doctrine/dbal": "^2.6",
3433
"cedx/coveralls": "^11.2"
3534
},
3635
"autoload": {

src/Jenssegers/Mongodb/Eloquent/Model.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -223,36 +223,37 @@ public function getCasts()
223223
/**
224224
* {@inheritdoc}
225225
*/
226-
public function originalIsEquivalent($key, $current)
226+
public function originalIsEquivalent($key)
227227
{
228228
if (! array_key_exists($key, $this->original)) {
229229
return false;
230230
}
231231

232-
$original = $this->getOriginal($key);
232+
$attribute = Arr::get($this->attributes, $key);
233+
$original = Arr::get($this->original, $key);
233234

234-
if ($current === $original) {
235+
if ($attribute === $original) {
235236
return true;
236237
}
237238

238-
if (null === $current) {
239+
if (null === $attribute) {
239240
return false;
240241
}
241242

242243
if ($this->isDateAttribute($key)) {
243-
$current = $current instanceof UTCDateTime ? $this->asDateTime($current) : $current;
244+
$attribute = $attribute instanceof UTCDateTime ? $this->asDateTime($attribute) : $attribute;
244245
$original = $original instanceof UTCDateTime ? $this->asDateTime($original) : $original;
245246

246-
return $current == $original;
247+
return $attribute == $original;
247248
}
248249

249-
if ($this->hasCast($key)) {
250-
return $this->castAttribute($key, $current) ===
250+
if ($this->hasCast($key, static::$primitiveCastTypes)) {
251+
return $this->castAttribute($key, $attribute) ===
251252
$this->castAttribute($key, $original);
252253
}
253254

254-
return is_numeric($current) && is_numeric($original)
255-
&& strcmp((string) $current, (string) $original) === 0;
255+
return is_numeric($attribute) && is_numeric($original)
256+
&& strcmp((string) $attribute, (string) $original) === 0;
256257
}
257258

258259
/**

tests/ModelTest.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,10 @@ public function testDates(): void
397397
$user = User::where('birthday', '>', new DateTime('1975/1/1'))->first();
398398
$this->assertEquals('John Doe', $user->name);
399399

400-
// test custom date format for json output
401-
$json = $user->toArray();
402-
$this->assertEquals($user->birthday->format('l jS \of F Y h:i:s A'), $json['birthday']);
403-
$this->assertEquals($user->created_at->format('l jS \of F Y h:i:s A'), $json['created_at']);
404-
405400
// test created_at
406401
$item = Item::create(['name' => 'sword']);
407-
$this->assertInstanceOf(UTCDateTime::class, $item->getOriginal('created_at'));
408-
$this->assertEquals($item->getOriginal('created_at')
402+
$this->assertInstanceOf(UTCDateTime::class, $item->getRawOriginal('created_at'));
403+
$this->assertEquals($item->getRawOriginal('created_at')
409404
->toDateTime()
410405
->getTimestamp(), $item->created_at->getTimestamp());
411406
$this->assertLessThan(2, abs(time() - $item->created_at->getTimestamp()));
@@ -414,7 +409,7 @@ public function testDates(): void
414409
/** @var Item $item */
415410
$item = Item::create(['name' => 'sword']);
416411
$json = $item->toArray();
417-
$this->assertEquals($item->created_at->format('Y-m-d H:i:s'), $json['created_at']);
412+
$this->assertEquals($item->created_at->format('Y-m-d\TH:i:s.u\Z'), $json['created_at']);
418413

419414
/** @var User $user */
420415
$user = User::create(['name' => 'Jane Doe', 'birthday' => time()]);

tests/QueueTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Carbon\Carbon;
6+
use Illuminate\Support\Str;
67
use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider;
78

89
class QueueTest extends TestCase
@@ -18,6 +19,12 @@ public function setUp(): void
1819

1920
public function testQueueJobLifeCycle(): void
2021
{
22+
$uuid = Str::uuid();
23+
24+
Str::createUuidsUsing(function () use ($uuid) {
25+
return $uuid;
26+
});
27+
2128
$id = Queue::push('test', ['action' => 'QueueJobLifeCycle'], 'test');
2229
$this->assertNotNull($id);
2330

@@ -26,9 +33,11 @@ public function testQueueJobLifeCycle(): void
2633
$this->assertInstanceOf(Jenssegers\Mongodb\Queue\MongoJob::class, $job);
2734
$this->assertEquals(1, $job->isReserved());
2835
$this->assertEquals(json_encode([
36+
'uuid' => $uuid,
2937
'displayName' => 'test',
3038
'job' => 'test',
3139
'maxTries' => null,
40+
'maxExceptions' => null,
3241
'delay' => null,
3342
'timeout' => null,
3443
'data' => ['action' => 'QueueJobLifeCycle'],
@@ -37,6 +46,8 @@ public function testQueueJobLifeCycle(): void
3746
// Remove reserved job
3847
$job->delete();
3948
$this->assertEquals(0, Queue::getDatabase()->table(Config::get('queue.connections.database.table'))->count());
49+
50+
Str::createUuidsNormally();
4051
}
4152

4253
public function testQueueJobExpired(): void

0 commit comments

Comments
 (0)