|
| 1 | +<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder; |
| 2 | + |
| 3 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; |
| 4 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book; |
| 5 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile; |
| 6 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher; |
| 7 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store; |
| 8 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; |
| 9 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook; |
| 10 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile; |
| 11 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher; |
| 12 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore; |
| 13 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource; |
| 14 | +use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; |
| 15 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 16 | +use Illuminate\Support\Collection; |
| 17 | + |
| 18 | +class ModelScopeTest extends IntegrationTestCase |
| 19 | +{ |
| 20 | + public function testScopeClauseParsing() |
| 21 | + { |
| 22 | + $author = factory(Author::class, 1) |
| 23 | + ->create(['name' => 'Anton']) |
| 24 | + ->first(); |
| 25 | + $authors = (new Author) |
| 26 | + ->startsWithA() |
| 27 | + ->get(); |
| 28 | + $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_A%'); |
| 29 | + $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; |
| 30 | + |
| 31 | + $cachedResults = $this->cache() |
| 32 | + ->tags($tags) |
| 33 | + ->get($key)['value']; |
| 34 | + $liveResults = (new UncachedAuthor) |
| 35 | + ->startsWithA() |
| 36 | + ->get(); |
| 37 | + |
| 38 | + $this->assertTrue($authors->contains($author)); |
| 39 | + $this->assertTrue($cachedResults->contains($author)); |
| 40 | + $this->assertTrue($liveResults->contains($author)); |
| 41 | + } |
| 42 | + |
| 43 | + public function testScopeClauseWithParameter() |
| 44 | + { |
| 45 | + $author = factory(Author::class, 1) |
| 46 | + ->create(['name' => 'Boris']) |
| 47 | + ->first(); |
| 48 | + $authors = (new Author) |
| 49 | + ->nameStartsWith("B") |
| 50 | + ->get(); |
| 51 | + $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_B%'); |
| 52 | + $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; |
| 53 | + |
| 54 | + $cachedResults = $this->cache() |
| 55 | + ->tags($tags) |
| 56 | + ->get($key)['value']; |
| 57 | + $liveResults = (new UncachedAuthor) |
| 58 | + ->nameStartsWith("B") |
| 59 | + ->get(); |
| 60 | + |
| 61 | + $this->assertTrue($authors->contains($author)); |
| 62 | + $this->assertTrue($cachedResults->contains($author)); |
| 63 | + $this->assertTrue($liveResults->contains($author)); |
| 64 | + } |
| 65 | +} |
0 commit comments