Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Scopes/CacheRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 19 additions & 1 deletion tests/CacheAwareConnectionProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -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';
Expand Down
Loading