diff --git a/src/Scopes/CacheRelations.php b/src/Scopes/CacheRelations.php index 2fc2f36..f40b956 100644 --- a/src/Scopes/CacheRelations.php +++ b/src/Scopes/CacheRelations.php @@ -15,7 +15,7 @@ class CacheRelations implements Scope * Creates a new scope instance. */ public function __construct( - protected DateTimeInterface|DateInterval|int|null $ttl, + protected DateTimeInterface|DateInterval|int|array|null $ttl, protected string $key, protected ?string $store, protected int $wait, diff --git a/tests/CacheAwareConnectionProxyTest.php b/tests/CacheAwareConnectionProxyTest.php index ce7ffac..3d7708b 100644 --- a/tests/CacheAwareConnectionProxyTest.php +++ b/tests/CacheAwareConnectionProxyTest.php @@ -445,7 +445,7 @@ public function test_regenerates_cache_using_ttl_with_negative_number(): void static::assertSame('test', $result->name); } - public function test_uses_flexible_caching_when_using_ttl_as_array_of_values(): void + public function test_uses_db_flexible_caching_when_using_ttl_as_array_of_values(): void { if (! method_exists(CacheRepository::class, 'flexible')) { $this->markTestSkipped('Cannot test flexible caching if repository does not implements it.'); @@ -463,6 +463,24 @@ public function test_uses_flexible_caching_when_using_ttl_as_array_of_values(): $this->app->make('db')->table('users')->where('id', 1)->cache([5, 300])->first(); } + public function test_uses_eloquent_flexible_caching_when_using_ttl_as_array_of_values(): void + { + if (! method_exists(CacheRepository::class, 'flexible')) { + $this->markTestSkipped('Cannot test flexible caching if repository does not implements it.'); + } + + $hash = 'cache-query|fj8Xyz4K1Zh0tdAamPbG1A'; + + $repository = $this->mock(CacheRepository::class); + $repository->expects('put')->never(); + $repository->expects('flexible')->with($hash, Mockery::type('array'), [5, 300])->once(); + $repository->expects('getMultiple')->with([$hash, ''])->times(1)->andReturn(['' => null, $hash => null]); + + $this->mock('cache')->shouldReceive('store')->with(null)->andReturn($repository); + + User::where('id', 1)->cache([5, 300])->first(); + } + public function test_doesnt_uses_flexible_caching_if_repository_is_not_flexible(): void { $hash = 'cache-query|fj8Xyz4K1Zh0tdAamPbG1A';