Skip to content

Commit 340aefe

Browse files
authored
Merge pull request #7 from GeneaLabs/laravel-5.5
Laravel 5.5
2 parents 1f71441 + 44e9f2b commit 340aefe

7 files changed

+32
-32
lines changed

Diff for: .gitattributes

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* text=auto
2+
3+
/.github export-ignore
4+
/.gitattributes export-ignore
5+
/.gitignore export-ignore
6+
/.scrutinizer.yml export-ignore
7+
/.travis.yml export-ignore
8+
/phpunit.xml export-ignore
9+
/tests export-ignore

Diff for: src/CachedBuilder.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,16 @@ protected function getQueryColumns(array $columns) : string
7373

7474
protected function getWhereClauses() : string
7575
{
76-
// dump($this->query->wheres);
7776
return collect($this->query->wheres)->reduce(function ($carry, $where) {
78-
if (! $where['column'] ?? false) {
79-
return $carry . '';
80-
}
81-
82-
$value = $where['value'] ?? '';
77+
$value = array_get($where, 'value');
8378

84-
if ($where['values'] ?? false) {
85-
$value .= 'in_' . implode('_', $where['values']);
79+
if (in_array($where['type'], ['In', 'Null', 'NotNull'])) {
80+
$value = strtolower($where['type']);
8681
}
8782

88-
$value = $where['type'] === 'Null' ? 'null' : $value;
83+
if (is_array(array_get($where, 'values'))) {
84+
$value .= '_' . implode('_', $where['values']);
85+
}
8986

9087
return "{$carry}-{$where['column']}_{$value}";
9188
}) ?: '';

Diff for: tests/Fixtures/UncachedBook.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
22

3-
use GeneaLabs\LaravelModelCaching\CachedModel;
3+
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Relations\BelongsTo;
55
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
66

7-
class UncachedBook extends CachedModel
7+
class UncachedBook extends Model
88
{
99
protected $dates = [
1010
'published_at',

Diff for: tests/Fixtures/UncachedProfile.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
22

3-
use GeneaLabs\LaravelModelCaching\CachedModel;
3+
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Relations\HasMany;
55
use Illuminate\Database\Eloquent\Relations\BelongsTo;
66

7-
class UncachedProfile extends CachedModel
7+
class UncachedProfile extends Model
88
{
99
protected $fillable = [
1010
'first_name',

Diff for: tests/Fixtures/UncachedPublisher.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
22

3-
use GeneaLabs\LaravelModelCaching\CachedModel;
3+
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Relations\HasMany;
55

6-
class UncachedPublisher extends CachedModel
6+
class UncachedPublisher extends Model
77
{
88
protected $fillable = [
99
'name',

Diff for: tests/Fixtures/UncachedStore.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
22

3-
use GeneaLabs\LaravelModelCaching\CachedModel;
3+
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
55

6-
class UncachedStore extends CachedModel
6+
class UncachedStore extends Model
77
{
88
protected $fillable = [
99
'address',

Diff for: tests/Unit/CachedBuilderTest.php

+9-15
Original file line numberDiff line numberDiff line change
@@ -415,26 +415,20 @@ public function testValueModelResultsCreatesCache()
415415

416416
public function testNestedRelationshipEagerloading()
417417
{
418-
$authors = collect()->push(
419-
(new Author)->with('books.publisher')
420-
->first()
421-
);
418+
$authors = collect([(new Author)->with('books.publisher')
419+
->first()]);
420+
422421
$key = 'genealabslaravelmodelcachingtestsfixturesauthor-books-books.publisher-first';
423422
$tags = [
424423
'genealabslaravelmodelcachingtestsfixturesauthor',
425424
'genealabslaravelmodelcachingtestsfixturesbook',
426425
'genealabslaravelmodelcachingtestsfixturespublisher',
427426
];
428427

429-
$cachedResults = collect()->push(
430-
cache()->tags($tags)
431-
->get($key)
432-
);
433-
434-
$liveResults = collect()->push(
435-
(new UncachedAuthor)->with('books.publisher')
436-
->first()
437-
);
428+
$cachedResults = collect([cache()->tags($tags)
429+
->get($key)]);
430+
$liveResults = collect([(new UncachedAuthor)->with('books.publisher')
431+
->first()]);
438432

439433
$this->assertEmpty($authors->diffAssoc($cachedResults));
440434
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
@@ -443,7 +437,7 @@ public function testNestedRelationshipEagerloading()
443437
public function testLazyLoadedRelationshipResolvesThroughCachedBuilder()
444438
{
445439
$books = (new Author)->first()->books;
446-
$key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1';
440+
$key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1-books.author_id_notnull';
447441
$tags = [
448442
'genealabslaravelmodelcachingtestsfixturesbook',
449443
];
@@ -458,7 +452,7 @@ public function testLazyLoadedRelationshipResolvesThroughCachedBuilder()
458452
public function testLazyLoadingOnResourceIsCached()
459453
{
460454
$books = (new AuthorResource((new Author)->first()))->books;
461-
$key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1';
455+
$key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1-books.author_id_notnull';
462456
$tags = [
463457
'genealabslaravelmodelcachingtestsfixturesbook',
464458
];

0 commit comments

Comments
 (0)