From c7d47e34e82128399e1b20b9f80a85f46c4cfd75 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 25 Nov 2019 21:27:43 +0100 Subject: [ticket/16223] Ensure memcached tests are only run when available PHPBB3-16223 --- tests/RUNNING_TESTS.md | 15 +++++++++++++++ tests/cache/memcached_test.php | 21 ++++++++++++++++++++- tests/test_framework/phpbb_test_case_helpers.php | 20 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) (limited to 'tests') 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: + + $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; } -- cgit v1.2.1