From d703eeca3694835de6e1c60a7f526df17d58c041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 4 Dec 2024 18:05:38 +0100 Subject: [PATCH] Skip Redis tests if REDIS_URIS is not defined --- README.md | 2 +- tests/mutex/MutexConcurrencyTest.php | 4 ++-- tests/mutex/PHPRedisMutexTest.php | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6215ab7f..6e5f7007 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ **[Requirements](#requirements)** | **[Installation](#installation)** | **[Usage](#usage)** | -**[License](#license)** | +**[License](#license)** # php-lock/lock diff --git a/tests/mutex/MutexConcurrencyTest.php b/tests/mutex/MutexConcurrencyTest.php index 2eb663b8..c67f15b7 100644 --- a/tests/mutex/MutexConcurrencyTest.php +++ b/tests/mutex/MutexConcurrencyTest.php @@ -279,9 +279,9 @@ public static function provideExecutionIsSerializedWhenLockedCases(): iterable }]; } - $uris = getenv('REDIS_URIS') !== false ? explode(',', getenv('REDIS_URIS')) : false; + if (getenv('REDIS_URIS')) { + $uris = explode(',', getenv('REDIS_URIS')); - if ($uris) { $cases['PredisMutex'] = [static function ($timeout = 3) use ($uris): Mutex { $clients = array_map( static function ($uri) { diff --git a/tests/mutex/PHPRedisMutexTest.php b/tests/mutex/PHPRedisMutexTest.php index 8249a227..8904966f 100644 --- a/tests/mutex/PHPRedisMutexTest.php +++ b/tests/mutex/PHPRedisMutexTest.php @@ -73,10 +73,14 @@ class PHPRedisMutexTest extends TestCase protected function setUp(): void { parent::setUp(); + + if (!getenv('REDIS_URIS')) { + self::markTestSkipped('Redis server is needed'); + } - $uris = explode(',', getenv('REDIS_URIS') ?: 'redis://localhost'); // @phpstan-ignore ternary.shortNotAllowed + $redisUris = explode(',', getenv('REDIS_URIS')); - foreach ($uris as $redisUri) { + foreach ($redisUris as $redisUri) { $uri = parse_url($redisUri); // original Redis::set and Redis::eval calls will reopen the connection @@ -241,14 +245,14 @@ public static function provideSerializersAndCompressorsCases(): iterable [\Redis::SERIALIZER_PHP, \Redis::COMPRESSION_NONE], ]; - if (defined('Redis::SERIALIZER_IGBINARY')) { + if (defined('Redis::SERIALIZER_IGBINARY') && extension_loaded('igbinary')) { $options[] = [ constant('Redis::SERIALIZER_IGBINARY'), \Redis::COMPRESSION_NONE, ]; } - if (defined('Redis::COMPRESSION_LZF')) { + if (defined('Redis::COMPRESSION_LZF') && extension_loaded('lzf')) { $options[] = [ \Redis::SERIALIZER_NONE, constant('Redis::COMPRESSION_LZF'), @@ -258,7 +262,7 @@ public static function provideSerializersAndCompressorsCases(): iterable constant('Redis::COMPRESSION_LZF'), ]; - if (defined('Redis::SERIALIZER_IGBINARY')) { + if (defined('Redis::SERIALIZER_IGBINARY') && extension_loaded('igbinary')) { $options[] = [ constant('Redis::SERIALIZER_IGBINARY'), constant('Redis::COMPRESSION_LZF'),