From ed321f8ce7ce136ce1c844cb26df9e348b794ffc Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Tue, 9 Jul 2024 13:57:33 +1200 Subject: [PATCH] MNT Test with all cache factories in CI --- .github/workflows/ci.yml | 6 ++++++ phpunit.xml.dist | 4 ++++ src/Core/Cache/DefaultCacheFactory.php | 7 ++++--- tests/php/Core/Cache/DefaultCacheFactoryTest.php | 6 +++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2f9a0ba4..035b6ef0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,3 +12,9 @@ jobs: with: # Turn phpcoverage off because it causes a segfault phpcoverage_force_off: true + phpunit_skip_suites: framework-cache-only + # Ensure we test all in-memory cache factories provided in core + extra_jobs: | + - phpunit: true + phpunit_suite: framework-cache-only + install_in_memory_cache_exts: true diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f435f9a45..78fdb6bd3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -21,6 +21,10 @@ Requires PHPUnit ^9 vendor/silverstripe/cms/tests + + + tests/php/Core/Cache + diff --git a/src/Core/Cache/DefaultCacheFactory.php b/src/Core/Cache/DefaultCacheFactory.php index 7d8d0a75f..5dc712ef1 100644 --- a/src/Core/Cache/DefaultCacheFactory.php +++ b/src/Core/Cache/DefaultCacheFactory.php @@ -46,17 +46,18 @@ class DefaultCacheFactory extends AbstractCacheFactory // In-memory caches are typically more resource constrained (number of items and storage space). // Give cache consumers an opt-out if they are expecting to create large caches with long lifetimes. $useInMemoryCache = isset($args['useInMemoryCache']) ? $args['useInMemoryCache'] : true; - $inMemoryCacheFactory = Environment::getEnv('SS_MEMORY_CACHEFACTORY'); + $inMemoryCacheFactory = Environment::getEnv('SS_IN_MEMORY_CACHE_FACTORY'); $filesystemCache = $this->instantiateFilesystemCache($namespace, $defaultLifetime, $directory, $useInjector); if (!$useInMemoryCache || !$inMemoryCacheFactory) { return $this->prepareCacheForUse($filesystemCache, $useInjector); } - // Check if SS_MEMORY_CACHEFACTORY is a factory + // Check if SS_IN_MEMORY_CACHE_FACTORY is a factory if (!is_a($inMemoryCacheFactory, InMemoryCacheFactory::class, true)) { throw new LogicException( - 'SS_MEMORY_CACHEFACTORY is not a valid InMemoryCacheFactory class name' + 'The value in your SS_IN_MEMORY_CACHE_FACTORY environment variable' + . ' is not a valid InMemoryCacheFactory class name' ); } diff --git a/tests/php/Core/Cache/DefaultCacheFactoryTest.php b/tests/php/Core/Cache/DefaultCacheFactoryTest.php index 50548e048..9041f4a3e 100644 --- a/tests/php/Core/Cache/DefaultCacheFactoryTest.php +++ b/tests/php/Core/Cache/DefaultCacheFactoryTest.php @@ -78,10 +78,10 @@ class DefaultCacheFactoryTest extends SapphireTest */ public function testCreate(array $args, ?string $inMemoryCacheFactory): void { - $oldFactoryValue = Environment::getEnv('SS_MEMORY_CACHEFACTORY'); + $oldFactoryValue = Environment::getEnv('SS_IN_MEMORY_CACHE_FACTORY'); $oldMemcachedDSNValue = Environment::getEnv('SS_MEMCACHED_DSN'); $oldRedisDSNValue = Environment::getEnv('SS_REDIS_DSN'); - Environment::setEnv('SS_MEMORY_CACHEFACTORY', $inMemoryCacheFactory); + Environment::setEnv('SS_IN_MEMORY_CACHE_FACTORY', $inMemoryCacheFactory); // These are obviously not real connections, but it seems a real connection is not required // to just instantiate the cache adapter, which allows us to validate the correct adapter // is instantiated. @@ -148,7 +148,7 @@ class DefaultCacheFactoryTest extends SapphireTest $reflectionLoggerProperty->setAccessible(true); $this->assertTrue($logger === $reflectionLoggerProperty->getValue($filesystemCache)); } finally { - Environment::setEnv('SS_MEMORY_CACHEFACTORY', $oldFactoryValue); + Environment::setEnv('SS_IN_MEMORY_CACHE_FACTORY', $oldFactoryValue); Environment::setEnv('SS_MEMCACHED_DSN', $oldMemcachedDSNValue); Environment::setEnv('SS_REDIS_DSN', $oldRedisDSNValue); }