Skip to content

Commit ad40e49

Browse files
committed
Add test to check if cooldown logic is skipped when disabled, and run when enabled
1 parent 4627bda commit ad40e49

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/Integration/CachedModelTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
77
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
88
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\AuthorWithCooldown;
9+
use ReflectionClass;
910

1011
class CachedModelTest extends IntegrationTestCase
1112
{
@@ -145,6 +146,33 @@ public function testWhereHasWithClosureIsBeingCached()
145146
$this->assertNotEmpty($books1->diffKeys($books2));
146147
}
147148

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+
148176
public function testModelCacheDoesntInvalidateDuringCooldownPeriod()
149177
{
150178
$authors = (new AuthorWithCooldown)

0 commit comments

Comments
 (0)