mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MNT Test with all cache factories in CI
This commit is contained in:
parent
232173753a
commit
ed321f8ce7
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -12,3 +12,9 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
# Turn phpcoverage off because it causes a segfault
|
# Turn phpcoverage off because it causes a segfault
|
||||||
phpcoverage_force_off: true
|
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
|
||||||
|
@ -21,6 +21,10 @@ Requires PHPUnit ^9
|
|||||||
<testsuite name="cms">
|
<testsuite name="cms">
|
||||||
<directory>vendor/silverstripe/cms/tests</directory>
|
<directory>vendor/silverstripe/cms/tests</directory>
|
||||||
</testsuite>
|
</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>
|
</testsuites>
|
||||||
<filter>
|
<filter>
|
||||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||||
|
@ -46,17 +46,18 @@ class DefaultCacheFactory extends AbstractCacheFactory
|
|||||||
// In-memory caches are typically more resource constrained (number of items and storage space).
|
// 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.
|
// Give cache consumers an opt-out if they are expecting to create large caches with long lifetimes.
|
||||||
$useInMemoryCache = isset($args['useInMemoryCache']) ? $args['useInMemoryCache'] : true;
|
$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);
|
$filesystemCache = $this->instantiateFilesystemCache($namespace, $defaultLifetime, $directory, $useInjector);
|
||||||
if (!$useInMemoryCache || !$inMemoryCacheFactory) {
|
if (!$useInMemoryCache || !$inMemoryCacheFactory) {
|
||||||
return $this->prepareCacheForUse($filesystemCache, $useInjector);
|
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)) {
|
if (!is_a($inMemoryCacheFactory, InMemoryCacheFactory::class, true)) {
|
||||||
throw new LogicException(
|
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'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,10 +78,10 @@ class DefaultCacheFactoryTest extends SapphireTest
|
|||||||
*/
|
*/
|
||||||
public function testCreate(array $args, ?string $inMemoryCacheFactory): void
|
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');
|
$oldMemcachedDSNValue = Environment::getEnv('SS_MEMCACHED_DSN');
|
||||||
$oldRedisDSNValue = Environment::getEnv('SS_REDIS_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
|
// 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
|
// to just instantiate the cache adapter, which allows us to validate the correct adapter
|
||||||
// is instantiated.
|
// is instantiated.
|
||||||
@ -148,7 +148,7 @@ class DefaultCacheFactoryTest extends SapphireTest
|
|||||||
$reflectionLoggerProperty->setAccessible(true);
|
$reflectionLoggerProperty->setAccessible(true);
|
||||||
$this->assertTrue($logger === $reflectionLoggerProperty->getValue($filesystemCache));
|
$this->assertTrue($logger === $reflectionLoggerProperty->getValue($filesystemCache));
|
||||||
} finally {
|
} finally {
|
||||||
Environment::setEnv('SS_MEMORY_CACHEFACTORY', $oldFactoryValue);
|
Environment::setEnv('SS_IN_MEMORY_CACHE_FACTORY', $oldFactoryValue);
|
||||||
Environment::setEnv('SS_MEMCACHED_DSN', $oldMemcachedDSNValue);
|
Environment::setEnv('SS_MEMCACHED_DSN', $oldMemcachedDSNValue);
|
||||||
Environment::setEnv('SS_REDIS_DSN', $oldRedisDSNValue);
|
Environment::setEnv('SS_REDIS_DSN', $oldRedisDSNValue);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user