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
6 changes: 5 additions & 1 deletion src/Support/GatewayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace YlsIdeas\FeatureFlags\Support;

use Illuminate\Contracts\Cache\Repository;
use Psr\SimpleCache\InvalidArgumentException;
use YlsIdeas\FeatureFlags\Contracts\Cacheable;

/**
Expand All @@ -21,9 +22,12 @@ public function hits(string $feature): bool
return $this->repository->has($this->generateKey($feature));
}

/**
* @throws InvalidArgumentException
*/
public function result(string $feature): bool
{
return $this->repository->get($this->generateKey($feature));
return (bool) $this->repository->get($this->generateKey($feature));
}

public function store(string $feature, ?bool $result): void
Expand Down
20 changes: 20 additions & 0 deletions tests/Support/GatewayCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ public function test_it_hits_the_cache_correct(): void
$this->assertTrue($cache->hits('my-feature'));
}

public function test_it_retrieves_the_cache_correctly(): void
{
$repository = Mockery::mock(Repository::class);
$cachable = Mockery::mock(Cacheable::class);

$cachable->shouldReceive('generateKey')
->with('my-feature')
->once()
->andReturn('key');

$repository->shouldReceive('get')
->with('test:key')
->once()
->andReturn(null);

$cache = new GatewayCache($repository, 'test', $cachable);

$this->assertFalse($cache->result('my-feature'));
}

public function test_it_stores_with_a_ttl_correctly(): void
{
$repository = Mockery::mock(Repository::class);
Expand Down
Loading