Skip to content

Commit

Permalink
refactor: change cache key names
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Oct 20, 2022
1 parent 2cb824a commit b826392
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Service/Dce/SystemDce.php
Expand Up @@ -43,12 +43,12 @@ final class SystemDce implements Dce
/**
* Key to use when caching the GID value in a PSR-16 cache instance
*/
private const GID_CACHE_KEY = '__ramsey_identifier_27a5';
private const GID_CACHE_KEY = '__ramsey_id_gid';

/**
* Key to use when caching the UID value in a PSR-16 cache instance
*/
private const UID_CACHE_KEY = '__ramsey_identifier_690f';
private const UID_CACHE_KEY = '__ramsey_id_uid';

/**
* @var int<0, max> | null
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Nic/SystemNic.php
Expand Up @@ -45,7 +45,7 @@ final class SystemNic implements Nic
/**
* Key to use when caching the address value in a PSR-16 cache instance
*/
private const CACHE_KEY = '__ramsey_identifier_64f4';
private const CACHE_KEY = '__ramsey_id_system_addr';

/**
* The system address, stored statically for better performance
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/Service/Dce/SystemDceTest.php
Expand Up @@ -51,7 +51,7 @@ public function testGroupId(): void
public function testGroupIdFromCache(): void
{
$cache = $this->mockery(CacheInterface::class);
$cache->expects('get')->with('__ramsey_identifier_27a5')->andReturn(5001);
$cache->expects('get')->with('__ramsey_id_gid')->andReturn(5001);

$dce = new SystemDce(cache: $cache);

Expand All @@ -68,8 +68,8 @@ public function testGroupIdFromCache(): void
public function testGroupIdFromCacheSetsIdentifierOnCache(): void
{
$cache = $this->mockery(CacheInterface::class);
$cache->expects('get')->with('__ramsey_identifier_27a5')->andReturnNull();
$cache->expects('set')->with('__ramsey_identifier_27a5', new IsInteger())->andReturnTrue();
$cache->expects('get')->with('__ramsey_id_gid')->andReturnNull();
$cache->expects('set')->with('__ramsey_id_gid', new IsInteger())->andReturnTrue();

$dce = new SystemDce(cache: $cache);
$groupId = $dce->groupId();
Expand All @@ -87,7 +87,7 @@ public function testGroupIdFromCacheSetsIdentifierOnCache(): void
public function testGroupIdThrowsExceptionWhenIdentifierNotFound(): void
{
$cache = $this->mockery(CacheInterface::class);
$cache->expects('get')->with('__ramsey_identifier_27a5')->andReturn(-1);
$cache->expects('get')->with('__ramsey_id_gid')->andReturn(-1);

$dce = new SystemDce(cache: $cache);

Expand Down Expand Up @@ -256,7 +256,7 @@ public function testUserId(): void
public function testUserIdFromCache(): void
{
$cache = $this->mockery(CacheInterface::class);
$cache->expects('get')->with('__ramsey_identifier_690f')->andReturn(6001);
$cache->expects('get')->with('__ramsey_id_uid')->andReturn(6001);

$dce = new SystemDce(cache: $cache);

Expand All @@ -273,8 +273,8 @@ public function testUserIdFromCache(): void
public function testUserIdFromCacheSetsIdentifierOnCache(): void
{
$cache = $this->mockery(CacheInterface::class);
$cache->expects('get')->with('__ramsey_identifier_690f')->andReturnNull();
$cache->expects('set')->with('__ramsey_identifier_690f', new IsInteger())->andReturnTrue();
$cache->expects('get')->with('__ramsey_id_uid')->andReturnNull();
$cache->expects('set')->with('__ramsey_id_uid', new IsInteger())->andReturnTrue();

$dce = new SystemDce(cache: $cache);
$userId = $dce->userId();
Expand All @@ -292,7 +292,7 @@ public function testUserIdFromCacheSetsIdentifierOnCache(): void
public function testUserIdThrowsExceptionWhenIdentifierNotFound(): void
{
$cache = $this->mockery(CacheInterface::class);
$cache->expects('get')->with('__ramsey_identifier_690f')->andReturn(-1);
$cache->expects('get')->with('__ramsey_id_uid')->andReturn(-1);

$dce = new SystemDce(cache: $cache);

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/Service/Nic/SystemNicTest.php
Expand Up @@ -42,7 +42,7 @@ public function testAddress(): void
public function testAddressFoundInCache(): void
{
$cache = $this->mockery(CacheInterface::class);
$cache->expects('get')->with('__ramsey_identifier_64f4')->andReturn('aabbccddeeff');
$cache->expects('get')->with('__ramsey_id_system_addr')->andReturn('aabbccddeeff');

$nic = new SystemNic($cache);

Expand All @@ -59,10 +59,10 @@ public function testAddressFoundInCache(): void
public function testAddressStoredInCache(): void
{
$cache = $this->mockery(CacheInterface::class);
$cache->expects('get')->with('__ramsey_identifier_64f4')->andReturnNull();
$cache->expects('get')->with('__ramsey_id_system_addr')->andReturnNull();
$cache
->expects('set')
->with('__ramsey_identifier_64f4', Mockery::pattern('/^[0-9a-f]{12}$/i'))
->with('__ramsey_id_system_addr', Mockery::pattern('/^[0-9a-f]{12}$/i'))
->andReturnTrue();

$nic = new SystemNic($cache);
Expand Down Expand Up @@ -353,10 +353,10 @@ public function testAddressUsesRandomNicIfAddressNotFoundWithCache(): void
$os->expects('run')->with('netstat -ie')->andReturn($netstat);

$cache = $this->mockery(CacheInterface::class);
$cache->expects('get')->with('__ramsey_identifier_64f4')->andReturn('');
$cache->expects('get')->with('__ramsey_id_system_addr')->andReturn('');
$cache
->expects('set')
->with('__ramsey_identifier_64f4', Mockery::pattern('/^[0-9a-f]{12}$/i'))
->with('__ramsey_id_system_addr', Mockery::pattern('/^[0-9a-f]{12}$/i'))
->andReturnTrue();

$nic = new SystemNic($cache, $os);
Expand Down

0 comments on commit b826392

Please sign in to comment.