Skip to content

Commit

Permalink
Fix key cache string. (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Oct 12, 2020
1 parent fece95f commit b37573a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tests/ConnectionTest.php
Expand Up @@ -223,7 +223,9 @@ public function testServerStatusCacheWorks(): void

$db->setShuffleMasters(false);

$cacheKey = ['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', $db->getDsn()];
$cacheKey = $this->buildKeyCache(
['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', $db->getDsn()]
);

$this->assertFalse($this->cache->has($cacheKey));

Expand All @@ -238,7 +240,9 @@ public function testServerStatusCacheWorks(): void

$db = $this->getConnection();

$cacheKey = ['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', 'host:invalid'];
$cacheKey = $this->buildKeyCache(
['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', 'host:invalid']
);

$db->setMasters(
'1',
Expand Down Expand Up @@ -295,7 +299,9 @@ public function testServerStatusCacheCanBeDisabled(): void

$db->setShuffleMasters(false);

$cacheKey = ['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', $db->getDsn()];
$cacheKey = $this->buildKeyCache(
['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', $db->getDsn()]
);

$this->assertFalse($this->cache->has($cacheKey));

Expand All @@ -305,7 +311,9 @@ public function testServerStatusCacheCanBeDisabled(): void

$db->close();

$cacheKey = ['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', 'host:invalid'];
$cacheKey = $this->buildKeyCache(
['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', 'host:invalid']
);

$db->setMasters(
'1',
Expand Down
7 changes: 7 additions & 0 deletions tests/TestCase.php
Expand Up @@ -111,6 +111,13 @@ protected function configContainer(): void
DatabaseFactory::initialize($this->container, []);
}

protected function buildKeyCache(array $key): string
{
$jsonKey = json_encode($key);

return md5($jsonKey);
}

/**
* Invokes a inaccessible method.
*
Expand Down

0 comments on commit b37573a

Please sign in to comment.