mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-23 22:24:18 +02:00
Skip cache tests when a cache driver is unavailable
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Tests\Factories;
|
||||
|
||||
use App\Exceptions\InvalidConfiguration;
|
||||
use App\Factories\CacheFactory;
|
||||
use RedisException;
|
||||
use Symfony\Component\Cache\Adapter;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -11,11 +12,19 @@ use Tests\TestCase;
|
||||
class CacheFactoryTest extends TestCase
|
||||
{
|
||||
/** @dataProvider cacheAdapters */
|
||||
public function test_it_can_compose_an_adapter(string $config, string $adapter): void
|
||||
public function test_it_can_compose_an_adapter(string $config, string $adapter, bool $available = true): void
|
||||
{
|
||||
if (! $available) {
|
||||
$this->markTestSkipped('Cache driver unavailable');
|
||||
}
|
||||
|
||||
$this->container->set('cache_driver', $config);
|
||||
|
||||
$cache = (new CacheFactory($this->container, $this->config))();
|
||||
try {
|
||||
$cache = (new CacheFactory($this->container, $this->config))();
|
||||
} catch (RedisException $exception) {
|
||||
$this->markTestSkipped(sprintf('Redis: %s', $exception->getMessage()));
|
||||
}
|
||||
|
||||
$this->assertInstanceOf($adapter, $cache);
|
||||
}
|
||||
@@ -32,12 +41,12 @@ class CacheFactoryTest extends TestCase
|
||||
public function cacheAdapters(): array
|
||||
{
|
||||
return [
|
||||
'APCu adapter' => ['apcu', Adapter\ApcuAdapter::class],
|
||||
'Array adapter' => ['array', Adapter\ArrayAdapter::class],
|
||||
'File adapter' => ['file', Adapter\FilesystemAdapter::class],
|
||||
'Memcached adapter' => ['memcached', Adapter\MemcachedAdapter::class],
|
||||
'PHP files adapter' => ['php-file', Adapter\PhpFilesAdapter::class],
|
||||
'Redis adapter' => ['redis', Adapter\RedisAdapter::class],
|
||||
'APCu adapter' => ['apcu', Adapter\ApcuAdapter::class, extension_loaded('apcu') && ini_get('apc.enabled')],
|
||||
'Array adapter' => ['array', Adapter\ArrayAdapter::class, true],
|
||||
'File adapter' => ['file', Adapter\FilesystemAdapter::class, true],
|
||||
'Memcached adapter' => ['memcached', Adapter\MemcachedAdapter::class, class_exists('Memcached')],
|
||||
'PHP files adapter' => ['php-file', Adapter\PhpFilesAdapter::class, true],
|
||||
'Redis adapter' => ['redis', Adapter\RedisAdapter::class, class_exists('Redis')],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user