Skip to content

Commit d1fc8d7

Browse files
committed
fix: improve guarding against missing clients
1 parent 3b5c0d1 commit d1fc8d7

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

packages/kv-store/src/Redis/MissingRedisException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Tempest\KeyValue\Redis;
44

55
use Exception;
6-
use Predis\Client;
6+
use Predis;
77

88
final class MissingRedisException extends Exception implements RedisException
99
{
@@ -13,7 +13,7 @@ public function __construct(string $fqcn)
1313
'Redis client not found.' .
1414
match ($fqcn) {
1515
\Redis::class => ' You may be missing the `redis` extension.',
16-
Client::class => ' You may need to install the `predis/predis` package.',
16+
Predis\Client::class => ' You may need to install the `predis/predis` package.',
1717
},
1818
);
1919
}

packages/kv-store/src/Redis/RedisInitializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function initialize(ClassReflector $class, null|string|UnitEnum $tag, Con
3434
private function buildPhpRedisClient(): \Redis
3535
{
3636
if (! extension_loaded('redis') || ! class_exists(\Redis::class)) {
37-
throw new MissingRedisException(Redis::class);
37+
throw new MissingRedisException(\Redis::class);
3838
}
3939

4040
return new \Redis();

packages/kv-store/tests/PhpRedisClientTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ protected function setUp(): void
1414
{
1515
parent::setUp();
1616

17+
if (! extension_loaded('redis') || ! class_exists(\Redis::class)) {
18+
$this->markTestSkipped('The `redis` extension is not loaded.');
19+
}
20+
1721
$this->redis = new PhpRedisClient(
1822
client: new \Redis(),
1923
config: new RedisConfig(

packages/kv-store/tests/PredisClientTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ protected function setUp(): void
1515
{
1616
parent::setUp();
1717

18+
if (! class_exists(Predis\Client::class)) {
19+
$this->markTestSkipped('The `predis/predis` package is not installed.');
20+
}
21+
1822
$this->redis = new PredisClient(
1923
client: new Predis\Client(
2024
parameters: array_filter([

0 commit comments

Comments
 (0)