From 59899f0d91cebc4c4a29978d1c9d71fe80cd100c Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Fri, 9 Apr 2021 23:46:59 -0700 Subject: [PATCH] Skip cache tests when a cache driver is unavailable --- tests/Factories/CacheFactoryTest.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/Factories/CacheFactoryTest.php b/tests/Factories/CacheFactoryTest.php index 8f5fc2e..201bb32 100644 --- a/tests/Factories/CacheFactoryTest.php +++ b/tests/Factories/CacheFactoryTest.php @@ -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')], ]; } }