|
5 | 5 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; |
6 | 6 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource; |
7 | 7 | use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; |
| 8 | +use Illuminate\Database\Query\Expression; |
8 | 9 | use Illuminate\Support\Str; |
9 | 10 |
|
10 | 11 | /** |
@@ -180,6 +181,27 @@ public function testAvgModelResultsCreatesCache() |
180 | 181 | $this->assertEquals($liveResult, $cachedResult); |
181 | 182 | } |
182 | 183 |
|
| 184 | + public function testRawAvgModelResultsCreatesCache() |
| 185 | + { |
| 186 | + $authorId = (new Author)->with('books', 'profile') |
| 187 | + ->avg(new Expression('id + id')); |
| 188 | + $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-testing:{$this->testingSqlitePath}testing.sqlite:books-testing:{$this->testingSqlitePath}testing.sqlite:profile-avg_id + id"); |
| 189 | + $tags = [ |
| 190 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
| 191 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook", |
| 192 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesprofile", |
| 193 | + ]; |
| 194 | + |
| 195 | + $cachedResult = $this->cache() |
| 196 | + ->tags($tags) |
| 197 | + ->get($key)['value']; |
| 198 | + $liveResult = (new UncachedAuthor)->with('books', 'profile') |
| 199 | + ->avg(new Expression('id + id')); |
| 200 | + |
| 201 | + $this->assertEquals($authorId, $cachedResult); |
| 202 | + $this->assertEquals($liveResult, $cachedResult); |
| 203 | + } |
| 204 | + |
183 | 205 | public function testChunkModelResultsCreatesCache() |
184 | 206 | { |
185 | 207 | $chunkedAuthors = []; |
@@ -356,6 +378,26 @@ public function testSumModelResultsCreatesCache() |
356 | 378 | $this->assertEquals($liveResult, $cachedResult); |
357 | 379 | } |
358 | 380 |
|
| 381 | + public function testRawSumModelResultsCreatesCache() |
| 382 | + { |
| 383 | + $authorId = (new Author)->with('books', 'profile') |
| 384 | + ->sum(new Expression('`id` + `id`')); |
| 385 | + $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-testing:{$this->testingSqlitePath}testing.sqlite:books-testing:{$this->testingSqlitePath}testing.sqlite:profile-sum_`id` + `id`"); |
| 386 | + $tags = [ |
| 387 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
| 388 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook", |
| 389 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesprofile", |
| 390 | + ]; |
| 391 | + |
| 392 | + $cachedResult = $this->cache()->tags($tags) |
| 393 | + ->get($key)['value']; |
| 394 | + $liveResult = (new UncachedAuthor)->with('books', 'profile') |
| 395 | + ->sum(new Expression('`id` + `id`')); |
| 396 | + |
| 397 | + $this->assertEquals($authorId, $cachedResult); |
| 398 | + $this->assertEquals($liveResult, $cachedResult); |
| 399 | + } |
| 400 | + |
359 | 401 | public function testValueModelResultsCreatesCache() |
360 | 402 | { |
361 | 403 | $authorName = (new Author)->with('books', 'profile') |
|
0 commit comments