Unverified Commit ec89233a authored by Stas's avatar Stas Committed by GitHub

Merge pull request #1988 from divine/laravel_7

[4.x] Laravel 7
parents b379bd39 c5498ef9
...@@ -11,7 +11,7 @@ jobs: ...@@ -11,7 +11,7 @@ jobs:
runs-on: ${{matrix.os}} runs-on: ${{matrix.os}}
strategy: strategy:
matrix: matrix:
php: ['7.1', '7.2', '7.3', '7.4'] php: ['7.2', '7.3', '7.4']
os: ['ubuntu-latest'] os: ['ubuntu-latest']
mongodb: ['3.6', '4.0', '4.2'] mongodb: ['3.6', '4.0', '4.2']
services: services:
......
...@@ -2,6 +2,13 @@ ...@@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [Unreleased] ## [Unreleased]
### Added
- Laravel 7 support by [@divine](https://github.com/divine).
### Changed
- Updated versions of all dependencies by [@divine](https://github.com/divine)
### Removed ### Removed
- EmbedsOne and EmbedsMany relations by [@divine](https://github.com/divine). - EmbedsOne and EmbedsMany relations by [@divine](https://github.com/divine).
- shouldUseCollections function by [@divine](https://github.com/divine). - shouldUseCollections function by [@divine](https://github.com/divine).
...@@ -62,6 +62,7 @@ Make sure you have the MongoDB PHP driver installed. You can find installation i ...@@ -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.7.x | 3.4.x
5.8.x | 3.5.x 5.8.x | 3.5.x
6.x | 3.6.x 6.x | 3.6.x
7.x | 4.x
Install the package via Composer: Install the package via Composer:
......
...@@ -19,18 +19,17 @@ ...@@ -19,18 +19,17 @@
], ],
"license": "MIT", "license": "MIT",
"require": { "require": {
"illuminate/support": "^5.8|^6.0", "illuminate/support": "^7.0",
"illuminate/container": "^5.8|^6.0", "illuminate/container": "^7.0",
"illuminate/database": "^5.8|^6.0", "illuminate/database": "^7.0",
"illuminate/events": "^5.8|^6.0", "illuminate/events": "^7.0",
"mongodb/mongodb": "^1.4" "mongodb/mongodb": "^1.6"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^6.0|^7.0|^8.0", "phpunit/phpunit": "^8.4",
"orchestra/testbench": "^3.1|^4.0", "orchestra/testbench": "^5.0",
"mockery/mockery": "^1.0", "mockery/mockery": "^1.3.1",
"doctrine/dbal": "^2.5", "doctrine/dbal": "^2.6",
"phpunit/phpcov": "^6.0",
"cedx/coveralls": "^11.2" "cedx/coveralls": "^11.2"
}, },
"autoload": { "autoload": {
......
...@@ -223,36 +223,37 @@ abstract class Model extends BaseModel ...@@ -223,36 +223,37 @@ abstract class Model extends BaseModel
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function originalIsEquivalent($key, $current) public function originalIsEquivalent($key)
{ {
if (! array_key_exists($key, $this->original)) { if (! array_key_exists($key, $this->original)) {
return false; 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; return true;
} }
if (null === $current) { if (null === $attribute) {
return false; return false;
} }
if ($this->isDateAttribute($key)) { 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; $original = $original instanceof UTCDateTime ? $this->asDateTime($original) : $original;
return $current == $original; return $attribute == $original;
} }
if ($this->hasCast($key)) { if ($this->hasCast($key, static::$primitiveCastTypes)) {
return $this->castAttribute($key, $current) === return $this->castAttribute($key, $attribute) ===
$this->castAttribute($key, $original); $this->castAttribute($key, $original);
} }
return is_numeric($current) && is_numeric($original) return is_numeric($attribute) && is_numeric($original)
&& strcmp((string) $current, (string) $original) === 0; && strcmp((string) $attribute, (string) $original) === 0;
} }
/** /**
......
...@@ -397,15 +397,10 @@ class ModelTest extends TestCase ...@@ -397,15 +397,10 @@ class ModelTest extends TestCase
$user = User::where('birthday', '>', new DateTime('1975/1/1'))->first(); $user = User::where('birthday', '>', new DateTime('1975/1/1'))->first();
$this->assertEquals('John Doe', $user->name); $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 // test created_at
$item = Item::create(['name' => 'sword']); $item = Item::create(['name' => 'sword']);
$this->assertInstanceOf(UTCDateTime::class, $item->getOriginal('created_at')); $this->assertInstanceOf(UTCDateTime::class, $item->getRawOriginal('created_at'));
$this->assertEquals($item->getOriginal('created_at') $this->assertEquals($item->getRawOriginal('created_at')
->toDateTime() ->toDateTime()
->getTimestamp(), $item->created_at->getTimestamp()); ->getTimestamp(), $item->created_at->getTimestamp());
$this->assertLessThan(2, abs(time() - $item->created_at->getTimestamp())); $this->assertLessThan(2, abs(time() - $item->created_at->getTimestamp()));
...@@ -414,7 +409,7 @@ class ModelTest extends TestCase ...@@ -414,7 +409,7 @@ class ModelTest extends TestCase
/** @var Item $item */ /** @var Item $item */
$item = Item::create(['name' => 'sword']); $item = Item::create(['name' => 'sword']);
$json = $item->toArray(); $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 */ /** @var User $user */
$user = User::create(['name' => 'Jane Doe', 'birthday' => time()]); $user = User::create(['name' => 'Jane Doe', 'birthday' => time()]);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
declare(strict_types=1); declare(strict_types=1);
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Str;
use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider; use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider;
class QueueTest extends TestCase class QueueTest extends TestCase
...@@ -18,6 +19,12 @@ class QueueTest extends TestCase ...@@ -18,6 +19,12 @@ class QueueTest extends TestCase
public function testQueueJobLifeCycle(): void public function testQueueJobLifeCycle(): void
{ {
$uuid = Str::uuid();
Str::createUuidsUsing(function () use ($uuid) {
return $uuid;
});
$id = Queue::push('test', ['action' => 'QueueJobLifeCycle'], 'test'); $id = Queue::push('test', ['action' => 'QueueJobLifeCycle'], 'test');
$this->assertNotNull($id); $this->assertNotNull($id);
...@@ -26,9 +33,11 @@ class QueueTest extends TestCase ...@@ -26,9 +33,11 @@ class QueueTest extends TestCase
$this->assertInstanceOf(Jenssegers\Mongodb\Queue\MongoJob::class, $job); $this->assertInstanceOf(Jenssegers\Mongodb\Queue\MongoJob::class, $job);
$this->assertEquals(1, $job->isReserved()); $this->assertEquals(1, $job->isReserved());
$this->assertEquals(json_encode([ $this->assertEquals(json_encode([
'uuid' => $uuid,
'displayName' => 'test', 'displayName' => 'test',
'job' => 'test', 'job' => 'test',
'maxTries' => null, 'maxTries' => null,
'maxExceptions' => null,
'delay' => null, 'delay' => null,
'timeout' => null, 'timeout' => null,
'data' => ['action' => 'QueueJobLifeCycle'], 'data' => ['action' => 'QueueJobLifeCycle'],
...@@ -37,6 +46,8 @@ class QueueTest extends TestCase ...@@ -37,6 +46,8 @@ class QueueTest extends TestCase
// Remove reserved job // Remove reserved job
$job->delete(); $job->delete();
$this->assertEquals(0, Queue::getDatabase()->table(Config::get('queue.connections.database.table'))->count()); $this->assertEquals(0, Queue::getDatabase()->table(Config::get('queue.connections.database.table'))->count());
Str::createUuidsNormally();
} }
public function testQueueJobExpired(): void public function testQueueJobExpired(): void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment