Skip to content

Commit

Permalink
MNT Test with all cache factories in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jul 11, 2024
1 parent 2321737 commit ed321f8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Requires PHPUnit ^9
<testsuite name="cms">
<directory>vendor/silverstripe/cms/tests</directory>
</testsuite>
<!-- Cache suite is separate so it only runs what it needs to run. Intentionally also included in core above. -->
<testsuite name="framework-cache-only">
<directory>tests/php/Core/Cache</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
Expand Down
7 changes: 4 additions & 3 deletions src/Core/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ public function create(string $service, array $args = []): CacheInterface
// 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'
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/php/Core/Cache/DefaultCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ class_exists(Relay::class) ||
*/
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.
Expand Down Expand Up @@ -148,7 +148,7 @@ public function testCreate(array $args, ?string $inMemoryCacheFactory): void
$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);
}
Expand Down

0 comments on commit ed321f8

Please sign in to comment.