|
1 | 1 | <?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder;
|
2 | 2 |
|
| 3 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; |
3 | 4 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
|
| 5 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; |
4 | 6 | use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
|
5 | 7 |
|
6 | 8 | class SelectTest extends IntegrationTestCase
|
@@ -38,28 +40,51 @@ public function testSelectWithRawColumns()
|
38 | 40 | $this->assertEquals($liveResults, $cachedResults);
|
39 | 41 | }
|
40 | 42 |
|
41 |
| - // public function testSelectFieldsAreCached() |
42 |
| - // { |
43 |
| - // $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name-first"); |
44 |
| - // $tags = [ |
45 |
| - // "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
46 |
| - // ]; |
| 43 | + public function testSelectFieldsAreCached() |
| 44 | + { |
| 45 | + $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name-first"); |
| 46 | + $tags = [ |
| 47 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
| 48 | + ]; |
| 49 | + |
| 50 | + $authorFields = (new Author) |
| 51 | + ->select("id", "name") |
| 52 | + ->first() |
| 53 | + ->getAttributes(); |
| 54 | + $uncachedFields = (new UncachedAuthor) |
| 55 | + ->select("id", "name") |
| 56 | + ->first() |
| 57 | + ->getAttributes(); |
| 58 | + $cachedFields = $this |
| 59 | + ->cache() |
| 60 | + ->tags($tags) |
| 61 | + ->get($key)['value'] |
| 62 | + ->getAttributes(); |
| 63 | + |
| 64 | + $this->assertEquals($cachedFields, $authorFields); |
| 65 | + $this->assertEquals($cachedFields, $uncachedFields); |
| 66 | + } |
| 67 | + |
| 68 | + /** @group test */ |
| 69 | + public function testAddSelectMethod() |
| 70 | + { |
| 71 | + $key = sha1("genealabs:laravel-model-caching:testing:/Users/mike/Developer/Sites/laravel-model-caching/tests/database/testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor_(SELECT id FROM authors WHERE id = 1)-first"); |
| 72 | + $tags = [ |
| 73 | + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
| 74 | + ]; |
47 | 75 |
|
48 |
| - // $authorFields = (new Author) |
49 |
| - // ->select("id", "name") |
50 |
| - // ->first() |
51 |
| - // ->getAttributes(); |
52 |
| - // $uncachedFields = (new UncachedAuthor) |
53 |
| - // ->select("id", "name") |
54 |
| - // ->first() |
55 |
| - // ->getAttributes(); |
56 |
| - // $cachedFields = $this |
57 |
| - // ->cache() |
58 |
| - // ->tags($tags) |
59 |
| - // ->get($key)['value'] |
60 |
| - // ->getAttributes(); |
| 76 | + $result = (new Author) |
| 77 | + ->addSelect(app("db")->raw("(SELECT id FROM authors WHERE id = 1)")) |
| 78 | + ->first(); |
| 79 | + $uncachedResult = (new UncachedAuthor) |
| 80 | + ->addSelect(app("db")->raw("(SELECT id FROM authors WHERE id = 1)")) |
| 81 | + ->first(); |
| 82 | + $uncachedResult = $this |
| 83 | + ->cache() |
| 84 | + ->tags($tags) |
| 85 | + ->get($key)['value']; |
61 | 86 |
|
62 |
| - // $this->assertEquals($cachedFields, $authorFields); |
63 |
| - // $this->assertEquals($cachedFields, $uncachedFields); |
64 |
| - // } |
| 87 | + $this->assertEquals($uncachedResult, $result); |
| 88 | + $this->assertEquals($uncachedResult, $uncachedResult); |
| 89 | + } |
65 | 90 | }
|
0 commit comments