From 3b9677419b95c1dbfc1a6fc70e453cc2ef05d057 Mon Sep 17 00:00:00 2001 From: Jakob Perry <19007-japerry@users.noreply.drupalcode.org> Date: Thu, 11 Jul 2024 17:23:36 +0000 Subject: [PATCH] Issue #2996055 by japerry, ericgsmith, Wim Leers: Test coverage --- .gitlab-ci.yml | 9 ++++++- src/Driver/DriverBase.php | 3 ++- src/Driver/MemcachedDriver.php | 2 +- .../Functional/MemcacheLockFunctionalTest.php | 24 ++++++++++++++++++- tests/src/Kernel/MemcacheBackendTest.php | 21 ++++++++++++++++ 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7ba55fc..afc7f38 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,6 +8,13 @@ include: variables: _PHPUNIT_CONCURRENT: '1' + SKIP_CSPELL: 1 + OPT_IN_TEST_PREVIOUS_MAJOR: 1 + OPT_IN_TEST_PREVIOUS_MINOR: 1 + OPT_IN_TEST_NEXT_MINOR: 1 + OPT_IN_TEST_NEXT_MAJOR: 1 + OPT_IN_TEST_MAX_PHP: 1 + # # Start custom overrides. # @@ -36,4 +43,4 @@ phpunit: # Show more log output _PHPUNIT_EXTRA: --verbose # Convenient, and we have no secrets. - _SHOW_ENVIRONMENT_VARIABLES: '1' + _SHOW_ENVIRONMENT_VARIABLES: 1 diff --git a/src/Driver/DriverBase.php b/src/Driver/DriverBase.php index 0dd0822..cc3daa7 100644 --- a/src/Driver/DriverBase.php +++ b/src/Driver/DriverBase.php @@ -243,8 +243,9 @@ abstract class DriverBase implements DrupalMemcacheInterface { */ public function getServers() { $memcache_servers = \Drupal::configFactory()->getEditable('memcache.settings')->get('memcache_servers'); + $host = getenv('MEMCACHED_HOST') ?: '127.0.0.1:11211'; if (!isset($memcache_servers)) { - $memcache_servers = ['127.0.0.1:11211' => 'default']; + $memcache_servers = [$host => 'default']; } return $memcache_servers; diff --git a/src/Driver/MemcachedDriver.php b/src/Driver/MemcachedDriver.php index 2460fe9..aa9ca11 100755 --- a/src/Driver/MemcachedDriver.php +++ b/src/Driver/MemcachedDriver.php @@ -17,7 +17,7 @@ class MemcachedDriver extends DriverBase { $result = $this->memcache->set($full_key, $value, $exp); // Something bad happened. Let's log the problem. - if (!$result && $this->settings->get('debug')) { + if (!$result || $this->settings->get('debug')) { $result_code = $this->memcache->getResultCode(); $result_message = $this->memcache->getResultMessage(); diff --git a/tests/src/Functional/MemcacheLockFunctionalTest.php b/tests/src/Functional/MemcacheLockFunctionalTest.php index ed26f8e..da3f7c4 100644 --- a/tests/src/Functional/MemcacheLockFunctionalTest.php +++ b/tests/src/Functional/MemcacheLockFunctionalTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\memcache\Tests; +namespace Drupal\Tests\memcache\Functional; use Drupal\Tests\system\Functional\Lock\LockFunctionalTest; @@ -18,4 +18,26 @@ class MemcacheLockFunctionalTest extends LockFunctionalTest { */ protected static $modules = ['system_test', 'memcache', 'memcache_test']; + public function setUp(): void { + parent::setUp(); + $host = getenv('MEMCACHED_HOST') ?: '127.0.0.1:11211'; + $settings['settings']['memcache'] = (object) [ + 'value' => [ + 'servers' => [$host => 'default'], + 'bin' => ['default' => 'default'], + ], + 'required' => TRUE, + ]; + + $settings['settings']['hash_salt'] = (object) [ + 'value' => $this->randomMachineName(), + 'required' => TRUE, + ]; + + $this->writeSettings($settings); + } + + public function testLockAcquire(): void { + parent::testLockAcquire(); + } } diff --git a/tests/src/Kernel/MemcacheBackendTest.php b/tests/src/Kernel/MemcacheBackendTest.php index b8ad849..8e6f4af 100644 --- a/tests/src/Kernel/MemcacheBackendTest.php +++ b/tests/src/Kernel/MemcacheBackendTest.php @@ -30,6 +30,15 @@ class MemcacheBackendTest extends GenericCacheBackendUnitTestBase implements Ser $service_definition->setArgument(2, 0); } + public function setUp(): void { + parent::setUp(); + $host = getenv('MEMCACHED_HOST') ?: '127.0.0.1:11211'; + $this->setSetting('memcache', [ + 'servers' => [$host => 'default'], + 'bin' => ['default' => 'default'], + 'debug' => TRUE, + ]); + } /** * Creates a new instance of DatabaseBackend. * @@ -46,4 +55,16 @@ class MemcacheBackendTest extends GenericCacheBackendUnitTestBase implements Ser return $factory->get($bin); } + /** + * Gets a backend to test; this will get a shared instance set in the object. + * + * @return \Drupal\Core\Cache\CacheBackendInterface + * Cache backend to test. + */ + protected function getCacheBackend($bin = NULL) { + $backend = parent::getCacheBackend($bin); + usleep(10000); + return $backend; + } + } -- GitLab