29
0
mirror of https://github.com/joomla/joomla-cms.git synced 2024-06-25 23:02:55 +00:00

Allow custom connection credentials for memcache and redis tests

This commit is contained in:
Robert Deutz 2017-07-05 12:06:26 +02:00
parent c100dfbefe
commit 5a1c027e51
No known key found for this signature in database
GPG Key ID: D81EF05FE9B6B8FF
4 changed files with 120 additions and 1 deletions

View File

@ -9,6 +9,9 @@
<const name="JTEST_DATABASE_SQLSRV_DSN" value="host=localhost;dbname=joomla_ut;user=utuser;pass=ut1234" />
<const name="JTEST_HTTP_STUB" value="http://localhost/joomla-cms/tests/unit/stubs/jhttp_stub.php" />
<const name="JOOMLA_TEST_LOGGING" value="yes" />
<const name="JTEST_CACHE_REDIS_DSN" value="host=localhost;port=6379;db=;auth=" />
<const name="JTEST_CACHE_MEMCACHE_DSN" value="host=localhost;port=11211" />
<const name="JTEST_CACHE_MEMCACHED_DSN" value="host=localhost;port=11211" />
</php>
-->

View File

@ -27,6 +27,39 @@ class JCacheStorageMemcacheTest extends TestCaseCache
parent::setUp();
// Parse the DSN details for the test server
$dsn = defined('JTEST_CACHE_MEMCACHE_DSN') ? JTEST_CACHE_MEMCACHE_DSN : getenv('JTEST_CACHE_MEMCACHE_DSN');
if ($dsn)
{
// First let's trim the redis: part off the front of the DSN if it exists.
if (strpos($dsn, 'memcache:') === 0)
{
$dsn = substr($dsn, 9);
}
// Call getConfig once to have the registry object prepared
JFactory::getConfig();
// Split the DSN into its parts over semicolons.
$parts = explode(';', $dsn);
// Parse each part and populate the options array.
foreach ($parts as $part)
{
list ($k, $v) = explode('=', $part, 2);
switch ($k)
{
case 'host':
JFactory::$config->set("memcache_server_host", $v);
break;
case 'port':
JFactory::$config->set("memcache_server_port", $v);
break;
}
}
}
try
{
$this->handler = new JCacheStorageMemcache;

View File

@ -27,6 +27,40 @@ class JCacheStorageMemcachedTest extends TestCaseCache
parent::setUp();
// Parse the DSN details for the test server
$dsn = defined('JTEST_CACHE_MEMCACHED_DSN') ? JTEST_CACHE_MEMCACHED_DSN : getenv('JTEST_CACHE_MEMCACHED_DSN');
if ($dsn)
{
// First let's trim the redis: part off the front of the DSN if it exists.
if (strpos($dsn, 'memcached:') === 0)
{
$dsn = substr($dsn, 10);
}
// Call getConfig once to have the registry object prepared
JFactory::getConfig();
// Split the DSN into its parts over semicolons.
$parts = explode(';', $dsn);
// Parse each part and populate the options array.
foreach ($parts as $part)
{
list ($k, $v) = explode('=', $part, 2);
switch ($k)
{
case 'host':
JFactory::$config->set("memcached_server_host", $v);
break;
case 'port':
JFactory::$config->set("memcached_server_port", $v);
break;
}
}
}
try
{
$this->handler = new JCacheStorageMemcached;

View File

@ -30,7 +30,7 @@ class JCacheStorageRedisTest extends TestCaseCache
// Mock the returns on JApplicationCms::get() to use the default values
JFactory::$application->expects($this->any())
->method('get')
->willReturnArgument(1);
->will($this->returnCallback(array($this, 'applicationGetterCallback')));
$this->handler = new JCacheStorageRedis;
@ -43,4 +43,53 @@ class JCacheStorageRedisTest extends TestCaseCache
// Override the lifetime because the JCacheStorage API multiplies it by 60 (converts minutes to seconds)
$this->handler->_lifetime = 2;
}
/**
* Callback for application getter that returns redis credentials
*
* @return mixed
*/
public function applicationGetterCallback()
{
// Parse the DSN details for the test server
$dsn = defined('JTEST_CACHE_REDIS_DSN') ? JTEST_CACHE_REDIS_DSN : getenv('JTEST_CACHE_REDIS_DSN');
$args = func_get_args();
if ($dsn)
{
// First let's trim the redis: part off the front of the DSN if it exists.
if (strpos($dsn, 'redis:') === 0)
{
$dsn = substr($dsn, 6);
}
// Split the DSN into its parts over semicolons.
$parts = explode(';', $dsn);
$connection = array();
// Parse each part and populate the options array.
foreach ($parts as $part)
{
list ($k, $v) = explode('=', $part, 2);
$connection[$k] = $v;
}
switch ($args[0])
{
case "redis_server_host":
return $connection["host"];
break;
case "redis_server_port":
return $connection["port"];
break;
case "redis_server_auth":
return $connection["auth"];
break;
case "redis_server_db":
return $connection["db"];
break;
}
}
return $args[1];
}
}