aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2019-11-25 21:27:43 +0100
committerMarc Alexander <admin@m-a-styles.de>2019-11-25 21:27:43 +0100
commitc7d47e34e82128399e1b20b9f80a85f46c4cfd75 (patch)
treeb37156468a2218fc2c832b8ca4739d0f3a66f84c /tests
parentfd7524858c9c178603cc3bb7440bcbad58c9096a (diff)
downloadforums-c7d47e34e82128399e1b20b9f80a85f46c4cfd75.tar
forums-c7d47e34e82128399e1b20b9f80a85f46c4cfd75.tar.gz
forums-c7d47e34e82128399e1b20b9f80a85f46c4cfd75.tar.bz2
forums-c7d47e34e82128399e1b20b9f80a85f46c4cfd75.tar.xz
forums-c7d47e34e82128399e1b20b9f80a85f46c4cfd75.zip
[ticket/16223] Ensure memcached tests are only run when available
PHPBB3-16223
Diffstat (limited to 'tests')
-rw-r--r--tests/RUNNING_TESTS.md15
-rw-r--r--tests/cache/memcached_test.php21
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php20
3 files changed, 55 insertions, 1 deletions
diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md
index 516541151c..54db823b4a 100644
--- a/tests/RUNNING_TESTS.md
+++ b/tests/RUNNING_TESTS.md
@@ -109,6 +109,21 @@ Or via environment variables as follows:
$ 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
=======
diff --git a/tests/cache/memcached_test.php b/tests/cache/memcached_test.php
index 2c63ed6bcb..a29f0040cf 100644
--- a/tests/cache/memcached_test.php
+++ b/tests/cache/memcached_test.php
@@ -29,6 +29,25 @@ class phpbb_cache_memcached_driver_test extends \phpbb_cache_common_test_case
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();
}
@@ -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->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();
}
}
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 807a64d810..9a2ea275d0 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -173,6 +173,16 @@ class phpbb_test_case_helpers
{
$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']))
@@ -205,6 +215,16 @@ class phpbb_test_case_helpers
$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;
}