Skip to content

Commit 24f0d70

Browse files
authored
Merge pull request #25 from GeneaLabs/laravel-5.5
Laravel 5.5
2 parents c9d498d + a7e0564 commit 24f0d70

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.2.7] - 2017-10-16
8+
### Added
9+
- remaining unit tests that were incomplete, thanks everyone who participated!
10+
- added parsing of where `doesnthave()` condition.
11+
712
## [0.2.6] - 2017-10-12
813
### Added
914
- orderBy clause to cache key. Thanks @RobMKR for the PR!

Diff for: src/CachedBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ protected function getWhereClauses(array $wheres = []) : string
8181
}
8282

8383
return $wheres->reduce(function ($carry, $where) {
84-
if (in_array($where['type'], ['Exists', 'Nested'])) {
85-
return $this->getWhereClauses($where['query']->wheres);
84+
if (in_array($where['type'], ['Exists', 'Nested', 'NotExists'])) {
85+
return '_' . strtolower($where['type']) . $this->getWhereClauses($where['query']->wheres);
8686
}
8787

8888
if ($where['type'] === 'Column') {

Diff for: tests/Unit/CachedBuilderTest.php

+40-16
Original file line numberDiff line numberDiff line change
@@ -504,34 +504,58 @@ public function testNestedRelationshipWhereClauseParsing()
504504

505505
public function testExistsRelationshipWhereClauseParsing()
506506
{
507+
$authors = (new Author)->whereHas('books')
508+
->get();
507509

508-
$authors = collect([(new Author)->whereHas('books')->first()]);
509-
510-
$key = 'genealabslaravelmodelcachingtestsfixturesauthor_and_authors.id_=_books.author_id-first';
510+
$key = 'genealabslaravelmodelcachingtestsfixturesauthor_exists_and_authors.id_=_books.author_id';
511511
$tags = ['genealabslaravelmodelcachingtestsfixturesauthor'];
512512

513-
$cachedResults = collect([cache()->tags($tags)->get($key)]);
513+
$cachedResults = cache()->tags($tags)->get($key);
514+
$liveResults = (new UncachedAuthor)->whereHas('books')
515+
->get();
514516

515-
$liveResults = collect([(new UncachedAuthor)
516-
->whereHas('books')->first()]);
517+
$this->assertEmpty($authors->diffAssoc($cachedResults));
518+
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
519+
}
517520

518-
$this->assertTrue($authors->diffAssoc($cachedResults)->isEmpty());
519-
$this->assertTrue($liveResults->diffAssoc($cachedResults)->isEmpty());
521+
public function testDoesntHaveWhereClaseParsing()
522+
{
523+
$authors = (new Author)
524+
->doesntHave('books')
525+
->get();
526+
527+
$key = 'genealabslaravelmodelcachingtestsfixturesauthor_notexists_and_authors.id_=_books.author_id';
528+
$tags = ['genealabslaravelmodelcachingtestsfixturesauthor'];
529+
530+
$cachedResults = cache()
531+
->tags($tags)
532+
->get($key);
533+
$liveResults = (new UncachedAuthor)
534+
->doesntHave('books')
535+
->get();
520536

537+
$this->assertEmpty($authors->diffAssoc($cachedResults));
538+
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
521539
}
522540

523541
public function testColumnsRelationshipWhereClauseParsing()
524542
{
525-
$author = (new Author)->orderBy('name')->first();
526-
527-
$authors = collect([(new Author)->where('name', '=', $author->name)->first()]);
528-
529-
$key = 'genealabslaravelmodelcachingtestsfixturesauthor-name_' . $author->name . '-first';
543+
$author = (new Author)
544+
->orderBy('name')
545+
->first();
546+
$authors = (new Author)
547+
->where('name', '=', $author->name)
548+
->get();
549+
$key = 'genealabslaravelmodelcachingtestsfixturesauthor-name_' .
550+
$author->name;
530551
$tags = ['genealabslaravelmodelcachingtestsfixturesauthor'];
531552

532-
$cachedResults = collect([cache()->tags($tags)->get($key)]);
533-
534-
$liveResults = collect([(new UncachedAuthor)->where('name', '=', $author->name)->first()]);
553+
$cachedResults = cache()
554+
->tags($tags)
555+
->get($key);
556+
$liveResults = (new UncachedAuthor)
557+
->where('name', '=', $author->name)
558+
->get();
535559

536560
$this->assertEmpty($authors->diffAssoc($cachedResults));
537561
$this->assertEmpty($liveResults->diffAssoc($cachedResults));

0 commit comments

Comments
 (0)