Skip to content

Commit

Permalink
fix getOriginal for Laravel 8
Browse files Browse the repository at this point in the history
  • Loading branch information
halaei committed Jun 7, 2021
1 parent a323c59 commit 17f7247
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@ php:
- 7.4
- 8.0

env:
- LARAVEL_VERSION=6.*
- LARAVEL_VERSION=8.*

services:
- redis-server

before_install:
- composer require "illuminate/console:${LARAVEL_VERSION}" --no-update --prefer-dist
- composer require "illuminate/support:${LARAVEL_VERSION}" --no-update --prefer-dist
- composer require "illuminate/support:${LARAVEL_VERSION}" --no-update --prefer-dist
- composer require "illuminate/support:${LARAVEL_VERSION}" --no-update --prefer-dist
install:
- composer install --no-interaction --prefer-source
script: vendor/bin/phpunit
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

#v0.9
- Minimum Laravel version: 8.
- Fix getOriginal() for Laravel >= 7.

#v0.8.0
- Drop support for old PHP and Laravel versions.
- Fix reporting throwable by calling `report()` helper function.
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
},
"require-dev": {
"predis/predis": "^1.1",
"illuminate/console": "^6.0|^7.0|^8.0",
"illuminate/cache": "^6.0|^7.0|^8.0",
"illuminate/database": "^6.0|^7.0|^8.0",
"illuminate/console": "^8.0",
"illuminate/cache": "^8.0",
"illuminate/database": "^8.0",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^8.0|^9.0",
"symfony/process": "^4.2|^5.0"
"phpunit/phpunit": "^9.0",
"symfony/process": "^5.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Eloquent/EloquentCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function find($id, $useCache = true)
$model = $this->model->newQuery()->where('id', '=', $id)->firstOrFail();

if ($useCache) {
$this->cache->put($key, $model->getOriginal(), $this->cacheDuration());
$this->cache->put($key, $model->getRawOriginal(), $this->cacheDuration());
}

return $model;
Expand Down Expand Up @@ -140,7 +140,7 @@ public function findBySecondaryKey(array $secondary, $useCache = true)
$model = $this->model->newQuery()->where($secondary)->firstOrFail();
$this->cache->putMany([
$secondaryKey => $model->getKey(),
$this->getPrimaryCacheKey($model->getKey()) => $model->getOriginal(),
$this->getPrimaryCacheKey($model->getKey()) => $model->getRawOriginal(),
], $this->cacheDuration());
} else {
$model = $this->find($id);
Expand Down
6 changes: 3 additions & 3 deletions tests/EloquentCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function test_find_from_db()
$this->cacheable->shouldReceive('newQuery')->once()->andReturnSelf();
$this->cacheable->shouldReceive('where')->once()->with('id', '=', 2)->andReturnSelf();
$this->cacheable->shouldReceive('firstOrFail')->once()->andReturnSelf();
$this->cacheable->shouldReceive('getOriginal')->once()->andReturn(['id' => 2, 'column' => 'value']);
$this->cacheable->shouldReceive('getRawOriginal')->once()->andReturn(['id' => 2, 'column' => 'value']);
$this->cache->shouldReceive('put')->once()
->with('elq-ch:cacheable_models:2', ['id' => 2, 'column' => 'value'], Mockery::on(function (Carbon $time) {
return Carbon::now()->timestamp + 600 === $time->timestamp;
Expand Down Expand Up @@ -103,7 +103,7 @@ public function test_find_by_secondary_id_from_cache_model_from_db()
$this->model->shouldReceive('newQuery')->once()->andReturnSelf();
$this->model->shouldReceive('where')->once()->with('id', '=', 3)->andReturnSelf();
$this->model->shouldReceive('firstOrFail')->once()->andReturnSelf();
$this->model->shouldReceive('getOriginal')->once()->andReturn(['id' => 3, 'column' => 'value']);
$this->model->shouldReceive('getRawOriginal')->once()->andReturn(['id' => 3, 'column' => 'value']);
$this->cache->shouldReceive('put')->once()
->with('elq-ch:cached_models:3', ['id' => 3, 'column' => 'value'], Mockery::on(function (Carbon $time) {
return Carbon::now()->timestamp + 600 === $time->timestamp;
Expand All @@ -121,7 +121,7 @@ public function test_find_by_secondary_from_db()
$this->model->shouldReceive('where')->once()->with(['column1' => 'value1', 'column2' => 'value2'])->andReturnSelf();
$this->model->shouldReceive('firstOrFail')->once()->andReturnSelf();
$this->model->shouldReceive('getKey')->twice()->andReturn(3);
$this->model->shouldReceive('getOriginal')->once()->andReturn(['id' => 3, 'column1' => 'value1', 'column2' => 'value2']);
$this->model->shouldReceive('getRawOriginal')->once()->andReturn(['id' => 3, 'column1' => 'value1', 'column2' => 'value2']);
$this->cache->shouldReceive('putMany')->once()->with([
'elq-ch:cached_models:3' => ['id' => 3, 'column1' => 'value1', 'column2' => 'value2'],
'elq-ch:cached_models:s:column1,column2:value1,value2' => 3,
Expand Down

0 comments on commit 17f7247

Please sign in to comment.