From fd7524858c9c178603cc3bb7440bcbad58c9096a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 25 Nov 2019 20:10:12 +0100 Subject: [ticket/16223] Add test for memcached driver PHPBB3-16223 --- tests/cache/memcached_test.php | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/cache/memcached_test.php (limited to 'tests') diff --git a/tests/cache/memcached_test.php b/tests/cache/memcached_test.php new file mode 100644 index 0000000000..2c63ed6bcb --- /dev/null +++ b/tests/cache/memcached_test.php @@ -0,0 +1,46 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +require_once dirname(__FILE__) . '/common_test_case.php'; + +class phpbb_cache_memcached_driver_test extends \phpbb_cache_common_test_case +{ + protected static $config; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + static public function setUpBeforeClass() + { + if (!extension_loaded('memcached')) + { + self::markTestSkipped('memcached extension is not loaded'); + } + + parent::setUpBeforeClass(); + } + + protected function setUp(): void + { + global $phpbb_root_path, $phpbb_container; + + parent::setUp(); + + $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->purge(); + } +} -- cgit v1.2.1 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 From 380b7d0a98f81d241208034bb76b1468485ea996 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 25 Nov 2019 22:16:41 +0100 Subject: [ticket/16223] Use constructor arguments instead of func_get_args() PHPBB3-16223 --- tests/cache/memcached_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/cache/memcached_test.php b/tests/cache/memcached_test.php index a29f0040cf..650b72ea18 100644 --- a/tests/cache/memcached_test.php +++ b/tests/cache/memcached_test.php @@ -59,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(self::$config['host'], self::$config['port']); + $this->driver = new \phpbb\cache\driver\memcached(self::$config['host'] . '/' . self::$config['port']); $this->driver->purge(); } } -- cgit v1.2.1