|
10 | 10 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile;
|
11 | 11 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher;
|
12 | 12 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore;
|
| 13 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource; |
13 | 14 | use GeneaLabs\LaravelModelCaching\Tests\TestCase;
|
14 | 15 | use Illuminate\Foundation\Testing\RefreshDatabase;
|
15 | 16 |
|
@@ -53,7 +54,7 @@ public function testCacheIsEmptyBeforeLoadingModels()
|
53 | 54 | 'genealabslaravelmodelcachingtestsfixturesauthor',
|
54 | 55 | 'genealabslaravelmodelcachingtestsfixturesbook'
|
55 | 56 | ])
|
56 |
| - ->get('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks'); |
| 57 | + ->get('genealabslaravelmodelcachingtestsfixturesauthor-books'); |
57 | 58 |
|
58 | 59 | $this->assertNull($results);
|
59 | 60 | }
|
@@ -438,4 +439,34 @@ public function testNestedRelationshipEagerloading()
|
438 | 439 | $this->assertEmpty($authors->diffAssoc($cachedResults));
|
439 | 440 | $this->assertEmpty($liveResults->diffAssoc($cachedResults));
|
440 | 441 | }
|
| 442 | + |
| 443 | + public function testLazyLoadedRelationshipResolvesThroughCachedBuilder() |
| 444 | + { |
| 445 | + $books = (new Author)->first()->books; |
| 446 | + $key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1'; |
| 447 | + $tags = [ |
| 448 | + 'genealabslaravelmodelcachingtestsfixturesbook', |
| 449 | + ]; |
| 450 | + |
| 451 | + $cachedResults = cache()->tags($tags)->get($key); |
| 452 | + $liveResults = (new UncachedAuthor)->first()->books; |
| 453 | + |
| 454 | + $this->assertEmpty($books->diffAssoc($cachedResults)); |
| 455 | + $this->assertEmpty($liveResults->diffAssoc($cachedResults)); |
| 456 | + } |
| 457 | + |
| 458 | + public function testLazyLoadingOnResourceIsCached() |
| 459 | + { |
| 460 | + $books = (new AuthorResource((new Author)->first()))->books; |
| 461 | + $key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1'; |
| 462 | + $tags = [ |
| 463 | + 'genealabslaravelmodelcachingtestsfixturesbook', |
| 464 | + ]; |
| 465 | + |
| 466 | + $cachedResults = cache()->tags($tags)->get($key); |
| 467 | + $liveResults = (new UncachedAuthor)->first()->books; |
| 468 | + |
| 469 | + $this->assertEmpty($books->diffAssoc($cachedResults)); |
| 470 | + $this->assertEmpty($liveResults->diffAssoc($cachedResults)); |
| 471 | + } |
441 | 472 | }
|
0 commit comments