|
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 | }
|
@@ -453,4 +454,20 @@ public function testNonEagerloadedRelationshipResolvesThroughCachedBuilder()
|
453 | 454 | $this->assertEmpty($books->diffAssoc($cachedResults));
|
454 | 455 | $this->assertEmpty($liveResults->diffAssoc($cachedResults));
|
455 | 456 | }
|
| 457 | + |
| 458 | + public function testLazyLoadingOnResourceIsCached() |
| 459 | + { |
| 460 | + $books = (new AuthorResource((new Author)->first()))->books; |
| 461 | + $key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1-books.author_id_'; |
| 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 | + } |
| 472 | + |
456 | 473 | }
|
0 commit comments