Skip cache tests when a cache driver is unavailable

This commit is contained in:
Chris Kankiewicz
2021-04-09 23:46:59 -07:00
parent e0f3f52d8a
commit 59899f0d91

View File

@@ -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')],
];
}
}