|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rennokki\QueryCache\Test; |
| 4 | + |
| 5 | +use Cache; |
| 6 | +use Rennokki\QueryCache\Test\Models\Post; |
| 7 | + |
| 8 | +class MethodsTest extends TestCase |
| 9 | +{ |
| 10 | + public function test_do_not_cache() |
| 11 | + { |
| 12 | + $post = factory(Post::class)->create(); |
| 13 | + |
| 14 | + $storedPost = Post::cacheFor(now()->addHours(1))->doNotCache()->first(); |
| 15 | + $cache = Cache::get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); |
| 16 | + $this->assertNull($cache); |
| 17 | + |
| 18 | + $storedPost = Post::cacheFor(now()->addHours(1))->dontCache()->first(); |
| 19 | + $cache = Cache::get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); |
| 20 | + $this->assertNull($cache); |
| 21 | + } |
| 22 | + |
| 23 | + public function test_cache_prefix() |
| 24 | + { |
| 25 | + $post = factory(Post::class)->create(); |
| 26 | + $storedPost = Post::cacheFor(now()->addHours(1))->cachePrefix('test')->first(); |
| 27 | + $cache = Cache::get('test:sqlitegetselect * from "posts" limit 1a:0:{}'); |
| 28 | + |
| 29 | + $this->assertNotNull($cache); |
| 30 | + } |
| 31 | + |
| 32 | + public function test_cache_tags() |
| 33 | + { |
| 34 | + $post = factory(Post::class)->create(); |
| 35 | + $storedPost = Post::cacheFor(now()->addHours(1))->cacheTags(['test'])->first(); |
| 36 | + |
| 37 | + $cache = Cache::get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); |
| 38 | + $this->assertNull($cache); |
| 39 | + |
| 40 | + $cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); |
| 41 | + $this->assertNotNull($cache); |
| 42 | + } |
| 43 | + |
| 44 | + public function test_cache_flush_with_the_right_tag() |
| 45 | + { |
| 46 | + $post = factory(Post::class)->create(); |
| 47 | + $storedPost = Post::cacheFor(now()->addHours(1))->cacheTags(['test'])->first(); |
| 48 | + |
| 49 | + $cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); |
| 50 | + $this->assertNotNull($cache); |
| 51 | + |
| 52 | + Post::flushQueryCache(['test']); |
| 53 | + |
| 54 | + $cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); |
| 55 | + $this->assertNull($cache); |
| 56 | + } |
| 57 | + |
| 58 | + public function test_cache_flush_without_the_right_tag() |
| 59 | + { |
| 60 | + $post = factory(Post::class)->create(); |
| 61 | + $storedPost = Post::cacheFor(now()->addHours(1))->cacheTags(['test'])->first(); |
| 62 | + |
| 63 | + $cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); |
| 64 | + $this->assertNotNull($cache); |
| 65 | + |
| 66 | + Post::flushQueryCache(['test2']); |
| 67 | + |
| 68 | + $cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); |
| 69 | + $this->assertNotNull($cache); |
| 70 | + } |
| 71 | +} |
0 commit comments