|
| 1 | +<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder; |
| 2 | + |
| 3 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; |
| 4 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Supplier; |
| 5 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; |
| 6 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedSupplier; |
| 7 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedUser; |
| 8 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\User; |
| 9 | +use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; |
| 10 | + |
| 11 | +class PolymorphicOneToOneTest extends IntegrationTestCase |
| 12 | +{ |
| 13 | + public function testEagerloadedRelationship() |
| 14 | + { |
| 15 | + $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:images:genealabslaravelmodelcachingtestsfixturesimage-images.imagable_id_inraw_2-images.imagable_type_=_GeneaLabs\LaravelModelCaching\Tests\Fixtures\User"); |
| 16 | + $tags = [ |
| 17 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesimage", |
| 18 | + ]; |
| 19 | + |
| 20 | + $result = (new User) |
| 21 | + ->with("image") |
| 22 | + ->whereHas("image") |
| 23 | + ->first() |
| 24 | + ->image; |
| 25 | + $cachedResults = $this->cache() |
| 26 | + ->tags($tags) |
| 27 | + ->get($key)['value'] |
| 28 | + ->first(); |
| 29 | + $liveResults = (new UncachedUser) |
| 30 | + ->with("image") |
| 31 | + ->whereHas("image") |
| 32 | + ->first() |
| 33 | + ->image; |
| 34 | + |
| 35 | + $this->assertEquals($liveResults->path, $result->path); |
| 36 | + $this->assertEquals($liveResults->path, $cachedResults->path); |
| 37 | + $this->assertNotEmpty($result); |
| 38 | + $this->assertNotEmpty($cachedResults); |
| 39 | + $this->assertNotEmpty($liveResults); |
| 40 | + } |
| 41 | + |
| 42 | + /** @group test */ |
| 43 | + public function testLazyloadedHasOneThrough() |
| 44 | + { |
| 45 | + $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:images:genealabslaravelmodelcachingtestsfixturesimage-images.imagable_id_=_2-images.imagable_id_notnull-images.imagable_type_=_GeneaLabs\LaravelModelCaching\Tests\Fixtures\User-limit_1"); |
| 46 | + $tags = [ |
| 47 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesimage", |
| 48 | + ]; |
| 49 | + |
| 50 | + $result = (new User) |
| 51 | + ->whereHas("image") |
| 52 | + ->first() |
| 53 | + ->image; |
| 54 | + $cachedResults = $this->cache() |
| 55 | + ->tags($tags) |
| 56 | + ->get($key)['value'] |
| 57 | + ->first(); |
| 58 | + $liveResults = (new UncachedUser) |
| 59 | + ->whereHas("image") |
| 60 | + ->first() |
| 61 | + ->image; |
| 62 | + |
| 63 | + $this->assertEquals($liveResults->path, $result->path); |
| 64 | + $this->assertEquals($liveResults->path, $cachedResults->path); |
| 65 | + $this->assertNotEmpty($result); |
| 66 | + $this->assertNotEmpty($cachedResults); |
| 67 | + $this->assertNotEmpty($liveResults); |
| 68 | + } |
| 69 | +} |
0 commit comments