mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/16223] Ensure memcached tests are only run when available
PHPBB3-16223
This commit is contained in:
parent
fd7524858c
commit
c7d47e34e8
4 changed files with 77 additions and 4 deletions
25
phpBB/phpbb/cache/driver/memcached.php
vendored
25
phpBB/phpbb/cache/driver/memcached.php
vendored
|
@ -56,6 +56,15 @@ class memcached extends \phpbb\cache\driver\memory
|
||||||
// Call the parent constructor
|
// Call the parent constructor
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
$memcached_servers = PHPBB_ACM_MEMCACHED;
|
||||||
|
|
||||||
|
// Allow overwriting PHPBB_ACM_MEMCACHED via constructor arguments
|
||||||
|
$args = func_get_args();
|
||||||
|
if (count($args) >= 2)
|
||||||
|
{
|
||||||
|
$memcached_servers = $args[0] . '/' . $args[1];
|
||||||
|
}
|
||||||
|
|
||||||
$this->memcached = new \Memcached();
|
$this->memcached = new \Memcached();
|
||||||
$this->memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
|
$this->memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
|
||||||
// Memcached defaults to using compression, disable if we don't want
|
// Memcached defaults to using compression, disable if we don't want
|
||||||
|
@ -65,10 +74,20 @@ class memcached extends \phpbb\cache\driver\memory
|
||||||
$this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);
|
$this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (explode(',', PHPBB_ACM_MEMCACHED) as $u)
|
$server_list = [];
|
||||||
|
foreach (explode(',', $memcached_servers) as $u)
|
||||||
{
|
{
|
||||||
preg_match('#(.*)/(\d+)#', $u, $parts);
|
if (preg_match('#(.*)/(\d+)#', $u, $parts))
|
||||||
$this->memcached->addServer(trim($parts[1]), (int) trim($parts[2]));
|
{
|
||||||
|
$server_list[] = [trim($parts[1]), (int) trim($parts[2])];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->memcached->addServers($server_list);
|
||||||
|
|
||||||
|
if (empty($server_list) || empty($this->memcached->getStats()))
|
||||||
|
{
|
||||||
|
trigger_error('Could not connect to memcached server(s).');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,21 @@ Or via environment variables as follows:
|
||||||
|
|
||||||
$ PHPBB_TEST_REDIS_HOST=localhost PHPBB_TEST_REDIS_PORT=6379 phpunit
|
$ PHPBB_TEST_REDIS_HOST=localhost PHPBB_TEST_REDIS_PORT=6379 phpunit
|
||||||
|
|
||||||
|
Memcached
|
||||||
|
---------
|
||||||
|
|
||||||
|
In order to run tests for the memcached cache driver, at least one of memcached
|
||||||
|
host or port must be specified in the test configuration. This can be done via
|
||||||
|
test_config.php as follows:
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$phpbb_memcached_host = 'localhost';
|
||||||
|
$phpbb_memcached_port = '11211';
|
||||||
|
|
||||||
|
Or via environment variables as follows:
|
||||||
|
|
||||||
|
$ PHPBB_TEST_MEMCACHED_HOST=localhost PHPBB_TEST_MEMCACHED_PORT=11211 phpunit
|
||||||
|
|
||||||
Running
|
Running
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|
21
tests/cache/memcached_test.php
vendored
21
tests/cache/memcached_test.php
vendored
|
@ -29,6 +29,25 @@ class phpbb_cache_memcached_driver_test extends \phpbb_cache_common_test_case
|
||||||
self::markTestSkipped('memcached extension is not loaded');
|
self::markTestSkipped('memcached extension is not loaded');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$config = phpbb_test_case_helpers::get_test_config();
|
||||||
|
if (isset($config['memcached_host']) || isset($config['memcached_port']))
|
||||||
|
{
|
||||||
|
$host = isset($config['memcached_host']) ? $config['memcached_host'] : 'localhost';
|
||||||
|
$port = isset($config['memcached_port']) ? $config['memcached_port'] : 11211;
|
||||||
|
self::$config = array('host' => $host, 'port' => $port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self::markTestSkipped('Test memcached host/port is not specified');
|
||||||
|
}
|
||||||
|
|
||||||
|
$memcached = new \Memcached();
|
||||||
|
$memcached->addServer(self::$config['host'], self::$config['port']);
|
||||||
|
if (empty($memcached->getStats()))
|
||||||
|
{
|
||||||
|
self::markTestSkipped('Test memcached server is not available');
|
||||||
|
}
|
||||||
|
|
||||||
parent::setUpBeforeClass();
|
parent::setUpBeforeClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +59,7 @@ class phpbb_cache_memcached_driver_test extends \phpbb_cache_common_test_case
|
||||||
|
|
||||||
$phpbb_container = new phpbb_mock_container_builder();
|
$phpbb_container = new phpbb_mock_container_builder();
|
||||||
$phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/');
|
$phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/');
|
||||||
$this->driver = new \phpbb\cache\driver\memcached();
|
$this->driver = new \phpbb\cache\driver\memcached(self::$config['host'], self::$config['port']);
|
||||||
$this->driver->purge();
|
$this->driver->purge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,6 +173,16 @@ class phpbb_test_case_helpers
|
||||||
{
|
{
|
||||||
$config['fulltext_sphinx_id'] = $fulltext_sphinx_id;
|
$config['fulltext_sphinx_id'] = $fulltext_sphinx_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($phpbb_memcached_host))
|
||||||
|
{
|
||||||
|
$config['memcached_host'] = $phpbb_memcached_host;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($phpbb_memcached_port))
|
||||||
|
{
|
||||||
|
$config['memcached_port'] = $phpbb_memcached_port;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
||||||
|
@ -205,6 +215,16 @@ class phpbb_test_case_helpers
|
||||||
$config['redis_port'] = $_SERVER['PHPBB_TEST_REDIS_PORT'];
|
$config['redis_port'] = $_SERVER['PHPBB_TEST_REDIS_PORT'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_SERVER['PHPBB_TEST_MEMCACHED_HOST']))
|
||||||
|
{
|
||||||
|
$config['memcached_host'] = $_SERVER['PHPBB_TEST_MEMCACHED_HOST'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_SERVER['PHPBB_TEST_MEMCACHED_PORT']))
|
||||||
|
{
|
||||||
|
$config['memcached_port'] = $_SERVER['PHPBB_TEST_MEMCACHED_PORT'];
|
||||||
|
}
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue