|
6 | 6 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
|
7 | 7 | use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
|
8 | 8 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\AuthorWithCooldown;
|
| 9 | +use ReflectionClass; |
9 | 10 |
|
10 | 11 | class CachedModelTest extends IntegrationTestCase
|
11 | 12 | {
|
@@ -145,6 +146,33 @@ public function testWhereHasWithClosureIsBeingCached()
|
145 | 146 | $this->assertNotEmpty($books1->diffKeys($books2));
|
146 | 147 | }
|
147 | 148 |
|
| 149 | + public function testCooldownIsNotQueriedForNormalCachedModels() |
| 150 | + { |
| 151 | + $class = new ReflectionClass(Author::class); |
| 152 | + $method = $class->getMethod('getModelCacheCooldown'); |
| 153 | + $method->setAccessible(true); |
| 154 | + $author = (new Author) |
| 155 | + ->first(); |
| 156 | + |
| 157 | + $this->assertEquals([null, null, null], $method->invokeArgs($author, [$author])); |
| 158 | + } |
| 159 | + |
| 160 | + public function testCooldownIsQueriedForCooldownModels() |
| 161 | + { |
| 162 | + $class = new ReflectionClass(AuthorWithCooldown::class); |
| 163 | + $method = $class->getMethod('getModelCacheCooldown'); |
| 164 | + $method->setAccessible(true); |
| 165 | + $author = (new AuthorWithCooldown) |
| 166 | + ->withCacheCooldownSeconds(1) |
| 167 | + ->first(); |
| 168 | + |
| 169 | + [$usesCacheCooldown, $expiresAt, $savedAt] = $method->invokeArgs($author, [$author]); |
| 170 | + |
| 171 | + $this->assertEquals($usesCacheCooldown, 1); |
| 172 | + $this->assertEquals("Carbon\Carbon", get_class($expiresAt)); |
| 173 | + $this->assertNull($savedAt); |
| 174 | + } |
| 175 | + |
148 | 176 | public function testModelCacheDoesntInvalidateDuringCooldownPeriod()
|
149 | 177 | {
|
150 | 178 | $authors = (new AuthorWithCooldown)
|
|
0 commit comments