Skip to content

Commit

Permalink
Merge branch 'hotfix/fix-first-not-returning-unique-results'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Mar 10, 2018
2 parents 3dd4b42 + e53999c commit 91173bd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/CachedBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function first($columns = ["*"])
return parent::first($columns);
}

$cacheKey = $this->makeCacheKey($columns);
$cacheKey = $this->makeCacheKey($columns, null, "-first");

return $this->cachedValue(func_get_args(), $cacheKey);
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Integration/CachedBuilderMultipleQueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration;

use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore;
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource;
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Collection;

class CachedBuilderMultipleQueryTest extends IntegrationTestCase
{
use RefreshDatabase;

public function testCallingAllThenFirstQueriesReturnsDifferingResults()
{
$allAuthors = (new Author)->all();
$firstAuthor = (new Author)->first();

$this->assertNotEquals($allAuthors, $firstAuthor);
$this->assertInstanceOf(Author::class, $firstAuthor);
$this->assertInstanceOf(Collection::class, $allAuthors);
}

public function testCallingGetThenFirstQueriesReturnsDifferingResults()
{
$allAuthors = (new Author)->get();
$firstAuthor = (new Author)->first();

$this->assertNotEquals($allAuthors, $firstAuthor);
$this->assertInstanceOf(Author::class, $firstAuthor);
$this->assertInstanceOf(Collection::class, $allAuthors);
}
}
2 changes: 1 addition & 1 deletion tests/Integration/CachedBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function testFirstModelResultsCreatesCache()
{
$author = (new Author)
->first();
$key = sha1('genealabs:laravel-model-caching:testing:genealabslaravelmodelcachingtestsfixturesauthor');
$key = sha1('genealabs:laravel-model-caching:testing:genealabslaravelmodelcachingtestsfixturesauthor-first');
$tags = [
'genealabs:laravel-model-caching:testing:genealabslaravelmodelcachingtestsfixturesauthor',
];
Expand Down

0 comments on commit 91173bd

Please sign in to comment.